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