Cleaning and API clarifications

Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
matt 2019-02-06 21:29:51 -05:00
parent 3d8179a4e6
commit b39ea1b68b
3 changed files with 57 additions and 55 deletions

File diff suppressed because one or more lines are too long

View File

@ -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,30 +554,18 @@ 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() {
try {
SQLManager.this.connection.commit();
} catch (SQLException e) {
e.printStackTrace();
}
if (whenDone != null) {
whenDone.run();
}
}
});
}
});
createSettings(settings, () -> createTiers(helpers, "helpers",
() -> createTiers(trusted, "trusted",
() -> createTiers(denied, "denied", () -> {
try {
SQLManager.this.connection.commit();
} catch (SQLException e) {
e.printStackTrace();
}
});
}
});
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

View File

@ -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);