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