From ce756411cf2fd34e4e66684de89386e5df7fdc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Apr 2020 14:05:01 +0200 Subject: [PATCH 1/6] Remove all direct access to Plot.owner New methods were added for access to the absolute owner of a plot, and the documentation of the owner getters to clarify the purpose of the methods. --- .../bukkit/commands/DebugUUID.java | 8 +- .../plotsquared/plot/PlotSquared.java | 6 +- .../plotsquared/plot/commands/Auto.java | 2 +- .../plotsquared/plot/commands/Buy.java | 4 +- .../plotsquared/plot/commands/Claim.java | 6 +- .../plotsquared/plot/commands/Owner.java | 2 +- .../plotsquared/plot/commands/Purge.java | 4 +- .../plotsquared/plot/database/SQLManager.java | 20 +-- .../plotsquared/plot/object/Plot.java | 128 +++++++++++------- .../plotsquared/plot/object/PlotArea.java | 2 +- .../plotsquared/plot/object/PlotHandler.java | 8 +- .../plot/object/worlds/SinglePlotArea.java | 2 +- .../plotsquared/plot/util/UUIDHandler.java | 6 +- .../plot/util/UUIDHandlerImplementation.java | 12 +- 14 files changed, 125 insertions(+), 85 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java index 49d399da1..edd0db055 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java @@ -231,9 +231,9 @@ import java.util.UUID; MainUtil.sendMessage(player, "&7 - Updating plot objects"); for (Plot plot : PlotSquared.get().getPlots()) { - UUID value = uCMap.get(plot.owner); + UUID value = uCMap.get(plot.getOwnerAbs()); if (value != null) { - plot.owner = value; + plot.setOwnerAbs(value); } plot.getTrusted().clear(); plot.getMembers().clear(); @@ -250,9 +250,9 @@ import java.util.UUID; if (!result) { MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery"); for (Plot plot : PlotSquared.get().getPlots()) { - UUID value = uCReverse.get(plot.owner); + UUID value = uCReverse.get(plot.getOwnerAbs()); if (value != null) { - plot.owner = value; + plot.setOwnerAbs(value); } } DBFunc.createPlotsAndData(new ArrayList<>(PlotSquared.get().getPlots()), 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 c909ccc1a..b87aa8a10 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 @@ -347,8 +347,8 @@ import java.util.zip.ZipInputStream; UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE); forEachPlotRaw(plot -> { if (plot.hasOwner() && plot.temp != -1) { - if (UUIDHandler.getName(plot.owner) == null) { - UUIDHandler.implementation.unknown.add(plot.owner); + if (UUIDHandler.getName(plot.getOwnerAbs()) == null) { + UUIDHandler.implementation.unknown.add(plot.getOwnerAbs()); } } }); @@ -736,7 +736,7 @@ import java.util.zip.ZipInputStream; } else { list = new ArrayList<>(input); } - list.sort(Comparator.comparingLong(a -> ExpireManager.IMP.getTimestamp(a.owner))); + list.sort(Comparator.comparingLong(a -> ExpireManager.IMP.getTimestamp(a.getOwnerAbs()))); return list; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java index a04540168..dc896b2a5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java @@ -138,7 +138,7 @@ public class Auto extends SubCommand { return; } whenDone.value = plot; - plot.owner = player.getUUID(); + plot.setOwnerAbs(player.getUUID()); DBFunc.createPlotSafe(plot, whenDone, () -> autoClaimFromDatabase(player, area, plot.getId(), whenDone)); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java index 1768ae7f3..0f2da6ae2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java @@ -59,8 +59,8 @@ public class Buy extends Command { confirm.run(this, () -> { Captions.REMOVED_BALANCE.send(player, price); EconHandler.manager - .depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price); - PlotPlayer owner = UUIDHandler.getPlayer(plot.owner); + .depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.getOwnerAbs()), price); + PlotPlayer owner = UUIDHandler.getPlayer(plot.getOwnerAbs()); if (owner != null) { Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java index 559df28ef..d52471d85 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java @@ -97,7 +97,7 @@ public class Claim extends SubCommand { if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) { return !sendMessage(player, Captions.BORDER); } - plot.owner = player.getUUID(); + plot.setOwnerAbs(player.getUUID()); final String finalSchematic = schematic; DBFunc.createPlotSafe(plot, () -> TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Object value) { @@ -105,7 +105,7 @@ public class Claim extends SubCommand { PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + String.format("Failed to claim plot %s", plot.getId().toCommaSeparatedString())); sendMessage(player, Captions.PLOT_NOT_CLAIMED); - plot.owner = null; + plot.setOwnerAbs(null); } else if (area.isAutoMerge()) { PlotMergeEvent event = PlotSquared.get().getEventDispatcher() .callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player); @@ -120,7 +120,7 @@ public class Claim extends SubCommand { PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + String.format("Failed to add plot %s to the database", plot.getId().toCommaSeparatedString())); sendMessage(player, Captions.PLOT_NOT_CLAIMED); - plot.owner = null; + plot.setOwnerAbs(null); }); return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java index e0baa49ef..e973105e9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java @@ -49,7 +49,7 @@ public class Owner extends SetCommand { uuid = null; } PlotChangeOwnerEvent event = PlotSquared.get().getEventDispatcher() - .callOwnerChange(player, plot, plot.hasOwner() ? plot.owner : null, uuid, + .callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid, plot.hasOwner()); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Owner change"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java index c61074f27..8d6150020 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java @@ -121,7 +121,7 @@ public class Purge extends SubCommand { if (added != null && !plot.isAdded(added)) { continue; } - if (unknown && UUIDHandler.getName(plot.owner) != null) { + if (unknown && UUIDHandler.getName(plot.getOwnerAbs()) != null) { continue; } toDelete.addAll(plot.getConnectedPlots()); @@ -144,7 +144,7 @@ public class Purge extends SubCommand { if (added != null && !plot.isAdded(added)) { continue; } - if (unknown && UUIDHandler.getName(plot.owner) != null) { + if (unknown && UUIDHandler.getName(plot.getOwnerAbs()) != null) { continue; } toDelete.add(plot); 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 b3d52a114..907600749 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 @@ -718,7 +718,7 @@ import java.util.concurrent.atomic.AtomicInteger; stmt.setInt(i * 5 + 1, plot.getId().x); stmt.setInt(i * 5 + 2, plot.getId().y); try { - stmt.setString(i * 5 + 3, plot.owner.toString()); + stmt.setString(i * 5 + 3, plot.getOwnerAbs().toString()); } catch (SQLException ignored) { stmt.setString(i * 5 + 3, everyone.toString()); } @@ -732,7 +732,7 @@ import java.util.concurrent.atomic.AtomicInteger; stmt.setInt(i * 6 + 2, plot.getId().x); stmt.setInt(i * 6 + 3, plot.getId().y); try { - stmt.setString(i * 6 + 4, plot.owner.toString()); + stmt.setString(i * 6 + 4, plot.getOwnerAbs().toString()); } catch (SQLException ignored) { stmt.setString(i * 6 + 4, everyone.toString()); } @@ -743,7 +743,7 @@ import java.util.concurrent.atomic.AtomicInteger; @Override public void setSQL(PreparedStatement stmt, Plot plot) throws SQLException { stmt.setInt(1, plot.getId().x); stmt.setInt(2, plot.getId().y); - stmt.setString(3, plot.owner.toString()); + stmt.setString(3, plot.getOwnerAbs().toString()); stmt.setString(4, plot.getArea().toString()); stmt.setTimestamp(5, new Timestamp(plot.getTimestamp())); @@ -982,7 +982,7 @@ import java.util.concurrent.atomic.AtomicInteger; @Override public void set(PreparedStatement statement) throws SQLException { statement.setInt(1, plot.getId().x); statement.setInt(2, plot.getId().y); - statement.setString(3, plot.owner.toString()); + statement.setString(3, plot.getOwnerAbs().toString()); statement.setString(4, plot.getArea().toString()); statement.setTimestamp(5, new Timestamp(plot.getTimestamp())); statement.setString(6, plot.getArea().toString()); @@ -1051,7 +1051,7 @@ import java.util.concurrent.atomic.AtomicInteger; @Override public void set(PreparedStatement statement) throws SQLException { statement.setInt(1, plot.getId().x); statement.setInt(2, plot.getId().y); - statement.setString(3, plot.owner.toString()); + statement.setString(3, plot.getOwnerAbs().toString()); statement.setString(4, plot.getArea().toString()); statement.setTimestamp(5, new Timestamp(plot.getTimestamp())); } @@ -1356,7 +1356,7 @@ import java.util.concurrent.atomic.AtomicInteger; @Override public void delete(final Plot plot) { PlotSquared.debug( "Deleting plot... Id: " + plot.getId() + " World: " + plot.getWorldName() + " Owner: " - + plot.owner + " Index: " + plot.temp); + + plot.getOwnerAbs() + " Index: " + plot.temp); deleteSettings(plot); deleteDenied(plot); deleteHelpers(plot); @@ -1384,7 +1384,7 @@ import java.util.concurrent.atomic.AtomicInteger; @Override public void createPlotSettings(final int id, Plot plot) { PlotSquared.debug( "Creating plot... Id: " + plot.getId() + " World: " + plot.getWorldName() + " Owner: " - + plot.owner + " Index: " + id); + + plot.getOwnerAbs() + " Index: " + id); addPlotTask(plot, new UniqueStatement("createPlotSettings") { @Override public void set(PreparedStatement statement) throws SQLException { statement.setInt(1, id); @@ -3002,10 +3002,10 @@ import java.util.concurrent.atomic.AtomicInteger; continue; } // owner - if (!plot.owner.equals(dataPlot.owner)) { + if (!plot.getOwnerAbs().equals(dataPlot.getOwnerAbs())) { PlotSquared - .debug("&8 - &7Setting owner: " + plot + " -> " + MainUtil.getName(plot.owner)); - setOwner(plot, plot.owner); + .debug("&8 - &7Setting owner: " + plot + " -> " + MainUtil.getName(plot.getOwnerAbs())); + setOwner(plot, plot.getOwnerAbs()); } // trusted if (!plot.getTrusted().equals(dataPlot.getTrusted())) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index ef21ef332..0b1239510 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -98,7 +98,7 @@ public class Plot { * * @deprecated */ - @Deprecated public UUID owner; + private UUID owner; /** * Has the plot changed since the last save cycle? @@ -286,6 +286,34 @@ public class Plot { return null; } + /** + * Get the owner of this exact plot, as it is + * stored in the database. + * + * If the plot is a mega-plot, then the method returns + * the owner of this particular subplot. + * + * Unlike {@link #getOwner()} this method does not + * consider factors such as {@link com.github.intellectualsites.plotsquared.plot.flags.implementations.ServerPlotFlag} + * that could alter the de facto owner of the plot. + * + * @return The plot owner of this particular (sub-)plot + * as stored in the database, if one exists. Else, null. + */ + @Nullable public UUID getOwnerAbs() { + return this.owner; + } + + /** + * Set the owner of this exact sub-plot. This does + * not update the database. + * + * @param owner The new owner of this particular sub-plot. + */ + public void setOwnerAbs(@Nullable final UUID owner) { + this.owner = owner; + } + public String getWorldName() { return area.getWorldName(); } @@ -366,7 +394,7 @@ public class Plot { * @return false if there is no owner */ public boolean hasOwner() { - return this.owner != null; + return this.getOwnerAbs() != null; } /** @@ -386,7 +414,10 @@ public class Plot { return connected.stream().anyMatch(current -> uuid.equals(current.getOwner())); } - public boolean isOwnerAbs(UUID uuid) { + public boolean isOwnerAbs(@Nullable final UUID uuid) { + if (uuid == null) { + return false; + } return uuid.equals(this.getOwner()); } @@ -395,13 +426,16 @@ public class Plot { * (Merged plots can have multiple owners) * Direct access is Deprecated: use getOwners() * - * @deprecated + * @deprecated A mega-plot may have multiple owners + * and this method only considers the + * owner of this particular sub-plot. + * @see #getOwnerAbs() getOwnerAbs() to get the owner as stored in the database */ @Deprecated public UUID getOwner() { if (MainUtil.isServerOwned(this)) { return DBFunc.SERVER; } - return this.owner; + return this.getOwnerAbs(); } /** @@ -411,20 +445,20 @@ public class Plot { */ public void setOwner(UUID owner) { if (!hasOwner()) { - this.owner = owner; + this.setOwnerAbs(owner); create(); return; } if (!isMerged()) { - if (!this.owner.equals(owner)) { - this.owner = owner; + if (!owner.equals(this.getOwnerAbs())) { + this.setOwnerAbs(owner); DBFunc.setOwner(this, owner); } return; } for (Plot current : getConnectedPlots()) { - if (!owner.equals(current.owner)) { - current.owner = owner; + if (!owner.equals(current.getOwnerAbs())) { + current.setOwnerAbs(owner); DBFunc.setOwner(current, owner); } } @@ -467,7 +501,7 @@ public class Plot { * @return true if the player is added/trusted or is the owner */ public boolean isAdded(UUID uuid) { - if (this.owner == null || getDenied().contains(uuid)) { + if (this.getOwnerAbs() == null || getDenied().contains(uuid)) { return false; } if (isOwner(uuid)) { @@ -832,20 +866,20 @@ public class Plot { */ public boolean setOwner(UUID owner, PlotPlayer initiator) { if (!hasOwner()) { - this.owner = owner; + this.setOwnerAbs(owner); create(); return true; } if (!isMerged()) { - if (!this.owner.equals(owner)) { - this.owner = owner; + if (!owner.equals(this.getOwnerAbs())) { + this.setOwnerAbs(owner); DBFunc.setOwner(this, owner); } return true; } - for (Plot current : getConnectedPlots()) { - if (!owner.equals(current.owner)) { - current.owner = owner; + for (final Plot current : getConnectedPlots()) { + if (!owner.equals(current.getOwnerAbs())) { + current.setOwnerAbs(owner); DBFunc.setOwner(current, owner); } } @@ -891,7 +925,7 @@ public class Plot { TaskManager.runTask(whenDone); }; for (Plot current : plots) { - if (isDelete || current.owner == null) { + if (isDelete || current.getOwnerAbs() == null) { manager.unClaimPlot(current, null); } else { manager.claimPlot(current); @@ -1023,7 +1057,7 @@ public class Plot { if (createSign) { GlobalBlockQueue.IMP.addEmptyTask(() -> { for (Plot current : plots) { - current.setSign(MainUtil.getName(current.owner)); + current.setSign(MainUtil.getName(current.getOwnerAbs())); } }); } @@ -1291,7 +1325,7 @@ public class Plot { * @return false if the Plot has no owner, otherwise true. */ public boolean unclaim() { - if (this.owner == null) { + if (this.getOwnerAbs() == null) { return false; } for (Plot current : getConnectedPlots()) { @@ -1301,7 +1335,7 @@ public class Plot { } getArea().removePlot(getId()); DBFunc.delete(current); - current.owner = null; + current.setOwnerAbs(null); current.settings = null; for (PlotPlayer pp : players) { PlotListener.plotEntry(pp, current); @@ -1677,11 +1711,11 @@ public class Plot { * Sets the plot sign if plot signs are enabled. */ public void setSign() { - if (this.owner == null) { + if (this.getOwnerAbs() == null) { this.setSign("unknown"); return; } - String name = UUIDHandler.getName(this.owner); + String name = UUIDHandler.getName(this.getOwnerAbs()); if (name == null) { this.setSign("unknown"); } else { @@ -1771,7 +1805,7 @@ public class Plot { * @return true if plot was created successfully */ public boolean create(@NotNull UUID uuid, final boolean notify) { - this.owner = uuid; + this.setOwnerAbs(uuid); Plot existing = this.area.getOwnedPlotAbs(this.id); if (existing != null) { throw new IllegalStateException("Plot already exists!"); @@ -1870,7 +1904,7 @@ public class Plot { * @return Future containing the result */ public CompletableFuture swapData(Plot plot) { - if (this.owner == null) { + if (this.getOwnerAbs() == null) { if (plot != null && plot.hasOwner()) { plot.moveData(this, null); return CompletableFuture.completedFuture(true); @@ -1905,7 +1939,7 @@ public class Plot { * @return */ public boolean moveData(Plot plot, Runnable whenDone) { - if (this.owner == null) { + if (this.getOwnerAbs() == null) { PlotSquared.debug(plot + " is unowned (single)"); TaskManager.runTask(whenDone); return false; @@ -2159,7 +2193,7 @@ public class Plot { } else { TaskManager.runTaskAsync(() -> { String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil - .getName(Plot.this.owner); + .getName(Plot.this.getOwnerAbs()); boolean result = SchematicHandler.manager.save(value, Settings.Paths.SCHEMATICS + File.separator + name + ".schem"); if (whenDone != null) { @@ -2366,7 +2400,7 @@ public class Plot { */ public UUID guessOwner() { if (this.hasOwner()) { - return this.owner; + return this.getOwnerAbs(); } if (!this.area.allowSigns() || !Settings.Enabled_Components.GUESS_PLOT_OWNER) { return null; @@ -2400,7 +2434,7 @@ public class Plot { } UUID owner = UUIDHandler.getUUID(name, null); if (owner != null) { - this.owner = owner; + this.setOwnerAbs(owner); break; } if (lines[i - 1].length() == 15) { @@ -2408,19 +2442,19 @@ public class Plot { for (Entry entry : map.entrySet()) { String key = entry.getKey().value; if (key.length() > name.length() && key.startsWith(name)) { - this.owner = entry.getValue(); + this.setOwnerAbs(entry.getValue()); break loop; } } } - this.owner = UUID.nameUUIDFromBytes( - ("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8)); + this.setOwnerAbs(UUID.nameUUIDFromBytes( + ("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8))); break; } if (this.hasOwner()) { this.create(); } - return this.owner; + return this.getOwnerAbs(); } catch (IllegalArgumentException ignored) { return null; } @@ -2454,7 +2488,7 @@ public class Plot { */ public boolean autoMerge(Direction dir, int max, UUID uuid, boolean removeRoads) { //Ignore merging if there is no owner for the plot - if (this.owner == null) { + if (this.getOwnerAbs() == null) { return false; } Set connected = this.getConnectedPlots(); @@ -2689,7 +2723,7 @@ public class Plot { if (!tmp.getMerged(Direction.SOUTH)) { // invalid merge PlotSquared.debug("Fixing invalid merge: " + this); - if (tmp.isOwnerAbs(this.owner)) { + if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.SOUTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); } else { @@ -2702,10 +2736,11 @@ public class Plot { } if (this.getMerged(Direction.EAST)) { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.EAST)); + assert tmp != null; if (!tmp.getMerged(Direction.WEST)) { // invalid merge PlotSquared.debug("Fixing invalid merge: " + this); - if (tmp.isOwnerAbs(this.owner)) { + if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.WEST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); } else { @@ -2718,10 +2753,11 @@ public class Plot { } if (this.getMerged(Direction.SOUTH)) { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.SOUTH)); + assert tmp != null; if (!tmp.getMerged(Direction.NORTH)) { // invalid merge PlotSquared.debug("Fixing invalid merge: " + this); - if (tmp.isOwnerAbs(this.owner)) { + if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.NORTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); } else { @@ -2737,7 +2773,7 @@ public class Plot { if (!tmp.getMerged(Direction.EAST)) { // invalid merge PlotSquared.debug("Fixing invalid merge: " + this); - if (tmp.isOwnerAbs(this.owner)) { + if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.EAST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); } else { @@ -2750,11 +2786,11 @@ public class Plot { } Plot current; while ((current = frontier.poll()) != null) { - if (current.owner == null || current.settings == null) { + if (current.getOwnerAbs() == null || current.settings == null) { // Invalid plot // merged onto unclaimed plot PlotSquared - .debug("Ignoring invalid merged plot: " + current + " | " + current.owner); + .debug("Ignoring invalid merged plot: " + current + " | " + current.getOwnerAbs()); continue; } tmpSet.add(current); @@ -3054,14 +3090,14 @@ public class Plot { * @return true if the owner of the Plot is online */ public boolean isOnline() { - if (this.owner == null) { + if (this.getOwnerAbs() == null) { return false; } if (!isMerged()) { - return UUIDHandler.getPlayer(this.owner) != null; + return UUIDHandler.getPlayer(this.getOwnerAbs()) != null; } - for (Plot current : getConnectedPlots()) { - if (current.hasOwner() && UUIDHandler.getPlayer(current.owner) != null) { + for (final Plot current : getConnectedPlots()) { + if (current.hasOwner() && UUIDHandler.getPlayer(current.getOwnerAbs()) != null) { return true; } } @@ -3183,7 +3219,7 @@ public class Plot { Location ob = this.getBottomAbs(); final int offsetX = db.getX() - ob.getX(); final int offsetZ = db.getZ() - ob.getZ(); - if (this.owner == null) { + if (this.getOwnerAbs() == null) { TaskManager.runTaskLater(whenDone, 1); return CompletableFuture.completedFuture(false); } @@ -3301,7 +3337,7 @@ public class Plot { Location ob = this.getBottomAbs(); final int offsetX = db.getX() - ob.getX(); final int offsetZ = db.getZ() - ob.getZ(); - if (this.owner == null) { + if (this.getOwnerAbs() == null) { TaskManager.runTaskLater(whenDone, 1); return false; } 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 6fe608188..d89aeb9de 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 @@ -503,7 +503,7 @@ public abstract class PlotArea { } final HashSet myPlots = new HashSet<>(); forEachPlotAbs(value -> { - if (uuid.equals(value.owner)) { + if (uuid.equals(value.getOwnerAbs())) { myPlots.add(value); } }); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java index 4faa17b76..6f7b6413c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java @@ -1,11 +1,14 @@ package com.github.intellectualsites.plotsquared.plot.object; +import org.jetbrains.annotations.NotNull; + import java.util.Set; import java.util.UUID; public class PlotHandler { - public static boolean sameOwners(final Plot plot1, final Plot plot2) { - if (plot1.owner == null || plot2.owner == null) { + + public static boolean sameOwners(@NotNull final Plot plot1, @NotNull final Plot plot2) { + if (plot1.getOwnerAbs() == null || plot2.getOwnerAbs() == null) { return false; } final Set owners = plot1.getOwners(); @@ -16,4 +19,5 @@ public class PlotHandler { } return false; } + } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java index 4fe3b69b4..076b9e79c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java @@ -171,7 +171,7 @@ public class SinglePlotArea extends GridPlotWorld { PlotSettings s = p.getSettings(); final FlagContainer oldContainer = p.getFlagContainer(); - p = new SinglePlot(p.getId(), p.owner, p.getTrusted(), p.getMembers(), p.getDenied(), + p = new SinglePlot(p.getId(), p.getOwnerAbs(), p.getTrusted(), p.getMembers(), p.getDenied(), s.getAlias(), s.getPosition(), null, this, s.getMerged(), p.getTimestamp(), p.temp); p.getFlagContainer().addAll(oldContainer); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java index 9967e88eb..6aaefa899 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java @@ -61,7 +61,7 @@ public class UUIDHandler { final HashSet uuids = new HashSet<>(); PlotSquared.get().forEachPlotRaw(plot -> { if (plot.hasOwner()) { - uuids.add(plot.owner); + uuids.add(plot.getOwnerAbs()); uuids.addAll(plot.getTrusted()); uuids.addAll(plot.getMembers()); uuids.addAll(plot.getDenied()); @@ -107,8 +107,8 @@ public class UUIDHandler { return implementation.getName(uuid); } - public static PlotPlayer getPlayer(UUID uuid) { - if (implementation == null) { + @Nullable public static PlotPlayer getPlayer(@Nullable final UUID uuid) { + if (implementation == null || uuid == null) { return null; } return check(implementation.getPlayer(uuid)); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java index 57b70d263..75c83894c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java @@ -130,8 +130,8 @@ public abstract class UUIDHandlerImplementation { UUIDHandlerImplementation.this.unknown.remove(offline); Set plots = PlotSquared.get().getPlotsAbs(offline); if (!plots.isEmpty()) { - for (Plot plot : plots) { - plot.owner = uuid; + for (final Plot plot : plots) { + plot.setOwnerAbs(uuid); } DBFunc.replaceUUID(offline, uuid); PlotSquared.debug("&cDetected invalid UUID stored for: " + name.value); @@ -152,8 +152,8 @@ public abstract class UUIDHandlerImplementation { UUIDHandlerImplementation.this.unknown.remove(offlineUpper); Set plots = PlotSquared.get().getPlotsAbs(offlineUpper); if (!plots.isEmpty()) { - for (Plot plot : plots) { - plot.owner = uuid; + for (final Plot plot : plots) { + plot.setOwnerAbs(uuid); } replace(offlineUpper, uuid, name.value); } @@ -166,8 +166,8 @@ public abstract class UUIDHandlerImplementation { if (!existing.equals(uuid)) { Set plots = PlotSquared.get().getPlots(existing); if (!plots.isEmpty()) { - for (Plot plot : plots) { - plot.owner = uuid; + for (final Plot plot : plots) { + plot.setOwnerAbs(uuid); } replace(existing, uuid, name.value); } From 474795367e9895a56652dda7e3e2ef4024283169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Apr 2020 14:07:52 +0200 Subject: [PATCH 2/6] Reformat Plot after the owner changes. It was a bit too messy. --- .../plotsquared/plot/object/Plot.java | 160 +++++++++--------- 1 file changed, 82 insertions(+), 78 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 0b1239510..21454c76c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -90,16 +90,10 @@ public class Plot { private static Set regions_cache; @NotNull private final PlotId id; - /** - * plot owner - * (Merged plots can have multiple owners) - * Direct access is Deprecated: use getOwners() - * - * @deprecated + * Plot flag container */ - private UUID owner; - + @Getter private final FlagContainer flagContainer = new FlagContainer(null); /** * Has the plot changed since the last save cycle? */ @@ -113,55 +107,50 @@ public class Plot { * @deprecated magical */ @Deprecated public int temp; - + /** + * plot owner + * (Merged plots can have multiple owners) + * Direct access is Deprecated: use getOwners() + * + * @deprecated + */ + private UUID owner; /** * Plot creation timestamp (not accurate if the plot was created before this was implemented)
* - Milliseconds since the epoch
*/ private long timestamp; - /** * List of trusted (with plot permissions). */ private HashSet trusted; - /** * List of members users (with plot permissions). */ private HashSet members; - /** * List of denied players. */ private HashSet denied; - /** * External settings class. * - Please favor the methods over direct access to this class
* - The methods are more likely to be left unchanged from version changes
*/ private PlotSettings settings; - private PlotArea area; - /** * Session only plot metadata (session is until the server stops)
*
* For persistent metadata use the flag system */ private ConcurrentHashMap meta; - /** * The cached origin plot. * - The origin plot is used for plot grouping and relational data */ private Plot origin; - /** - * Plot flag container - */ - @Getter private final FlagContainer flagContainer = new FlagContainer(null); - /** * Constructor for a new plot. * (Only changes after plot.create() will be properly set in the database) @@ -289,16 +278,16 @@ public class Plot { /** * Get the owner of this exact plot, as it is * stored in the database. - * + *

* If the plot is a mega-plot, then the method returns * the owner of this particular subplot. - * + *

* Unlike {@link #getOwner()} this method does not * consider factors such as {@link com.github.intellectualsites.plotsquared.plot.flags.implementations.ServerPlotFlag} * that could alter the de facto owner of the plot. * * @return The plot owner of this particular (sub-)plot - * as stored in the database, if one exists. Else, null. + * as stored in the database, if one exists. Else, null. */ @Nullable public UUID getOwnerAbs() { return this.owner; @@ -426,10 +415,10 @@ public class Plot { * (Merged plots can have multiple owners) * Direct access is Deprecated: use getOwners() * - * @deprecated A mega-plot may have multiple owners - * and this method only considers the - * owner of this particular sub-plot. * @see #getOwnerAbs() getOwnerAbs() to get the owner as stored in the database + * @deprecated A mega-plot may have multiple owners + * and this method only considers the + * owner of this particular sub-plot. */ @Deprecated public UUID getOwner() { if (MainUtil.isServerOwned(this)) { @@ -1088,7 +1077,9 @@ public class Plot { "%plr%", name), Captions.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll( "%plr%", name)}; - WorldUtil.IMP.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(), lines); + WorldUtil.IMP + .setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(), + lines); } } @@ -1368,7 +1359,7 @@ public class Plot { WorldUtil.IMP.getHighestBlock(getWorldName(), location.getX(), location.getZ(), y -> { int height = y; if (area.allowSigns()) { - height = Math.max(y, getManager().getSignLoc(this).getY()); + height = Math.max(y, getManager().getSignLoc(this).getY()); } location.setY(1 + height); result.accept(location); @@ -1378,8 +1369,7 @@ public class Plot { /** * @deprecated May cause synchronous chunk loads */ - @Deprecated - public Location getCenterSynchronous() { + @Deprecated public Location getCenterSynchronous() { Location[] corners = getCorners(); Location top = corners[0]; Location bot = corners[1]; @@ -1389,7 +1379,8 @@ public class Plot { if (!isLoaded()) { return location; } - int y = WorldUtil.IMP.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ()); + int y = WorldUtil.IMP + .getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ()); if (area.allowSigns()) { y = Math.max(y, getManager().getSignLoc(this).getY()); } @@ -1400,8 +1391,7 @@ public class Plot { /** * @deprecated May cause synchronous chunk loads */ - @Deprecated - public Location getSideSynchronous() { + @Deprecated public Location getSideSynchronous() { CuboidRegion largest = getLargestRegion(); int x = (largest.getMaximumPoint().getX() >> 1) - (largest.getMinimumPoint().getX() >> 1) + largest.getMinimumPoint().getX(); @@ -1440,8 +1430,7 @@ public class Plot { /** * @deprecated May cause synchronous chunk loading */ - @Deprecated - public Location getHomeSynchronous() { + @Deprecated public Location getHomeSynchronous() { BlockLoc home = this.getPosition(); if (home == null || home.getX() == 0 && home.getZ() == 0) { return this.getDefaultHomeSynchronous(true); @@ -1455,8 +1444,8 @@ public class Plot { } if (!WorldUtil.IMP.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) { location.setY(Math.max(1 + WorldUtil.IMP - .getHighestBlockSynchronous(this.getWorldName(), location.getX(), location.getZ()), - bottom.getY())); + .getHighestBlockSynchronous(this.getWorldName(), location.getX(), + location.getZ()), bottom.getY())); } return location; } @@ -1481,11 +1470,11 @@ public class Plot { WorldUtil.IMP.getBlock(location, block -> { if (!block.getBlockType().getMaterial().isAir()) { WorldUtil.IMP - .getHighestBlock(this.getWorldName(), location.getX(), location.getZ(), y -> { - location.setY(Math.max(1 + y, - bottom.getY())); - result.accept(location); - }); + .getHighestBlock(this.getWorldName(), location.getX(), location.getZ(), + y -> { + location.setY(Math.max(1 + y, bottom.getY())); + result.accept(location); + }); } else { result.accept(location); } @@ -1524,8 +1513,7 @@ public class Plot { /** * @deprecated May cause synchronous chunk loads */ - @Deprecated - public Location getDefaultHomeSynchronous(final boolean member) { + @Deprecated public Location getDefaultHomeSynchronous(final boolean member) { Plot plot = this.getBasePlot(false); PlotLoc loc = member ? area.getDefaultHome() : area.getNonmemberHome(); if (loc != null) { @@ -1545,7 +1533,9 @@ public class Plot { z = bot.getZ() + loc.getZ(); } int y = loc.getY() < 1 ? - (isLoaded() ? WorldUtil.IMP.getHighestBlockSynchronous(plot.getWorldName(), x, z) + 1 : 63) : + (isLoaded() ? + WorldUtil.IMP.getHighestBlockSynchronous(plot.getWorldName(), x, z) + 1 : + 63) : loc.getY(); return new Location(plot.getWorldName(), x, y, z); } @@ -1574,8 +1564,8 @@ public class Plot { } if (loc.getY() < 1) { if (isLoaded()) { - WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z, y -> - result.accept(new Location(plot.getWorldName(), x, y + 1, z))); + WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z, + y -> result.accept(new Location(plot.getWorldName(), x, y + 1, z))); } else { result.accept(new Location(plot.getWorldName(), x, 63, z)); } @@ -1737,8 +1727,8 @@ public class Plot { public boolean claim(final PlotPlayer player, boolean teleport, String schematic) { if (!canClaim(player)) { - PlotSquared.debug(Captions.PREFIX.getTranslated() + - String.format("Player %s attempted to claim plot %s, but was not allowed", + PlotSquared.debug(Captions.PREFIX.getTranslated() + String + .format("Player %s attempted to claim plot %s, but was not allowed", player.getName(), this.getId().toCommaSeparatedString())); return false; } @@ -1750,9 +1740,9 @@ public class Plot { if (updateDB) { if (!create(player.getUUID(), true)) { - PlotSquared.debug(Captions.PREFIX.getTranslated() + - String.format("Player %s attempted to claim plot %s, but the database failed to update", - player.getName(), this.getId().toCommaSeparatedString())); + PlotSquared.debug(Captions.PREFIX.getTranslated() + String.format( + "Player %s attempted to claim plot %s, but the database failed to update", + player.getName(), this.getId().toCommaSeparatedString())); return false; } } else { @@ -1761,7 +1751,8 @@ public class Plot { setSign(player.getName()); MainUtil.sendMessage(player, Captions.CLAIMED); if (teleport && Settings.Teleport.ON_CLAIM) { - teleportPlayer(player, TeleportCause.COMMAND, result -> {}); + teleportPlayer(player, TeleportCause.COMMAND, result -> { + }); } PlotArea plotworld = getArea(); if (plotworld.isSchematicOnClaim()) { @@ -1838,9 +1829,9 @@ public class Plot { }); return true; } - PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + - String.format("Failed to add plot %s to plot area %s", this.getId().toCommaSeparatedString(), - this.area.toString())); + PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + String + .format("Failed to add plot %s to plot area %s", this.getId().toCommaSeparatedString(), + this.area.toString())); return false; } @@ -1862,17 +1853,17 @@ public class Plot { * @return the name of the biome */ public void getBiome(Consumer result) { - this.getCenter(location -> - WorldUtil.IMP.getBiome(location.getWorld(), location.getX(), location.getZ(), result)); + this.getCenter(location -> WorldUtil.IMP + .getBiome(location.getWorld(), location.getX(), location.getZ(), result)); } /** * @deprecated May cause synchronous chunk loads */ - @Deprecated - public BiomeType getBiomeSynchronous() { + @Deprecated public BiomeType getBiomeSynchronous() { final Location location = this.getCenterSynchronous(); - return WorldUtil.IMP.getBiomeSynchronous(location.getWorld(), location.getX(), location.getZ()); + return WorldUtil.IMP + .getBiomeSynchronous(location.getWorld(), location.getX(), location.getZ()); } //TODO Better documentation needed. @@ -1900,7 +1891,7 @@ public class Plot { /** * Swaps the settings for two plots. * - * @param plot the plot to swap data with + * @param plot the plot to swap data with * @return Future containing the result */ public CompletableFuture swapData(Plot plot) { @@ -2020,14 +2011,16 @@ public class Plot { * - Used when a plot is merged
*/ public void removeRoadEast() { - if (this.area.getType() != PlotAreaType.NORMAL && this.area.getTerrain() == PlotAreaTerrainType.ROAD) { + if (this.area.getType() != PlotAreaType.NORMAL + && this.area.getTerrain() == PlotAreaTerrainType.ROAD) { Plot other = this.getRelative(Direction.EAST); Location bot = other.getBottomAbs(); Location top = this.getTopAbs(); Location pos1 = new Location(this.getWorldName(), top.getX(), 0, bot.getZ()); Location pos2 = new Location(this.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ()); ChunkManager.manager.regenerateRegion(pos1, pos2, true, null); - } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove + } else if (this.area.getTerrain() + != PlotAreaTerrainType.ALL) { // no road generated => no road to remove this.area.getPlotManager().removeRoadEast(this); } } @@ -2465,14 +2458,16 @@ public class Plot { * - Used when a plot is merged
*/ public void removeRoadSouth() { - if (this.area.getType() != PlotAreaType.NORMAL && this.area.getTerrain() == PlotAreaTerrainType.ROAD) { + if (this.area.getType() != PlotAreaType.NORMAL + && this.area.getTerrain() == PlotAreaTerrainType.ROAD) { Plot other = this.getRelative(Direction.SOUTH); Location bot = other.getBottomAbs(); Location top = this.getTopAbs(); Location pos1 = new Location(this.getWorldName(), bot.getX(), 0, top.getZ()); Location pos2 = new Location(this.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ()); ChunkManager.manager.regenerateRegion(pos1, pos2, true, null); - } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove + } else if (this.area.getTerrain() + != PlotAreaTerrainType.ALL) { // no road generated => no road to remove this.getManager().removeRoadSouth(this); } } @@ -2641,14 +2636,16 @@ public class Plot { * Remove the SE road (only effects terrain) */ public void removeRoadSouthEast() { - if (this.area.getType() != PlotAreaType.NORMAL && this.area.getTerrain() == PlotAreaTerrainType.ROAD) { + if (this.area.getType() != PlotAreaType.NORMAL + && this.area.getTerrain() == PlotAreaTerrainType.ROAD) { Plot other = this.getRelative(1, 1); Location pos1 = this.getTopAbs().add(1, 0, 1); Location pos2 = other.getBottomAbs().subtract(1, 0, 1); pos1.setY(0); pos2.setY(MAX_HEIGHT); ChunkManager.manager.regenerateRegion(pos1, pos2, true, null); - } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove + } else if (this.area.getTerrain() + != PlotAreaTerrainType.ALL) { // no road generated => no road to remove this.area.getPlotManager().removeRoadSouthEast(this); } } @@ -2789,8 +2786,8 @@ public class Plot { if (current.getOwnerAbs() == null || current.settings == null) { // Invalid plot // merged onto unclaimed plot - PlotSquared - .debug("Ignoring invalid merged plot: " + current + " | " + current.getOwnerAbs()); + PlotSquared.debug( + "Ignoring invalid merged plot: " + current + " | " + current.getOwnerAbs()); continue; } tmpSet.add(current); @@ -3045,23 +3042,27 @@ public class Plot { * @param cause the cause of the teleport * @return if the teleport succeeded */ - public void teleportPlayer(final PlotPlayer player, TeleportCause cause, Consumer resultConsumer) { + public void teleportPlayer(final PlotPlayer player, TeleportCause cause, + Consumer resultConsumer) { Plot plot = this.getBasePlot(false); Result result = - PlotSquared.get().getEventDispatcher().callTeleport(player, player.getLocation(), plot).getEventResult(); + PlotSquared.get().getEventDispatcher().callTeleport(player, player.getLocation(), plot) + .getEventResult(); if (result == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Teleport"); resultConsumer.accept(false); return; } final Consumer locationConsumer = location -> { - if (Settings.Teleport.DELAY == 0 || Permissions.hasPermission(player, "plots.teleport.delay.bypass")) { + if (Settings.Teleport.DELAY == 0 || Permissions + .hasPermission(player, "plots.teleport.delay.bypass")) { MainUtil.sendMessage(player, Captions.TELEPORTED_TO_PLOT); player.teleport(location, cause); resultConsumer.accept(true); return; } - MainUtil.sendMessage(player, Captions.TELEPORT_IN_SECONDS, Settings.Teleport.DELAY + ""); + MainUtil + .sendMessage(player, Captions.TELEPORT_IN_SECONDS, Settings.Teleport.DELAY + ""); final String name = player.getName(); TaskManager.TELEPORT_QUEUE.add(name); TaskManager.runTaskLater(() -> { @@ -3114,7 +3115,8 @@ public class Plot { * @return */ public boolean setComponent(String component, Pattern blocks) { - PlotComponentSetEvent event = PlotSquared.get().getEventDispatcher().callComponentSet(this, component, blocks); + PlotComponentSetEvent event = + PlotSquared.get().getEventDispatcher().callComponentSet(this, component, blocks); component = event.getComponent(); blocks = event.getPattern(); return this.getManager().setComponent(this.getId(), component, blocks); @@ -3212,7 +3214,8 @@ public class Plot { * @param allowSwap whether to swap plots * @return success */ - public CompletableFuture move(final Plot destination, final Runnable whenDone, boolean allowSwap) { + public CompletableFuture move(final Plot destination, final Runnable whenDone, + boolean allowSwap) { final PlotId offset = new PlotId(destination.getId().x - this.getId().x, destination.getId().y - this.getId().y); Location db = destination.getBottomAbs(); @@ -3293,7 +3296,8 @@ public class Plot { @Override public void run() { if (regions.isEmpty()) { Plot plot = destination.getRelative(0, 0); - Plot originPlot = originArea.getPlotAbs(new PlotId(plot.id.x - offset.x, plot.id.y - offset.y)); + Plot originPlot = originArea + .getPlotAbs(new PlotId(plot.id.x - offset.x, plot.id.y - offset.y)); final Runnable clearDone = () -> { for (final Plot current : plot.getConnectedPlots()) { getManager().claimPlot(current); From 7962004215980b01637f7200590aed455b2f1820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Apr 2020 19:10:43 +0200 Subject: [PATCH 3/6] Replace `getOwnerAbs() == null` with `hasOwner()` --- .../plotsquared/plot/object/Plot.java | 22 +++++++++---------- .../plotsquared/plot/object/PlotHandler.java | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 21454c76c..66b6b56bd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -490,7 +490,7 @@ public class Plot { * @return true if the player is added/trusted or is the owner */ public boolean isAdded(UUID uuid) { - if (this.getOwnerAbs() == null || getDenied().contains(uuid)) { + if (this.hasOwner() || getDenied().contains(uuid)) { return false; } if (isOwner(uuid)) { @@ -914,7 +914,7 @@ public class Plot { TaskManager.runTask(whenDone); }; for (Plot current : plots) { - if (isDelete || current.getOwnerAbs() == null) { + if (isDelete || current.hasOwner()) { manager.unClaimPlot(current, null); } else { manager.claimPlot(current); @@ -1316,7 +1316,7 @@ public class Plot { * @return false if the Plot has no owner, otherwise true. */ public boolean unclaim() { - if (this.getOwnerAbs() == null) { + if (this.hasOwner()) { return false; } for (Plot current : getConnectedPlots()) { @@ -1701,7 +1701,7 @@ public class Plot { * Sets the plot sign if plot signs are enabled. */ public void setSign() { - if (this.getOwnerAbs() == null) { + if (this.hasOwner()) { this.setSign("unknown"); return; } @@ -1895,7 +1895,7 @@ public class Plot { * @return Future containing the result */ public CompletableFuture swapData(Plot plot) { - if (this.getOwnerAbs() == null) { + if (this.hasOwner()) { if (plot != null && plot.hasOwner()) { plot.moveData(this, null); return CompletableFuture.completedFuture(true); @@ -1930,7 +1930,7 @@ public class Plot { * @return */ public boolean moveData(Plot plot, Runnable whenDone) { - if (this.getOwnerAbs() == null) { + if (this.hasOwner()) { PlotSquared.debug(plot + " is unowned (single)"); TaskManager.runTask(whenDone); return false; @@ -2483,7 +2483,7 @@ public class Plot { */ public boolean autoMerge(Direction dir, int max, UUID uuid, boolean removeRoads) { //Ignore merging if there is no owner for the plot - if (this.getOwnerAbs() == null) { + if (this.hasOwner()) { return false; } Set connected = this.getConnectedPlots(); @@ -2783,7 +2783,7 @@ public class Plot { } Plot current; while ((current = frontier.poll()) != null) { - if (current.getOwnerAbs() == null || current.settings == null) { + if (current.hasOwner() || current.settings == null) { // Invalid plot // merged onto unclaimed plot PlotSquared.debug( @@ -3091,7 +3091,7 @@ public class Plot { * @return true if the owner of the Plot is online */ public boolean isOnline() { - if (this.getOwnerAbs() == null) { + if (this.hasOwner()) { return false; } if (!isMerged()) { @@ -3222,7 +3222,7 @@ public class Plot { Location ob = this.getBottomAbs(); final int offsetX = db.getX() - ob.getX(); final int offsetZ = db.getZ() - ob.getZ(); - if (this.getOwnerAbs() == null) { + if (this.hasOwner()) { TaskManager.runTaskLater(whenDone, 1); return CompletableFuture.completedFuture(false); } @@ -3341,7 +3341,7 @@ public class Plot { Location ob = this.getBottomAbs(); final int offsetX = db.getX() - ob.getX(); final int offsetZ = db.getZ() - ob.getZ(); - if (this.getOwnerAbs() == null) { + if (this.hasOwner()) { TaskManager.runTaskLater(whenDone, 1); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java index 6f7b6413c..fbaaabbf6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java @@ -8,7 +8,7 @@ import java.util.UUID; public class PlotHandler { public static boolean sameOwners(@NotNull final Plot plot1, @NotNull final Plot plot2) { - if (plot1.getOwnerAbs() == null || plot2.getOwnerAbs() == null) { + if (plot1.hasOwner() || plot2.hasOwner()) { return false; } final Set owners = plot1.getOwners(); From c2060ea1a78961f939a645c7ac53cbc1b44a3b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Apr 2020 19:11:53 +0200 Subject: [PATCH 4/6] Remove deprecation of `getOwner()` --- .../intellectualsites/plotsquared/plot/object/Plot.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 66b6b56bd..8bfb493f5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -411,16 +411,13 @@ public class Plot { } /** - * plot owner + * Get the plot owner of this particular sub-plot. * (Merged plots can have multiple owners) - * Direct access is Deprecated: use getOwners() + * Direct access is discouraged: use getOwners() * * @see #getOwnerAbs() getOwnerAbs() to get the owner as stored in the database - * @deprecated A mega-plot may have multiple owners - * and this method only considers the - * owner of this particular sub-plot. */ - @Deprecated public UUID getOwner() { + public UUID getOwner() { if (MainUtil.isServerOwned(this)) { return DBFunc.SERVER; } From 172bcc7677b048ab66b74b8dc377b57e5ceaeda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Apr 2020 19:22:12 +0200 Subject: [PATCH 5/6] Revert "Replace `getOwnerAbs() == null` with `hasOwner()`" This reverts commit 79620042 --- .../plotsquared/plot/object/Plot.java | 22 +++++++++---------- .../plotsquared/plot/object/PlotHandler.java | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 8bfb493f5..cf610f896 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -487,7 +487,7 @@ public class Plot { * @return true if the player is added/trusted or is the owner */ public boolean isAdded(UUID uuid) { - if (this.hasOwner() || getDenied().contains(uuid)) { + if (this.getOwnerAbs() == null || getDenied().contains(uuid)) { return false; } if (isOwner(uuid)) { @@ -911,7 +911,7 @@ public class Plot { TaskManager.runTask(whenDone); }; for (Plot current : plots) { - if (isDelete || current.hasOwner()) { + if (isDelete || current.getOwnerAbs() == null) { manager.unClaimPlot(current, null); } else { manager.claimPlot(current); @@ -1313,7 +1313,7 @@ public class Plot { * @return false if the Plot has no owner, otherwise true. */ public boolean unclaim() { - if (this.hasOwner()) { + if (this.getOwnerAbs() == null) { return false; } for (Plot current : getConnectedPlots()) { @@ -1698,7 +1698,7 @@ public class Plot { * Sets the plot sign if plot signs are enabled. */ public void setSign() { - if (this.hasOwner()) { + if (this.getOwnerAbs() == null) { this.setSign("unknown"); return; } @@ -1892,7 +1892,7 @@ public class Plot { * @return Future containing the result */ public CompletableFuture swapData(Plot plot) { - if (this.hasOwner()) { + if (this.getOwnerAbs() == null) { if (plot != null && plot.hasOwner()) { plot.moveData(this, null); return CompletableFuture.completedFuture(true); @@ -1927,7 +1927,7 @@ public class Plot { * @return */ public boolean moveData(Plot plot, Runnable whenDone) { - if (this.hasOwner()) { + if (this.getOwnerAbs() == null) { PlotSquared.debug(plot + " is unowned (single)"); TaskManager.runTask(whenDone); return false; @@ -2480,7 +2480,7 @@ public class Plot { */ public boolean autoMerge(Direction dir, int max, UUID uuid, boolean removeRoads) { //Ignore merging if there is no owner for the plot - if (this.hasOwner()) { + if (this.getOwnerAbs() == null) { return false; } Set connected = this.getConnectedPlots(); @@ -2780,7 +2780,7 @@ public class Plot { } Plot current; while ((current = frontier.poll()) != null) { - if (current.hasOwner() || current.settings == null) { + if (current.getOwnerAbs() == null || current.settings == null) { // Invalid plot // merged onto unclaimed plot PlotSquared.debug( @@ -3088,7 +3088,7 @@ public class Plot { * @return true if the owner of the Plot is online */ public boolean isOnline() { - if (this.hasOwner()) { + if (this.getOwnerAbs() == null) { return false; } if (!isMerged()) { @@ -3219,7 +3219,7 @@ public class Plot { Location ob = this.getBottomAbs(); final int offsetX = db.getX() - ob.getX(); final int offsetZ = db.getZ() - ob.getZ(); - if (this.hasOwner()) { + if (this.getOwnerAbs() == null) { TaskManager.runTaskLater(whenDone, 1); return CompletableFuture.completedFuture(false); } @@ -3338,7 +3338,7 @@ public class Plot { Location ob = this.getBottomAbs(); final int offsetX = db.getX() - ob.getX(); final int offsetZ = db.getZ() - ob.getZ(); - if (this.hasOwner()) { + if (this.getOwnerAbs() == null) { TaskManager.runTaskLater(whenDone, 1); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java index fbaaabbf6..6f7b6413c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java @@ -8,7 +8,7 @@ import java.util.UUID; public class PlotHandler { public static boolean sameOwners(@NotNull final Plot plot1, @NotNull final Plot plot2) { - if (plot1.hasOwner() || plot2.hasOwner()) { + if (plot1.getOwnerAbs() == null || plot2.getOwnerAbs() == null) { return false; } final Set owners = plot1.getOwners(); From 79583c011ff9c7391131f4fde32cf54c53f155e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Apr 2020 19:28:10 +0200 Subject: [PATCH 6/6] Replace `getOwnerAbs() == null` with `!hasOwner()` --- .../plotsquared/plot/object/Plot.java | 22 +++++++++---------- .../plotsquared/plot/object/PlotHandler.java | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index cf610f896..2fed2bfd1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -487,7 +487,7 @@ public class Plot { * @return true if the player is added/trusted or is the owner */ public boolean isAdded(UUID uuid) { - if (this.getOwnerAbs() == null || getDenied().contains(uuid)) { + if (!this.hasOwner() || getDenied().contains(uuid)) { return false; } if (isOwner(uuid)) { @@ -911,7 +911,7 @@ public class Plot { TaskManager.runTask(whenDone); }; for (Plot current : plots) { - if (isDelete || current.getOwnerAbs() == null) { + if (isDelete || !current.hasOwner()) { manager.unClaimPlot(current, null); } else { manager.claimPlot(current); @@ -1313,7 +1313,7 @@ public class Plot { * @return false if the Plot has no owner, otherwise true. */ public boolean unclaim() { - if (this.getOwnerAbs() == null) { + if (!this.hasOwner()) { return false; } for (Plot current : getConnectedPlots()) { @@ -1698,7 +1698,7 @@ public class Plot { * Sets the plot sign if plot signs are enabled. */ public void setSign() { - if (this.getOwnerAbs() == null) { + if (!this.hasOwner()) { this.setSign("unknown"); return; } @@ -1892,7 +1892,7 @@ public class Plot { * @return Future containing the result */ public CompletableFuture swapData(Plot plot) { - if (this.getOwnerAbs() == null) { + if (!this.hasOwner()) { if (plot != null && plot.hasOwner()) { plot.moveData(this, null); return CompletableFuture.completedFuture(true); @@ -1927,7 +1927,7 @@ public class Plot { * @return */ public boolean moveData(Plot plot, Runnable whenDone) { - if (this.getOwnerAbs() == null) { + if (!this.hasOwner()) { PlotSquared.debug(plot + " is unowned (single)"); TaskManager.runTask(whenDone); return false; @@ -2480,7 +2480,7 @@ public class Plot { */ public boolean autoMerge(Direction dir, int max, UUID uuid, boolean removeRoads) { //Ignore merging if there is no owner for the plot - if (this.getOwnerAbs() == null) { + if (!this.hasOwner()) { return false; } Set connected = this.getConnectedPlots(); @@ -2780,7 +2780,7 @@ public class Plot { } Plot current; while ((current = frontier.poll()) != null) { - if (current.getOwnerAbs() == null || current.settings == null) { + if (!current.hasOwner() || current.settings == null) { // Invalid plot // merged onto unclaimed plot PlotSquared.debug( @@ -3088,7 +3088,7 @@ public class Plot { * @return true if the owner of the Plot is online */ public boolean isOnline() { - if (this.getOwnerAbs() == null) { + if (!this.hasOwner()) { return false; } if (!isMerged()) { @@ -3219,7 +3219,7 @@ public class Plot { Location ob = this.getBottomAbs(); final int offsetX = db.getX() - ob.getX(); final int offsetZ = db.getZ() - ob.getZ(); - if (this.getOwnerAbs() == null) { + if (!this.hasOwner()) { TaskManager.runTaskLater(whenDone, 1); return CompletableFuture.completedFuture(false); } @@ -3338,7 +3338,7 @@ public class Plot { Location ob = this.getBottomAbs(); final int offsetX = db.getX() - ob.getX(); final int offsetZ = db.getZ() - ob.getZ(); - if (this.getOwnerAbs() == null) { + if (!this.hasOwner()) { TaskManager.runTaskLater(whenDone, 1); return false; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java index 6f7b6413c..b2ad9c17d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotHandler.java @@ -8,11 +8,11 @@ import java.util.UUID; public class PlotHandler { public static boolean sameOwners(@NotNull final Plot plot1, @NotNull final Plot plot2) { - if (plot1.getOwnerAbs() == null || plot2.getOwnerAbs() == null) { + if (!(plot1.hasOwner() && plot2.hasOwner())) { return false; } final Set owners = plot1.getOwners(); - for (UUID owner : owners) { + for (final UUID owner : owners) { if (plot2.isOwner(owner)) { return true; }