diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 991cc9706..7a9abb000 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -49,7 +49,7 @@ import java.util.zip.ZipInputStream; */ @SuppressWarnings({"unused", "WeakerAccess"}) public class PlotSquared { private static final Set EMPTY_SET = - Collections.unmodifiableSet(Collections.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. - *

+ * *

This will be either Bukkit or Sponge

* * @return the server implementation @@ -1526,9 +1526,9 @@ import java.util.zip.ZipInputStream; for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) { Map 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); @@ -1969,7 +1967,7 @@ import java.util.zip.ZipInputStream; * * @param alias to search plots * @param worldname to filter alias to a specific world [optional] null means all worlds - * @return Set<{ @ link Plot }> empty if nothing found + * @return Set<{ @ link Plot }> empty if nothing found */ public Set getPlotsByAlias(@Nullable final String alias, @NonNull final String worldname) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java index e1099076e..1c3395b56 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java @@ -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> 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 diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index 48ebb759a..a1ae29904 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -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 getPlots(@Nonnull final UUID uuid) { - final Set myplots = new HashSet<>(); - for (final Plot plot : getPlots()) { - if (plot.isBasePlot() && plot.isOwner(uuid)) { - myplots.add(plot); - } - } - return myplots; - } - - public Set 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 getPlots(@Nonnull final PlotPlayer player) { + return getPlots(player.getUUID()); + } + public boolean hasPlot(@Nonnull final UUID uuid) { for (Entry entry : this.plots.entrySet()) { if (entry.getValue().isOwner(uuid)) @@ -685,8 +687,20 @@ public abstract class PlotArea { } } - @Nonnull public Map getPlotsRaw() { - return this.plots; + /** + * Returns an ImmutableMap of PlotId's and Plots in this PlotArea. + */ + public Map 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 getPlotsRaw() { + return ImmutableMap.copyOf(plots); } @Nonnull public Set> 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);