mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2024-12-23 00:15:06 +00:00
Cleaning and API clarifications
Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
parent
3d8179a4e6
commit
b39ea1b68b
3 changed files with 57 additions and 55 deletions
|
@ -49,7 +49,7 @@ import java.util.zip.ZipInputStream;
|
|||
*/
|
||||
@SuppressWarnings({"unused", "WeakerAccess"}) public class PlotSquared {
|
||||
private static final Set<Plot> EMPTY_SET =
|
||||
Collections.unmodifiableSet(Collections.<Plot>emptySet());
|
||||
Collections.unmodifiableSet(Collections.emptySet());
|
||||
private static PlotSquared instance;
|
||||
// Implementation
|
||||
public final IPlotMain IMP;
|
||||
|
@ -394,7 +394,7 @@ import java.util.zip.ZipInputStream;
|
|||
|
||||
/**
|
||||
* Gets the server platform this plugin is running on this is running on.
|
||||
* <p>
|
||||
*
|
||||
* <p>This will be either <b>Bukkit</b> or <b>Sponge</b></p>
|
||||
*
|
||||
* @return the server implementation
|
||||
|
@ -1526,9 +1526,9 @@ import java.util.zip.ZipInputStream;
|
|||
for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
|
||||
Map<PlotId, Plot> map2 = map.get(area.toString());
|
||||
if (map2 == null) {
|
||||
map.put(area.toString(), area.getPlotsRaw());
|
||||
map.put(area.toString(), area.getPlotsMap());
|
||||
} else {
|
||||
map2.putAll(area.getPlotsRaw());
|
||||
map2.putAll(area.getPlotsMap());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
@ -1554,8 +1554,8 @@ import java.util.zip.ZipInputStream;
|
|||
// Close the connection
|
||||
DBFunc.close();
|
||||
UUIDHandler.handleShutdown();
|
||||
} catch (NullPointerException ignored) {
|
||||
ignored.printStackTrace();
|
||||
} catch (NullPointerException throwable) {
|
||||
throwable.printStackTrace();
|
||||
PlotSquared.log("&cCould not close database connection!");
|
||||
}
|
||||
}
|
||||
|
@ -1638,22 +1638,20 @@ import java.util.zip.ZipInputStream;
|
|||
}
|
||||
}
|
||||
Settings.load(configFile);
|
||||
try {
|
||||
InputStream stream = getClass().getResourceAsStream("/plugin.properties");
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
|
||||
try (InputStream stream = getClass().getResourceAsStream("/plugin.properties");
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(stream))) {
|
||||
//java.util.Scanner scanner = new java.util.Scanner(stream).useDelimiter("\\A");
|
||||
String versionString = br.readLine();
|
||||
String commitString = br.readLine();
|
||||
String dateString = br.readLine();
|
||||
//scanner.close();
|
||||
br.close();
|
||||
this.version = PlotVersion.tryParse(versionString, commitString, dateString);
|
||||
Settings.DATE = new Date(100 + version.year, version.month, version.day).toGMTString();
|
||||
Settings.BUILD = "https://ci.athion.net/job/PlotSquared/" + version.build;
|
||||
Settings.COMMIT = "https://github.com/IntellectualSites/PlotSquared/commit/" + Integer
|
||||
.toHexString(version.hash);
|
||||
System.out.println("Version is " + this.version);
|
||||
} catch (Throwable throwable) {
|
||||
} catch (IOException throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
Settings.save(configFile);
|
||||
|
|
|
@ -34,10 +34,12 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
public final String CREATE_PLOT;
|
||||
public final String CREATE_PLOT_SAFE;
|
||||
public final String CREATE_CLUSTER;
|
||||
private final String prefix;
|
||||
|
||||
// Private Final
|
||||
private final String prefix;
|
||||
private final Database database;
|
||||
private final boolean mySQL;
|
||||
|
||||
/**
|
||||
* important tasks
|
||||
*/
|
||||
|
@ -67,6 +69,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
* cluster_settings
|
||||
*/
|
||||
public volatile ConcurrentHashMap<PlotCluster, Queue<UniqueStatement>> clusterTasks;
|
||||
|
||||
// Private
|
||||
private Connection connection;
|
||||
private boolean closed = false;
|
||||
|
@ -75,11 +78,11 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
* Constructor
|
||||
*
|
||||
* @param database
|
||||
* @param p prefix
|
||||
* @param prefix prefix
|
||||
* @throws SQLException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public SQLManager(final Database database, String p, boolean debug)
|
||||
public SQLManager(final Database database, String prefix, boolean debug)
|
||||
throws SQLException, ClassNotFoundException {
|
||||
// Private final
|
||||
this.database = database;
|
||||
|
@ -90,7 +93,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
this.plotTasks = new ConcurrentHashMap<>();
|
||||
this.playerTasks = new ConcurrentHashMap<>();
|
||||
this.clusterTasks = new ConcurrentHashMap<>();
|
||||
this.prefix = p;
|
||||
this.prefix = prefix;
|
||||
this.SET_OWNER = "UPDATE `" + this.prefix
|
||||
+ "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND `world` = ?";
|
||||
this.GET_ALL_PLOTS =
|
||||
|
@ -551,14 +554,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
}
|
||||
}
|
||||
}
|
||||
createSettings(settings, new Runnable() {
|
||||
@Override public void run() {
|
||||
createTiers(helpers, "helpers", new Runnable() {
|
||||
@Override public void run() {
|
||||
createTiers(trusted, "trusted", new Runnable() {
|
||||
@Override public void run() {
|
||||
createTiers(denied, "denied", new Runnable() {
|
||||
@Override public void run() {
|
||||
createSettings(settings, () -> createTiers(helpers, "helpers",
|
||||
() -> createTiers(trusted, "trusted",
|
||||
() -> createTiers(denied, "denied", () -> {
|
||||
try {
|
||||
SQLManager.this.connection.commit();
|
||||
} catch (SQLException e) {
|
||||
|
@ -567,14 +565,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}))));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
PlotSquared.debug("&7[WARN] Failed to set all helpers for plots");
|
||||
|
@ -1354,7 +1345,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
}
|
||||
|
||||
/**
|
||||
* Create plot settings
|
||||
* Creates plot settings
|
||||
*
|
||||
* @param id
|
||||
* @param plot
|
||||
|
|
|
@ -14,6 +14,8 @@ import com.github.intellectualsites.plotsquared.plot.util.*;
|
|||
import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -525,17 +527,8 @@ public abstract class PlotArea {
|
|||
}
|
||||
|
||||
@Nonnull public Set<Plot> getPlots(@Nonnull final UUID uuid) {
|
||||
final Set<Plot> myplots = new HashSet<>();
|
||||
for (final Plot plot : getPlots()) {
|
||||
if (plot.isBasePlot() && plot.isOwner(uuid)) {
|
||||
myplots.add(plot);
|
||||
}
|
||||
}
|
||||
return myplots;
|
||||
}
|
||||
|
||||
public Set<Plot> getPlots(@Nonnull final PlotPlayer player) {
|
||||
return getPlots(player.getUUID());
|
||||
return getPlots().stream().filter(plot -> plot.isBasePlot() && plot.isOwner(uuid))
|
||||
.collect(ImmutableSet.toImmutableSet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -560,6 +553,15 @@ public abstract class PlotArea {
|
|||
return getPlotsAbs(uuid).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the plots for the player in this PlotArea.
|
||||
*
|
||||
* @deprecated Use {@link #getPlots(UUID)}
|
||||
*/
|
||||
@Deprecated public Set<Plot> getPlots(@Nonnull final PlotPlayer player) {
|
||||
return getPlots(player.getUUID());
|
||||
}
|
||||
|
||||
public boolean hasPlot(@Nonnull final UUID uuid) {
|
||||
for (Entry<PlotId, Plot> entry : this.plots.entrySet()) {
|
||||
if (entry.getValue().isOwner(uuid))
|
||||
|
@ -685,8 +687,20 @@ public abstract class PlotArea {
|
|||
}
|
||||
}
|
||||
|
||||
@Nonnull public Map<PlotId, Plot> getPlotsRaw() {
|
||||
return this.plots;
|
||||
/**
|
||||
* Returns an ImmutableMap of PlotId's and Plots in this PlotArea.
|
||||
*/
|
||||
public Map<PlotId, Plot> getPlotsMap() {
|
||||
return ImmutableMap.copyOf(plots);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ImmutableMap of PlotId's and Plots in this PlotArea.
|
||||
* @deprecated Use {@link #getPlotsMap()}
|
||||
*/
|
||||
//todo eventually remove
|
||||
@Deprecated @Nonnull public Map<PlotId, Plot> getPlotsRaw() {
|
||||
return ImmutableMap.copyOf(plots);
|
||||
}
|
||||
|
||||
@Nonnull public Set<Entry<PlotId, Plot>> getPlotEntries() {
|
||||
|
@ -714,14 +728,13 @@ public abstract class PlotArea {
|
|||
center = new PlotId(0, 0);
|
||||
plots = Integer.MAX_VALUE;
|
||||
}
|
||||
PlotId currentId;
|
||||
for (int i = 0; i < plots; i++) {
|
||||
if (start == null) {
|
||||
start = getMeta("lastPlot", new PlotId(0, 0));
|
||||
} else {
|
||||
start = start.getNextId(1);
|
||||
}
|
||||
currentId = new PlotId(center.x + start.x, center.y + start.y);
|
||||
PlotId currentId = new PlotId(center.x + start.x, center.y + start.y);
|
||||
Plot plot = getPlotAbs(currentId);
|
||||
if (plot != null && plot.canClaim(player)) {
|
||||
setMeta("lastPlot", currentId);
|
||||
|
|
Loading…
Reference in a new issue