From 2d3c72921571f4f2b128f0d6e96b9e31ec196ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 20 Aug 2020 17:10:50 +0200 Subject: [PATCH] Extract plot modifications to external class --- .../com/plotsquared/core/command/Biome.java | 5 +- .../com/plotsquared/core/command/Claim.java | 2 +- .../com/plotsquared/core/command/Clear.java | 4 +- .../plotsquared/core/command/Condense.java | 2 +- .../com/plotsquared/core/command/Copy.java | 16 +- .../com/plotsquared/core/command/Delete.java | 2 +- .../com/plotsquared/core/command/Merge.java | 11 +- .../com/plotsquared/core/command/Move.java | 2 +- .../com/plotsquared/core/command/Owner.java | 6 +- .../com/plotsquared/core/command/Purge.java | 4 +- .../com/plotsquared/core/command/Set.java | 4 +- .../com/plotsquared/core/command/Swap.java | 2 +- .../com/plotsquared/core/command/Unlink.java | 2 +- .../components/ComponentPresetManager.java | 2 +- .../core/generator/ClassicPlotManager.java | 36 +- .../core/generator/SquarePlotManager.java | 16 +- .../plotsquared/core/player/PlotPlayer.java | 11 +- .../java/com/plotsquared/core/plot/Plot.java | 1122 +++-------------- .../com/plotsquared/core/plot/PlotArea.java | 10 +- .../core/plot/PlotModificationManager.java | 819 ++++++++++++ .../core/plot/expiration/ExpireManager.java | 8 +- .../core/util/task/AutoClaimFinishTask.java | 3 +- 22 files changed, 1036 insertions(+), 1053 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java diff --git a/Core/src/main/java/com/plotsquared/core/command/Biome.java b/Core/src/main/java/com/plotsquared/core/command/Biome.java index 63eff5351..e8d7b7871 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Biome.java +++ b/Core/src/main/java/com/plotsquared/core/command/Biome.java @@ -67,7 +67,7 @@ public class Biome extends SetCommand { return false; } plot.addRunning(); - plot.setBiome(biome, () -> { + plot.getPlotModificationManager().setBiome(biome, () -> { plot.removeRunning(); player.sendMessage( TranslatableCaption.of("biome.biome_set_to"), @@ -78,8 +78,7 @@ public class Biome extends SetCommand { } @Override - public Collection tab(final PlotPlayer player, final String[] args, - final boolean space) { + public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { return SuggestionHelper.getNamespacedRegistrySuggestions(BiomeType.REGISTRY, args[0]) .map(value -> value.toLowerCase(Locale.ENGLISH).replace("minecraft:", "")) .filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH))) diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index a3996799a..9c8244798 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -187,7 +187,7 @@ public class Claim extends SubCommand { Template.of("value", "Auto merge on claim") ); } else { - plot.autoMerge(mergeEvent.getDir(), mergeEvent.getMax(), player.getUUID(), true); + plot.getPlotModificationManager().autoMerge(mergeEvent.getDir(), mergeEvent.getMax(), player.getUUID(), true); } } return null; diff --git a/Core/src/main/java/com/plotsquared/core/command/Clear.java b/Core/src/main/java/com/plotsquared/core/command/Clear.java index 58c087ccc..ab49db1b4 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Clear.java +++ b/Core/src/main/java/com/plotsquared/core/command/Clear.java @@ -92,8 +92,8 @@ public class Clear extends Command { confirm.run(this, () -> { BackupManager.backup(player, plot, () -> { final long start = System.currentTimeMillis(); - boolean result = plot.clear(true, false, () -> { - plot.unlink(); + boolean result = plot.getPlotModificationManager().clear(true, false, () -> { + plot.getPlotModificationManager().unlink(); TaskManager.runTask(() -> { plot.removeRunning(); // If the state changes, then mark it as no longer done diff --git a/Core/src/main/java/com/plotsquared/core/command/Condense.java b/Core/src/main/java/com/plotsquared/core/command/Condense.java index 7258bf70d..738f07acc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Condense.java +++ b/Core/src/main/java/com/plotsquared/core/command/Condense.java @@ -179,7 +179,7 @@ public class Condense extends SubCommand { i++; final AtomicBoolean result = new AtomicBoolean(false); try { - result.set(origin.move(possible, () -> { + result.set(origin.getPlotModificationManager().move(possible, () -> { if (result.get()) { player.sendMessage( TranslatableCaption.of("condense.moving"), diff --git a/Core/src/main/java/com/plotsquared/core/command/Copy.java b/Core/src/main/java/com/plotsquared/core/command/Copy.java index 4d5116696..b8d4e08fc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Copy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Copy.java @@ -77,11 +77,15 @@ public class Copy extends SubCommand { player.sendMessage(TranslatableCaption.of("errors.plotworld_incompatible")); return false; } - if (plot1.copy(plot2, () -> player.sendMessage(TranslatableCaption.of("move.copy_success")))) { - return true; - } else { - player.sendMessage(TranslatableCaption.of("move.requires_unowned")); - return false; - } + + plot1.getPlotModificationManager().copy(plot2).thenAccept(result -> { + if (result) { + player.sendMessage(TranslatableCaption.of("move.copy_success")); + } else { + player.sendMessage(TranslatableCaption.of("move.requires_unowned")); + } + }); + + return true; } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Delete.java b/Core/src/main/java/com/plotsquared/core/command/Delete.java index 6a57aadc3..93621eb47 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Delete.java +++ b/Core/src/main/java/com/plotsquared/core/command/Delete.java @@ -99,7 +99,7 @@ public class Delete extends SubCommand { return; } final long start = System.currentTimeMillis(); - boolean result = plot.deletePlot(() -> { + boolean result = plot.getPlotModificationManager().deletePlot(() -> { plot.removeRunning(); if ((this.econHandler != null) && plotArea.useEconomy()) { Expression valueExr = plotArea.getPrices().get("sell"); diff --git a/Core/src/main/java/com/plotsquared/core/command/Merge.java b/Core/src/main/java/com/plotsquared/core/command/Merge.java index 925053c60..4eea6cbbc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Merge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Merge.java @@ -42,7 +42,6 @@ import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.StringMan; -import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; @@ -182,7 +181,7 @@ public class Merge extends SubCommand { ); return true; } - if (plot.autoMerge(Direction.ALL, maxSize, uuid, terrain)) { + if (plot.getPlotModificationManager().autoMerge(Direction.ALL, maxSize, uuid, terrain)) { if (this.econHandler != null && plotArea.useEconomy() && price > 0d) { this.econHandler.withdrawMoney(player, price); player.sendMessage( @@ -226,7 +225,7 @@ public class Merge extends SubCommand { ); return true; } - if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) { + if (plot.getPlotModificationManager().autoMerge(direction, maxSize - size, uuid, terrain)) { if (this.econHandler != null && plotArea.useEconomy() && price > 0d) { this.econHandler.withdrawMoney(player, price); player.sendMessage( @@ -239,7 +238,7 @@ public class Merge extends SubCommand { } Plot adjacent = plot.getRelative(direction); if (adjacent == null || !adjacent.hasOwner() || adjacent - .getMerged((direction.getIndex() + 2) % 4) || (!force && adjacent.isOwner(uuid))) { + .isMerged((direction.getIndex() + 2) % 4) || (!force && adjacent.isOwner(uuid))) { player.sendMessage(TranslatableCaption.of("merge.no_available_automerge")); return false; } @@ -261,8 +260,8 @@ public class Merge extends SubCommand { final Direction dir = direction; Runnable run = () -> { accepter.sendMessage(TranslatableCaption.of("merge.merge_accepted")); - plot.autoMerge(dir, maxSize - size, owner, terrain); - PlotPlayer plotPlayer = PlotSquared.platform().getPlayerManager().getPlayerIfExists(player.getUUID()); + plot.getPlotModificationManager().autoMerge(dir, maxSize - size, owner, terrain); + PlotPlayer plotPlayer = PlotSquared.platform().getPlayerManager().getPlayerIfExists(player.getUUID()); if (plotPlayer == null) { accepter.sendMessage(TranslatableCaption.of("merge.merge_not_valid")); return; diff --git a/Core/src/main/java/com/plotsquared/core/command/Move.java b/Core/src/main/java/com/plotsquared/core/command/Move.java index d3b7104f5..7a7893026 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Move.java +++ b/Core/src/main/java/com/plotsquared/core/command/Move.java @@ -107,7 +107,7 @@ public class Move extends SubCommand { return CompletableFuture.completedFuture(false); } - return plot1.move(plot2, () -> { + return plot1.getPlotModificationManager().move(plot2, () -> { }, false).thenApply(result -> { if (result) { player.sendMessage(TranslatableCaption.of("move.move_success")); diff --git a/Core/src/main/java/com/plotsquared/core/command/Owner.java b/Core/src/main/java/com/plotsquared/core/command/Owner.java index 5128002aa..b7e4552b5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Owner.java +++ b/Core/src/main/java/com/plotsquared/core/command/Owner.java @@ -106,11 +106,11 @@ public class Owner extends SetCommand { Template.of("value", "Unlink on owner change")); return; } - plot.unlinkPlot(unlinkEvent.isCreateRoad(), unlinkEvent.isCreateRoad()); + plot.getPlotModificationManager().unlinkPlot(unlinkEvent.isCreateRoad(), unlinkEvent.isCreateRoad()); Set connected = plot.getConnectedPlots(); for (Plot current : connected) { current.unclaim(); - current.removeSign(); + current.getPlotModificationManager().removeSign(); } player.sendMessage(TranslatableCaption.of("owner.set_owner")); return; @@ -148,7 +148,7 @@ public class Owner extends SetCommand { if (plot.setOwner(finalUUID, player)) { if (removeDenied) plot.removeDenied(finalUUID); - plot.setSign(finalName); + plot.getPlotModificationManager().setSign(finalName); player.sendMessage(TranslatableCaption.of("owner.set_owner")); if (other != null) { other.sendMessage( diff --git a/Core/src/main/java/com/plotsquared/core/command/Purge.java b/Core/src/main/java/com/plotsquared/core/command/Purge.java index 01350c24f..727fdda46 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -215,13 +215,13 @@ public class Purge extends SubCommand { try { ids.add(plot.temp); if (finalClear) { - plot.clear(false, true, () -> { + plot.getPlotModificationManager().clear(false, true, () -> { if (Settings.DEBUG) { logger.info("Plot {} cleared by purge", plot.getId()); } }); } else { - plot.removeSign(); + plot.getPlotModificationManager().removeSign(); } plot.getArea().removePlot(plot.getId()); for (PlotPlayer pp : plot.getPlayersInPlot()) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Set.java b/Core/src/main/java/com/plotsquared/core/command/Set.java index 9b35c68f2..f3f2a3648 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Set.java +++ b/Core/src/main/java/com/plotsquared/core/command/Set.java @@ -154,8 +154,8 @@ public class Set extends SubCommand { BackupManager.backup(player, plot, () -> { plot.addRunning(); QueueCoordinator queue = plotArea.getQueue(); - for (Plot current : plot.getConnectedPlots()) { - current.setComponent(component, pattern, queue); + for (final Plot current : plot.getConnectedPlots()) { + current.getPlotModificationManager().setComponent(component, pattern, queue); } queue.setCompleteTask(plot::removeRunning); queue.enqueue(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Swap.java b/Core/src/main/java/com/plotsquared/core/command/Swap.java index a7786db3b..6d31ef7ae 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Swap.java +++ b/Core/src/main/java/com/plotsquared/core/command/Swap.java @@ -85,7 +85,7 @@ public class Swap extends SubCommand { return CompletableFuture.completedFuture(false); } - return plot1.move(plot2, () -> { + return plot1.getPlotModificationManager().move(plot2, () -> { }, true).thenApply(result -> { if (result) { player.sendMessage(TranslatableCaption.of("swap.swap_success")); diff --git a/Core/src/main/java/com/plotsquared/core/command/Unlink.java b/Core/src/main/java/com/plotsquared/core/command/Unlink.java index 9101e7827..7ed9995bc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Unlink.java +++ b/Core/src/main/java/com/plotsquared/core/command/Unlink.java @@ -96,7 +96,7 @@ public class Unlink extends SubCommand { player.sendMessage(TranslatableCaption.of("permission.no_plot_perms")); } Runnable runnable = () -> { - if (!plot.unlinkPlot(createRoad, createRoad)) { + if (!plot.getPlotModificationManager().unlinkPlot(createRoad, createRoad)) { player.sendMessage(TranslatableCaption.of("merge.unmerge_cancelled")); return; } diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java index c8dbcdee4..9143257cf 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -194,7 +194,7 @@ public class ComponentPresetManager { plot.addRunning(); QueueCoordinator queue = plot.getArea().getQueue(); for (Plot current : plot.getConnectedPlots()) { - current.setComponent(componentPreset.getComponent().name(), pattern, queue); + current.getPlotModificationManager().setComponent(componentPreset.getComponent().name(), pattern, queue); } queue.setCompleteTask(plot::removeRunning); queue.enqueue(); diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java index c1ec78c91..ca8b5013a 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java @@ -227,7 +227,7 @@ public class ClassicPlotManager extends SquarePlotManager { } int maxY = classicPlotWorld.getPlotManager().getWorldHeight(); - if (!plot.getMerged(Direction.NORTH)) { + if (!plot.isMerged(Direction.NORTH)) { int z = bottom.getZ(); for (int x = bottom.getX(); x <= top.getX(); x++) { for (int y = classicPlotWorld.PLOT_HEIGHT; y <= maxY; y++) { @@ -235,7 +235,7 @@ public class ClassicPlotManager extends SquarePlotManager { } } } - if (!plot.getMerged(Direction.WEST)) { + if (!plot.isMerged(Direction.WEST)) { int x = bottom.getX(); for (int z = bottom.getZ(); z <= top.getZ(); z++) { for (int y = classicPlotWorld.PLOT_HEIGHT; y <= maxY; y++) { @@ -244,7 +244,7 @@ public class ClassicPlotManager extends SquarePlotManager { } } - if (!plot.getMerged(Direction.SOUTH)) { + if (!plot.isMerged(Direction.SOUTH)) { int z = top.getZ(); for (int x = bottom.getX(); x <= top.getX(); x++) { for (int y = classicPlotWorld.PLOT_HEIGHT; y <= maxY; y++) { @@ -252,7 +252,7 @@ public class ClassicPlotManager extends SquarePlotManager { } } } - if (!plot.getMerged(Direction.EAST)) { + if (!plot.isMerged(Direction.EAST)) { int x = top.getX(); for (int z = bottom.getZ(); z <= top.getZ(); z++) { for (int y = classicPlotWorld.PLOT_HEIGHT; y <= maxY; y++) { @@ -293,7 +293,7 @@ public class ClassicPlotManager extends SquarePlotManager { if (plot == null) { return false; } - Location bot = plot.getExtendedBottomAbs().subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0, plot.getMerged(Direction.NORTH) ? 0 : 1); + Location bot = plot.getExtendedBottomAbs().subtract(plot.isMerged(Direction.WEST) ? 0 : 1, 0, plot.isMerged(Direction.NORTH) ? 0 : 1); Location top = plot.getExtendedTopAbs().add(1, 0, 1); boolean enqueue = false; @@ -302,7 +302,7 @@ public class ClassicPlotManager extends SquarePlotManager { enqueue = true; } - if (!plot.getMerged(Direction.NORTH)) { + if (!plot.isMerged(Direction.NORTH)) { int z = bot.getZ(); for (int x = bot.getX(); x < top.getX(); x++) { for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) { @@ -310,7 +310,7 @@ public class ClassicPlotManager extends SquarePlotManager { } } } - if (!plot.getMerged(Direction.WEST)) { + if (!plot.isMerged(Direction.WEST)) { int x = bot.getX(); for (int z = bot.getZ(); z < top.getZ(); z++) { for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) { @@ -318,17 +318,17 @@ public class ClassicPlotManager extends SquarePlotManager { } } } - if (!plot.getMerged(Direction.SOUTH)) { + if (!plot.isMerged(Direction.SOUTH)) { int z = top.getZ(); - for (int x = bot.getX(); x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) { + for (int x = bot.getX(); x < top.getX() + (plot.isMerged(Direction.EAST) ? 0 : 1); x++) { for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) { queue.setBlock(x, y, z, blocks); } } } - if (!plot.getMerged(Direction.EAST)) { + if (!plot.isMerged(Direction.EAST)) { int x = top.getX(); - for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) { + for (int z = bot.getZ(); z < top.getZ() + (plot.isMerged(Direction.SOUTH) ? 0 : 1); z++) { for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) { queue.setBlock(x, y, z, blocks); } @@ -360,7 +360,7 @@ public class ClassicPlotManager extends SquarePlotManager { if (plot == null) { return false; } - Location bot = plot.getExtendedBottomAbs().subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0, plot.getMerged(Direction.NORTH) ? 0 : 1); + Location bot = plot.getExtendedBottomAbs().subtract(plot.isMerged(Direction.WEST) ? 0 : 1, 0, plot.isMerged(Direction.NORTH) ? 0 : 1); Location top = plot.getExtendedTopAbs().add(1, 0, 1); boolean enqueue = false; @@ -370,27 +370,27 @@ public class ClassicPlotManager extends SquarePlotManager { } int y = classicPlotWorld.WALL_HEIGHT + 1; - if (!plot.getMerged(Direction.NORTH)) { + if (!plot.isMerged(Direction.NORTH)) { int z = bot.getZ(); for (int x = bot.getX(); x < top.getX(); x++) { queue.setBlock(x, y, z, blocks); } } - if (!plot.getMerged(Direction.WEST)) { + if (!plot.isMerged(Direction.WEST)) { int x = bot.getX(); for (int z = bot.getZ(); z < top.getZ(); z++) { queue.setBlock(x, y, z, blocks); } } - if (!plot.getMerged(Direction.SOUTH)) { + if (!plot.isMerged(Direction.SOUTH)) { int z = top.getZ(); - for (int x = bot.getX(); x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) { + for (int x = bot.getX(); x < top.getX() + (plot.isMerged(Direction.EAST) ? 0 : 1); x++) { queue.setBlock(x, y, z, blocks); } } - if (!plot.getMerged(Direction.EAST)) { + if (!plot.isMerged(Direction.EAST)) { int x = top.getX(); - for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) { + for (int z = bot.getZ(); z < top.getZ() + (plot.isMerged(Direction.SOUTH) ? 0 : 1); z++) { queue.setBlock(x, y, z, blocks); } } diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java index 855a15189..8c4b09fdd 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java @@ -210,28 +210,28 @@ public abstract class SquarePlotManager extends GridPlotManager { switch (hash) { case 8: // north - return plot.getMerged(Direction.NORTH) ? id : null; + return plot.isMerged(Direction.NORTH) ? id : null; case 4: // east - return plot.getMerged(Direction.EAST) ? id : null; + return plot.isMerged(Direction.EAST) ? id : null; case 2: // south - return plot.getMerged(Direction.SOUTH) ? id : null; + return plot.isMerged(Direction.SOUTH) ? id : null; case 1: // west - return plot.getMerged(Direction.WEST) ? id : null; + return plot.isMerged(Direction.WEST) ? id : null; case 12: // northeast - return plot.getMerged(Direction.NORTHEAST) ? id : null; + return plot.isMerged(Direction.NORTHEAST) ? id : null; case 6: // southeast - return plot.getMerged(Direction.SOUTHEAST) ? id : null; + return plot.isMerged(Direction.SOUTHEAST) ? id : null; case 3: // southwest - return plot.getMerged(Direction.SOUTHWEST) ? id : null; + return plot.isMerged(Direction.SOUTHWEST) ? id : null; case 9: // northwest - return plot.getMerged(Direction.NORTHWEST) ? id : null; + return plot.isMerged(Direction.NORTHWEST) ? id : null; } } catch (Exception ignored) { logger.error("Invalid plot / road width in settings.yml for world: {}", squarePlotWorld.getWorldName()); diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index f211f40de..b8c123495 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -262,15 +262,6 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, return Permissions.hasPermissionRange(this, "plots.plot", Settings.Limit.MAX_PLOTS); } - /** - * Get the total number of allowed clusters - * - * @return number of allowed clusters within the scope (globally, or in the player's current world as defined in the settings.yml) - */ - public int getAllowedClusters() { - return Permissions.hasPermissionRange(this, "plots.cluster", Settings.Limit.MAX_PLOTS); - } - /** * Get the number of plots this player owns. * @@ -588,7 +579,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, } if (Settings.Enabled_Components.BAN_DELETER && isBanned()) { for (Plot owned : getPlots()) { - owned.deletePlot(null); + owned.getPlotModificationManager().deletePlot(null); if (Settings.DEBUG) { logger.info("Plot {} was deleted + cleared due to {} getting banned", owned.getId(), getName()); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 8926eff3b..c2689461e 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -31,20 +31,14 @@ import com.google.common.collect.Sets; import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.Like; -import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.CaptionUtility; import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; -import com.plotsquared.core.events.PlotComponentSetEvent; -import com.plotsquared.core.events.PlotMergeEvent; -import com.plotsquared.core.events.PlotUnlinkEvent; import com.plotsquared.core.events.Result; import com.plotsquared.core.events.TeleportCause; -import com.plotsquared.core.generator.SquarePlotWorld; -import com.plotsquared.core.inject.annotations.ImpromptuPipeline; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.BlockLoc; import com.plotsquared.core.location.Direction; @@ -64,7 +58,6 @@ import com.plotsquared.core.plot.flag.implementations.KeepFlag; import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag; import com.plotsquared.core.plot.flag.types.DoubleFlag; import com.plotsquared.core.plot.schematic.Schematic; -import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MathMan; @@ -79,14 +72,9 @@ import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskTime; -import com.plotsquared.core.uuid.UUIDPipeline; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.function.pattern.Pattern; -import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BlockTypes; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; @@ -95,11 +83,6 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.awt.geom.Area; -import java.awt.geom.PathIterator; -import java.awt.geom.Rectangle2D; -import java.io.File; -import java.net.URL; import java.text.DecimalFormat; import java.util.ArrayDeque; import java.util.ArrayList; @@ -107,7 +90,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -116,9 +98,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; -import java.util.stream.Collectors; import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL; import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY; @@ -143,8 +123,8 @@ public class Plot { private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0"); private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); - private static Set connected_cache; - private static Set regions_cache; + static Set connected_cache; + static Set regions_cache; static { FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340); } @@ -157,9 +137,9 @@ public class Plot { */ private final PlotCommentContainer plotCommentContainer = new PlotCommentContainer(this); /** - * Has the plot changed since the last save cycle? + * Utility used to modify the plot */ - public boolean countsTowardsMax = true; + private final PlotModificationManager plotModificationManager = new PlotModificationManager(this); /** * Represents whatever the database manager needs it to:
* - A value of -1 usually indicates the plot will not be stored in the DB
@@ -173,10 +153,8 @@ public class Plot { @Inject private EventDispatcher eventDispatcher; @Inject private PlotListener plotListener; @Inject private RegionManager regionManager; - @Inject private GlobalBlockQueue blockQueue; @Inject private WorldUtil worldUtil; @Inject private SchematicHandler schematicHandler; - @Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline; /** * plot owner * (Merged plots can have multiple owners) @@ -193,21 +171,21 @@ public class Plot { /** * List of trusted (with plot permissions). */ - private HashSet trusted; + HashSet trusted; /** * List of members users (with plot permissions). */ - private HashSet members; + HashSet members; /** * List of denied players. */ - private HashSet denied; + 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; + PlotSettings settings; private PlotArea area; /** * Session only plot metadata (session is until the server stops)
@@ -347,7 +325,7 @@ public class Plot { } else { area = ConsolePlayer.getConsole().getApplicablePlotArea(); } - String[] split = arg.split(";|,"); + String[] split = arg.split("[;,]"); PlotId id; if (split.length == 4) { area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[0] + ';' + split[1]); @@ -392,7 +370,7 @@ public class Plot { * @return New or existing plot object */ @Nullable public static Plot fromString(@Nullable final PlotArea defaultArea, @Nonnull final String string) { - final String[] split = string.split(";|,"); + final String[] split = string.split("[;,]"); if (split.length == 2) { if (defaultArea != null) { PlotId id = PlotId.fromString(split[0] + ';' + split[1]); @@ -421,7 +399,7 @@ public class Plot { * @return plot at location or null * @see PlotPlayer#getCurrentPlot() if a player is expected here. */ - @Nullable public static Plot getPlot(@Nullable final Location location) { + @Nullable public static Plot getPlot(@Nonnull final Location location) { final PlotArea pa = location.getPlotArea(); if (pa != null) { return pa.getPlot(location); @@ -429,7 +407,7 @@ public class Plot { return null; } - @Nonnull private static Location[] getCorners(@Nonnull final String world, @Nonnull final CuboidRegion region) { + @Nonnull static Location[] getCorners(@Nonnull final String world, @Nonnull final CuboidRegion region) { final BlockVector3 min = region.getMinimumPoint(); final BlockVector3 max = region.getMaximumPoint(); return new Location[] {Location.at(world, min), Location.at(world, max)}; @@ -463,7 +441,12 @@ public class Plot { this.owner = owner; } - public String getWorldName() { + /** + * Get the name of the world that the plot is in + * + * @return World name + */ + @Nullable public String getWorldName() { return area.getWorldName(); } @@ -475,7 +458,7 @@ public class Plot { * @param key metadata key * @param value metadata value */ - public void setMeta(String key, Object value) { + public void setMeta(@Nonnull final String key, @Nonnull final Object value) { if (this.meta == null) { this.meta = new ConcurrentHashMap<>(); } @@ -490,7 +473,7 @@ public class Plot { * @param key metadata key to get value for * @return Object value */ - public Object getMeta(String key) { + @Nullable public Object getMeta(@Nonnull final String key) { if (this.meta != null) { return this.meta.get(key); } @@ -504,7 +487,7 @@ public class Plot { * * @param key key to delete */ - public void deleteMeta(String key) { + public void deleteMeta(@Nonnull final String key) { if (this.meta != null) { this.meta.remove(key); } @@ -515,7 +498,10 @@ public class Plot { * * @return the PlotCluster object, or null */ - public PlotCluster getCluster() { + @Nullable public PlotCluster getCluster() { + if (this.getArea() == null) { + return null; + } return this.getArea().getCluster(this.id); } @@ -526,7 +512,7 @@ public class Plot { * * @return list of PlotPlayer(s) or an empty list */ - public List> getPlayersInPlot() { + @Nonnull public List> getPlayersInPlot() { final List> players = new ArrayList<>(); for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { if (this.equals(player.getCurrentPlot())) { @@ -539,7 +525,7 @@ public class Plot { /** * Checks if the plot has an owner. * - * @return false if there is no owner + * @return {@code true} if there is an owner, else {@code false} */ public boolean hasOwner() { return this.getOwnerAbs() != null; @@ -548,20 +534,26 @@ public class Plot { /** * Checks if a UUID is a plot owner (merged plots may have multiple owners) * - * @param uuid the player uuid - * @return if the provided uuid is the owner of the plot + * @param uuid Player UUID + * @return {@code true} if the provided uuid is the owner of the plot, else {@code false} */ - public boolean isOwner(@Nonnull UUID uuid) { + public boolean isOwner(@Nonnull final UUID uuid) { if (uuid.equals(this.getOwner())) { return true; } if (!isMerged()) { return false; } - Set connected = getConnectedPlots(); + final Set connected = getConnectedPlots(); return connected.stream().anyMatch(current -> uuid.equals(current.getOwner())); } + /** + * Checks if the given UUID is the owner of this specific plot + * + * @param uuid Player UUID + * @return {@code true} if the provided uuid is the owner of the plot, else {@code false} + */ public boolean isOwnerAbs(@Nullable final UUID uuid) { if (uuid == null) { return false; @@ -578,7 +570,7 @@ public class Plot { * * @return Server if ServerPlot flag set, else {@link #getOwnerAbs()} */ - public UUID getOwner() { + @Nullable public UUID getOwner() { if (this.getFlag(ServerPlotFlag.class)) { return DBFunc.SERVER; } @@ -590,10 +582,10 @@ public class Plot { * * @param owner uuid to set as owner */ - public void setOwner(UUID owner) { + public void setOwner(@Nonnull final UUID owner) { if (!hasOwner()) { this.setOwnerAbs(owner); - create(); + this.getPlotModificationManager().create(); return; } if (!isMerged()) { @@ -603,7 +595,7 @@ public class Plot { } return; } - for (Plot current : getConnectedPlots()) { + for (final Plot current : getConnectedPlots()) { if (!owner.equals(current.getOwnerAbs())) { current.setOwnerAbs(owner); DBFunc.setOwner(current, owner); @@ -617,9 +609,9 @@ public class Plot { * This method cannot be used to add or remove owners from a plot. *

* - * @return the plot owners + * @return Immutable view of plot owners */ - public Set getOwners() { + @Nonnull public Set getOwners() { if (this.getOwner() == null) { return ImmutableSet.of(); } @@ -629,7 +621,10 @@ public class Plot { ImmutableSet.Builder owners = ImmutableSet.builder(); UUID last = this.getOwner(); owners.add(this.getOwner()); - for (Plot current : array) { + for (final Plot current : array) { + if (current.getOwner() == null) { + continue; + } if (last == null || current.getOwner().getMostSignificantBits() != last.getMostSignificantBits()) { owners.add(current.getOwner()); last = current.getOwner(); @@ -644,9 +639,9 @@ public class Plot { * Checks if the player is either the owner or on the trusted/added list. * * @param uuid uuid to check - * @return true if the player is added/trusted or is the owner + * @return {@code true} if the player is added/trusted or is the owner, else {@code false} */ - public boolean isAdded(UUID uuid) { + public boolean isAdded(@Nonnull final UUID uuid) { if (!this.hasOwner() || getDenied().contains(uuid)) { return false; } @@ -669,9 +664,9 @@ public class Plot { * Checks if the player is not permitted on this plot. * * @param uuid uuid to check - * @return boolean false if the player is allowed to enter + * @return {@code false} if the player is allowed to enter the plot, else {@code true} */ - public boolean isDenied(UUID uuid) { + public boolean isDenied(@Nonnull final UUID uuid) { return this.denied != null && (this.denied.contains(DBFunc.EVERYONE) && !this.isAdded(uuid) || !this.isAdded(uuid) && this.denied .contains(uuid)); } @@ -700,7 +695,7 @@ public class Plot { * * @return PlotArea */ - public PlotArea getArea() { + @Nullable public PlotArea getArea() { return this.area; } @@ -713,7 +708,7 @@ public class Plot { * * @param area area to assign to */ - public void setArea(PlotArea area) { + public void setArea(@Nonnull final PlotArea area) { if (this.getArea() == area) { return; } @@ -731,7 +726,7 @@ public class Plot { * * @return PlotManager */ - public PlotManager getManager() { + @Nonnull public PlotManager getManager() { return this.area.getPlotManager(); } @@ -740,7 +735,7 @@ public class Plot { * * @return PlotSettings */ - public PlotSettings getSettings() { + @Nonnull public PlotSettings getSettings() { if (this.settings == null) { this.settings = new PlotSettings(); } @@ -768,7 +763,7 @@ public class Plot { * * @return base Plot */ - public Plot getBasePlot(boolean recalculate) { + public Plot getBasePlot(final boolean recalculate) { if (this.origin != null && !recalculate) { if (this.equals(this.origin)) { return this; @@ -796,7 +791,7 @@ public class Plot { /** * Checks if this plot is merged in any direction. * - * @return true if this plot is merged, otherwise false + * @return {@code true} if this plot is merged, otherwise {@code false} */ public boolean isMerged() { return getSettings().getMerged(0) || getSettings().getMerged(2) || getSettings().getMerged(1) || getSettings().getMerged(3); @@ -829,13 +824,13 @@ public class Plot { * 6 = south-west
* 7 = north-west
* ----------
- * //todo these artificial values are way too confusing. + * * Note: A plot that is merged north and east will not be merged northeast if the northeast plot is not part of the same group
* * @param dir direction to check for merged plot - * @return true if merged in that direction + * @return {@code true} if merged in that direction, else {@code false} */ - public boolean getMerged(int dir) { + public boolean isMerged(final int dir) { if (this.settings == null) { return false; } @@ -850,8 +845,10 @@ public class Plot { int i2 = 0; if (this.getSettings().getMerged(i2)) { if (this.getSettings().getMerged(i)) { - if (this.area.getPlotAbs(this.id.getRelative(Direction.getFromIndex(i))).getMerged(i2)) { - return this.area.getPlotAbs(this.id.getRelative(Direction.getFromIndex(i2))).getMerged(i); + if (Objects.requireNonNull( + this.area.getPlotAbs(this.id.getRelative(Direction.getFromIndex(i)))).isMerged(i2)) { + return Objects.requireNonNull(this.area + .getPlotAbs(this.id.getRelative(Direction.getFromIndex(i2)))).isMerged(i); } } } @@ -861,9 +858,11 @@ public class Plot { case 6: i = dir - 4; i2 = dir - 3; - return this.getSettings().getMerged(i2) && this.getSettings().getMerged(i) && this.area - .getPlotAbs(this.id.getRelative(Direction.getFromIndex(i))).getMerged(i2) && this.area - .getPlotAbs(this.id.getRelative(Direction.getFromIndex(i2))).getMerged(i); + return this.getSettings().getMerged(i2) && this.getSettings().getMerged(i) && Objects + .requireNonNull( + this.area.getPlotAbs(this.id.getRelative(Direction.getFromIndex(i)))).isMerged(i2) && Objects + .requireNonNull( + this.area.getPlotAbs(this.id.getRelative(Direction.getFromIndex(i2)))).isMerged(i); } return false; @@ -874,7 +873,7 @@ public class Plot { * * @return a set of denied users */ - public HashSet getDenied() { + @Nonnull public HashSet getDenied() { if (this.denied == null) { this.denied = new HashSet<>(); } @@ -886,7 +885,7 @@ public class Plot { * * @param uuids uuids to deny */ - public void setDenied(Set uuids) { + public void setDenied(@Nonnull final Set uuids) { boolean larger = uuids.size() > getDenied().size(); HashSet intersection; if (larger) { @@ -915,7 +914,7 @@ public class Plot { * * @return a set of trusted users */ - public HashSet getTrusted() { + @Nonnull public HashSet getTrusted() { if (this.trusted == null) { this.trusted = new HashSet<>(); } @@ -927,7 +926,7 @@ public class Plot { * * @param uuids uuids to trust */ - public void setTrusted(Set uuids) { + public void setTrusted(@Nonnull final Set uuids) { boolean larger = uuids.size() > getTrusted().size(); HashSet intersection = new HashSet<>(larger ? getTrusted() : uuids); intersection.retainAll(larger ? uuids : getTrusted()); @@ -947,7 +946,7 @@ public class Plot { * * @return a set of members */ - public HashSet getMembers() { + @Nonnull public HashSet getMembers() { if (this.members == null) { this.members = new HashSet<>(); } @@ -959,7 +958,7 @@ public class Plot { * * @param uuids uuids to set member status for */ - public void setMembers(Set uuids) { + public void setMembers(@Nonnull final Set uuids) { boolean larger = uuids.size() > getMembers().size(); HashSet intersection = new HashSet<>(larger ? getMembers() : uuids); intersection.retainAll(larger ? uuids : getMembers()); @@ -979,8 +978,8 @@ public class Plot { * * @param uuid the uuid of the player to deny. */ - public void addDenied(UUID uuid) { - for (Plot current : getConnectedPlots()) { + public void addDenied(@Nonnull final UUID uuid) { + for (final Plot current : getConnectedPlots()) { if (current.getDenied().add(uuid)) { DBFunc.setDenied(current, uuid); } @@ -992,8 +991,8 @@ public class Plot { * * @param uuid the uuid of the player to trust */ - public void addTrusted(UUID uuid) { - for (Plot current : getConnectedPlots()) { + public void addTrusted(@Nonnull final UUID uuid) { + for (final Plot current : getConnectedPlots()) { if (current.getTrusted().add(uuid)) { DBFunc.setTrusted(current, uuid); } @@ -1005,8 +1004,8 @@ public class Plot { * * @param uuid the uuid of the player to add as a member */ - public void addMember(UUID uuid) { - for (Plot current : getConnectedPlots()) { + public void addMember(@Nonnull final UUID uuid) { + for (final Plot current : getConnectedPlots()) { if (current.getMembers().add(uuid)) { DBFunc.setMember(current, uuid); } @@ -1020,10 +1019,10 @@ public class Plot { * @param initiator player initiating set owner * @return boolean */ - public boolean setOwner(UUID owner, PlotPlayer initiator) { + public boolean setOwner(UUID owner, PlotPlayer initiator) { if (!hasOwner()) { this.setOwnerAbs(owner); - create(); + this.getPlotModificationManager().create(); return true; } if (!isMerged()) { @@ -1042,183 +1041,6 @@ public class Plot { return true; } - /** - * Clear a plot. - * - * @param whenDone A runnable to execute when clearing finishes, or null - * @see #clear(boolean, boolean, Runnable) - * @see #deletePlot(Runnable) to clear and delete a plot - */ - public void clear(Runnable whenDone) { - this.clear(false, false, whenDone); - } - - public boolean clear(boolean checkRunning, final boolean isDelete, final Runnable whenDone) { - if (checkRunning && this.getRunning() != 0) { - return false; - } - final Set regions = this.getRegions(); - final Set plots = this.getConnectedPlots(); - final ArrayDeque queue = new ArrayDeque<>(plots); - if (isDelete) { - this.removeSign(); - } - PlotUnlinkEvent event = this.eventDispatcher - .callUnlink(getArea(), this, true, !isDelete, isDelete ? PlotUnlinkEvent.REASON.DELETE : PlotUnlinkEvent.REASON.CLEAR); - if (event.getEventResult() != Result.DENY) { - this.unlinkPlot(event.isCreateRoad(), event.isCreateSign()); - } - final PlotManager manager = this.area.getPlotManager(); - Runnable run = new Runnable() { - @Override public void run() { - if (queue.isEmpty()) { - Runnable run = () -> { - for (CuboidRegion region : regions) { - Location[] corners = getCorners(getWorldName(), region); - regionManager.clearAllEntities(corners[0], corners[1]); - } - TaskManager.runTask(whenDone); - }; - QueueCoordinator queue = getArea().getQueue(); - for (Plot current : plots) { - if (isDelete || !current.hasOwner()) { - manager.unClaimPlot(current, null, queue); - } else { - manager.claimPlot(current, queue); - } - } - if (queue.size() > 0) { - queue.enqueue(); - } - TaskManager.runTask(run); - return; - } - Plot current = queue.poll(); - if (Plot.this.area.getTerrain() != PlotAreaTerrainType.NONE) { - try { - regionManager.regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false, this); - } catch (UnsupportedOperationException exception) { - logger.info("Please ask md_5 to fix regenerateChunk() because it breaks plugins. We apologize for the inconvenience."); - return; - } - return; - } - manager.clearPlot(current, this, null); - } - }; - run.run(); - return true; - } - - /** - * Sets the biome for a plot asynchronously. - * - * @param biome The biome e.g. "forest" - * @param whenDone The task to run when finished, or null - */ - public void setBiome(final BiomeType biome, final Runnable whenDone) { - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); - final int extendBiome; - if (area instanceof SquarePlotWorld) { - extendBiome = (((SquarePlotWorld) area).ROAD_WIDTH > 0) ? 1 : 0; - } else { - extendBiome = 0; - } - Runnable run = new Runnable() { - @Override public void run() { - if (regions.isEmpty()) { - TaskManager.runTask(whenDone); - return; - } - CuboidRegion region = regions.poll(); - regionManager.setBiome(region, extendBiome, biome, getWorldName(), this); - } - }; - run.run(); - } - - /** - * Unlink the plot and all connected plots. - * - * @param createRoad whether to recreate road - * @param createSign whether to recreate signs - * @return success/!cancelled - */ - public boolean unlinkPlot(boolean createRoad, boolean createSign) { - if (!this.isMerged()) { - return false; - } - final Set plots = this.getConnectedPlots(); - ArrayList ids = new ArrayList<>(plots.size()); - for (Plot current : plots) { - current.setHome(null); - ids.add(current.getId()); - } - this.clearRatings(); - QueueCoordinator queue = null; - if (createSign) { - this.removeSign(); - queue = getArea().getQueue(); - } - PlotManager manager = this.area.getPlotManager(); - if (createRoad) { - manager.startPlotUnlink(ids, queue); - } - if (this.area.getTerrain() != PlotAreaTerrainType.ALL && createRoad) { - for (Plot current : plots) { - if (current.getMerged(Direction.EAST)) { - manager.createRoadEast(current, queue); - if (current.getMerged(Direction.SOUTH)) { - manager.createRoadSouth(current, queue); - if (current.getMerged(Direction.SOUTHEAST)) { - manager.createRoadSouthEast(current, queue); - } - } - } - if (current.getMerged(Direction.SOUTH)) { - manager.createRoadSouth(current, queue); - } - } - } - for (Plot current : plots) { - boolean[] merged = new boolean[] {false, false, false, false}; - current.setMerged(merged); - } - if (createSign) { - queue.setCompleteTask(() -> TaskManager.runTaskAsync(() -> { - for (Plot current : plots) { - current.setSign(PlayerManager.getName(current.getOwnerAbs())); - } - })); - } - if (createRoad) { - manager.finishPlotUnlink(ids, queue); - } - return true; - } - - /** - * Sets the sign for a plot to a specific name - * - * @param name name - */ - public void setSign(@Nonnull String name) { - if (!isLoaded()) { - return; - } - PlotManager manager = this.area.getPlotManager(); - if (this.area.allowSigns()) { - Location location = manager.getSignLoc(this); - String id = this.id.toString(); - Caption[] lines = - new Caption[] {TranslatableCaption.of("signs.owner_sign_line_1"), - TranslatableCaption.of("signs.owner_sign_line_2"), - TranslatableCaption.of("signs.owner_sign_line_3"), - TranslatableCaption.of("signs.owner_sign_line_4")}; - this.worldUtil.setSign(location, lines, Template.of("id", id), Template.of("owner", name)); - } - } - public boolean isLoaded() { return this.worldUtil.isWorld(getWorldName()); } @@ -1234,10 +1056,6 @@ public class Plot { return PlotAnalysis.getAnalysis(this, settings); } - public void analyze(RunnableVal whenDone) { - PlotAnalysis.analyzePlot(this, whenDone); - } - /** * Get an immutable view of all the flags associated with the plot. * @@ -1254,7 +1072,7 @@ public class Plot { * @param flag value type * @return A boolean indicating whether or not the operation succeeded */ - public boolean setFlag(PlotFlag flag) { + public boolean setFlag(@Nonnull final PlotFlag flag) { if (flag instanceof KeepFlag && ExpireManager.IMP != null) { ExpireManager.IMP.updateExpired(this); } @@ -1274,7 +1092,7 @@ public class Plot { * @param value Flag value * @return A boolean indicating whether or not the operation succeeded */ - public boolean setFlag(Class flag, String value) { + public boolean setFlag(@Nonnull final Class flag, @Nonnull final String value) { try { this.setFlag(GlobalFlagContainer.getInstance().getFlagErased(flag).parse(value)); } catch (final Exception e) { @@ -1289,7 +1107,7 @@ public class Plot { * @param flag the flag to remove * @return success */ - public boolean removeFlag(Class> flag) { + public boolean removeFlag(@Nonnull final Class> flag) { return this.removeFlag(getFlagContainer().queryLocal(flag)); } @@ -1321,7 +1139,7 @@ public class Plot { } else { flags.putAll(flagMap); } - return flagMap.values(); + return flags.values(); } /** @@ -1340,7 +1158,7 @@ public class Plot { * @param flag the flag to remove * @return success */ - public boolean removeFlag(PlotFlag flag) { + public boolean removeFlag(@Nonnull final PlotFlag flag) { if (flag == null) { return false; } @@ -1357,30 +1175,6 @@ public class Plot { return removed; } - /** - * Delete a plot (use null for the runnable if you don't need to be notified on completion) - * - * @see PlotSquared#removePlot(Plot, boolean) - * @see #clear(boolean, boolean, Runnable) to simply clear a plot - * - * @param whenDone task to run when plot has been deleted. Nullable - * - * @return success status - */ - public boolean deletePlot(final Runnable whenDone) { - if (!this.hasOwner()) { - return false; - } - final Set plots = this.getConnectedPlots(); - this.clear(false, true, () -> { - for (Plot current : plots) { - current.unclaim(); - } - TaskManager.runTask(whenDone); - }); - return true; - } - /** * Count the entities in a plot * @@ -1475,23 +1269,13 @@ public class Plot { DBFunc.delete(current); current.setOwnerAbs(null); current.settings = null; - for (PlotPlayer pp : players) { + for (final PlotPlayer pp : players) { this.plotListener.plotEntry(pp, current); } } return true; } - /** - * Unlink a plot and remove the roads - * - * @return true if plot was linked - * @see #unlinkPlot(boolean, boolean) - */ - public boolean unlink() { - return this.unlinkPlot(true, true); - } - public void getCenter(final Consumer result) { Location[] corners = getCorners(); Location top = corners[0]; @@ -1798,72 +1582,17 @@ public class Plot { return base.settings != null && base.settings.getRatings() != null; } - /** - * Resend all chunks inside the plot to nearby players
- * This should not need to be called - */ - public void refreshChunks() { - QueueCoordinator queue = this.blockQueue.getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(getWorldName())); - HashSet chunks = new HashSet<>(); - for (CuboidRegion region : Plot.this.getRegions()) { - for (int x = region.getMinimumPoint().getX() >> 4; x <= region.getMaximumPoint().getX() >> 4; x++) { - for (int z = region.getMinimumPoint().getZ() >> 4; z <= region.getMaximumPoint().getZ() >> 4; z++) { - if (chunks.add(BlockVector2.at(x, z))) { - worldUtil.refreshChunk(x, z, getWorldName()); - } - } - } - } - } - - /** - * Remove the plot sign if it is set. - */ - public void removeSign() { - PlotManager manager = this.area.getPlotManager(); - if (!this.area.allowSigns()) { - return; - } - Location location = manager.getSignLoc(this); - QueueCoordinator queue = this.blockQueue.getNewQueue(worldUtil.getWeWorld(getWorldName())); - queue.setBlock(location.getX(), location.getY(), location.getZ(), BlockTypes.AIR.getDefaultState()); - queue.enqueue(); - } - - /** - * Sets the plot sign if plot signs are enabled. - */ - public void setSign() { - if (!this.hasOwner()) { - this.setSign("unknown"); - return; - } - this.impromptuPipeline.getSingle(this.getOwnerAbs(), (username, sign) -> this.setSign(username)); - } - - /** - * Register a plot and create it in the database
- * - The plot will not be created if the owner is null
- * - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot - * creation. - * - * @return true if plot was created successfully - */ - public boolean create() { - return this.create(this.owner, true); - } - - public boolean claim(@Nonnull final PlotPlayer player, boolean teleport, String schematic) { + public boolean claim(@Nonnull final PlotPlayer player, boolean teleport, String schematic) { if (!canClaim(player)) { return false; } return claim(player, teleport, schematic, true); } - public boolean claim(@Nonnull final PlotPlayer player, boolean teleport, String schematic, boolean updateDB) { + public boolean claim(@Nonnull final PlotPlayer player, boolean teleport, String schematic, boolean updateDB) { if (updateDB) { - if (!create(player.getUUID(), true)) { + if (!this.getPlotModificationManager().create(player.getUUID(), true)) { logger.error("Player {} attempted to claim plot {}, but the database failed to update", player.getName(), this.getId().toCommaSeparatedString()); return false; @@ -1872,7 +1601,7 @@ public class Plot { area.addPlot(this); updateWorldBorder(); } - setSign(player.getName()); + this.getPlotModificationManager().setSign(player.getName()); player.sendMessage(TranslatableCaption.of("working.claimed")); if (teleport && Settings.Teleport.ON_CLAIM) { teleportPlayer(player, TeleportCause.COMMAND, result -> { @@ -1908,80 +1637,6 @@ public class Plot { return true; } - - /** - * Register a plot and create it in the database
- * - The plot will not be created if the owner is null
- * - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot - * creation. - * - * @param uuid the uuid of the plot owner - * @param notify notify - * @return true if plot was created successfully - */ - public boolean create(@Nonnull UUID uuid, final boolean notify) { - this.setOwnerAbs(uuid); - Plot existing = this.area.getOwnedPlotAbs(this.id); - if (existing != null) { - throw new IllegalStateException("Plot already exists!"); - } - if (notify) { - Integer meta = (Integer) this.area.getMeta("worldBorder"); - if (meta != null) { - this.updateWorldBorder(); - } - } - connected_cache = null; - regions_cache = null; - this.getTrusted().clear(); - this.getMembers().clear(); - this.getDenied().clear(); - this.settings = new PlotSettings(); - if (this.area.addPlot(this)) { - DBFunc.createPlotAndSettings(this, () -> { - PlotArea plotworld = Plot.this.area; - if (notify && plotworld.isAutoMerge()) { - final PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); - - PlotMergeEvent event = this.eventDispatcher.callMerge(this, Direction.ALL, Integer.MAX_VALUE, player); - - if (event.getEventResult() == Result.DENY) { - if (player != null) { - player.sendMessage(TranslatableCaption.of("events.event_denied"), - Template.of("value", "Auto merge on claim")); - } - return; - } - Plot.this.autoMerge(event.getDir(), event.getMax(), uuid, true); - } - }); - return true; - } - logger.info("Failed to add plot {} to plot area {}", this.getId().toCommaSeparatedString(), this.area.toString()); - return false; - } - - /** - * Sets components such as border, wall, floor. - * (components are generator specific) - * - * @param component component to set - * @param blocks string of block(s) to set component to - * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, - * otherwise writes to the queue but does not enqueue. - * - * @return success or not - */ - @Deprecated public boolean setComponent(String component, String blocks, QueueCoordinator queue) { - BlockBucket parsed = ConfigurationUtil.BLOCK_BUCKET.parseString(blocks); - if (parsed != null && parsed.isEmpty()) { - return false; - } - return this.setComponent(component, parsed.toPattern(), queue); - } - - //TODO Better documentation needed. - /** * Retrieve the biome of the plot. * @@ -2086,10 +1741,10 @@ public class Plot { if (!this.isMerged()) { return top; } - if (this.getMerged(Direction.SOUTH)) { + if (this.isMerged(Direction.SOUTH)) { top = top.withZ(this.getRelative(Direction.SOUTH).getBottomAbs().getZ() - 1); } - if (this.getMerged(Direction.EAST)) { + if (this.isMerged(Direction.EAST)) { top = top.withX(this.getRelative(Direction.EAST).getBottomAbs().getX() - 1); } return top; @@ -2107,10 +1762,10 @@ public class Plot { if (!this.isMerged()) { return bot; } - if (this.getMerged(Direction.NORTH)) { + if (this.isMerged(Direction.NORTH)) { bot = bot.withZ(this.getRelative(Direction.NORTH).getTopAbs().getZ() + 1); } - if (this.getMerged(Direction.WEST)) { + if (this.isMerged(Direction.WEST)) { bot = bot.withX(this.getRelative(Direction.WEST).getTopAbs().getX() + 1); } return bot; @@ -2131,26 +1786,6 @@ public class Plot { return RegionUtil.getCorners(this.getWorldName(), this.getRegions()); } - /** - * Remove the east road section of a plot
- * - Used when a plot is merged
- * - * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, - * otherwise writes to the queue but does not enqueue. - */ - public void removeRoadEast(@Nullable QueueCoordinator queue) { - 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 = Location.at(this.getWorldName(), top.getX(), 0, bot.getZ()); - Location pos2 = Location.at(this.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ()); - this.regionManager.regenerateRegion(pos1, pos2, true, null); - } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove - this.area.getPlotManager().removeRoadEast(this, queue); - } - } - /** * @deprecated in favor of getCorners()[0];
* @return bottom corner location @@ -2169,31 +1804,6 @@ public class Plot { return this.getCorners()[1]; } - /** - * Swap the plot contents and settings with another location
- * - The destination must correspond to a valid plot of equal dimensions - * - * @param destination The other plot to swap with - * @param whenDone A task to run when finished, or null - * @return boolean if swap was successful - * @see #swapData(Plot) to swap plot settings - */ - public CompletableFuture swap(Plot destination, Runnable whenDone) { - return this.move(destination, whenDone, true); - } - - /** - * Moves the plot to an empty location
- * - The location must be empty - * - * @param destination Where to move the plot - * @param whenDone A task to run when done, or null - * @return if the move was successful - */ - public CompletableFuture move(Plot destination, Runnable whenDone) { - return this.move(destination, whenDone, false); - } - /** * Gets plot display name. * @@ -2299,58 +1909,6 @@ public class Plot { return true; } - /** - * Export the plot as a schematic to the configured output directory. - * - * @param whenDone task to run when the export has finished - */ - public void export(final RunnableVal whenDone) { - this.schematicHandler.getCompoundTag(this, new RunnableVal() { - @Override public void run(final CompoundTag value) { - if (value == null) { - if (whenDone != null) { - whenDone.value = false; - TaskManager.runTask(whenDone); - } - } else { - TaskManager.runTaskAsync(() -> { - String name = Plot.this.id + "," + Plot.this.area + ',' + PlayerManager.getName(Plot.this.getOwnerAbs()); - boolean result = schematicHandler.save(value, Settings.Paths.SCHEMATICS + File.separator + name + ".schem"); - if (whenDone != null) { - whenDone.value = result; - TaskManager.runTask(whenDone); - } - }); - } - } - }); - } - - /** - * Upload the plot as a schematic to the configured web interface. - * - * @param whenDone value will be null if uploading fails - */ - public void upload(final RunnableVal whenDone) { - this.schematicHandler.getCompoundTag(this, new RunnableVal() { - @Override public void run(CompoundTag value) { - schematicHandler.upload(value, null, null, whenDone); - } - }); - } - - /** - * Upload this plot as a world file
- * - The mca files are each 512x512, so depending on the plot size it may also download adjacent plots
- * - Works best when (plot width + road width) % 512 == 0
- * - * @param whenDone task to run when plot is uploaded - * @see WorldUtil - */ - public void uploadWorld(RunnableVal whenDone) { - this.worldUtil.upload(this, null, null, whenDone); - } - @Override public boolean equals(Object obj) { if (this == obj) { return true; @@ -2512,128 +2070,6 @@ public class Plot { return !isMerged(); } - /** - * Remove the south road section of a plot
- * - Used when a plot is merged
- * - * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, - * otherwise writes to the queue but does not enqueue. - */ - public void removeRoadSouth(@Nullable QueueCoordinator queue) { - 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 = Location.at(this.getWorldName(), bot.getX(), 0, top.getZ()); - Location pos2 = Location.at(this.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ()); - this.regionManager.regenerateRegion(pos1, pos2, true, null); - } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove - this.getManager().removeRoadSouth(this, queue); - } - } - - /** - * Auto merge a plot in a specific direction. - * - * @param dir the direction to merge - * @param max the max number of merges to do - * @param uuid the UUID it is allowed to merge with - * @param removeRoads whether to remove roads - * @return true if a merge takes place - */ - public boolean autoMerge(Direction dir, int max, UUID uuid, boolean removeRoads) { - //Ignore merging if there is no owner for the plot - if (!this.hasOwner()) { - return false; - } - Set connected = this.getConnectedPlots(); - HashSet merged = connected.stream().map(Plot::getId).collect(Collectors.toCollection(HashSet::new)); - ArrayDeque frontier = new ArrayDeque<>(connected); - Plot current; - boolean toReturn = false; - HashSet visited = new HashSet<>(); - QueueCoordinator queue = getArea().getQueue(); - while ((current = frontier.poll()) != null && max >= 0) { - if (visited.contains(current)) { - continue; - } - visited.add(current); - Set plots; - if ((dir == Direction.ALL || dir == Direction.NORTH) && !getMerged(Direction.NORTH)) { - Plot other = current.getRelative(Direction.NORTH); - if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) - || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { - current.mergePlot(other, removeRoads, queue); - merged.add(current.getId()); - merged.add(other.getId()); - toReturn = true; - - if (removeRoads) { - ArrayList ids = new ArrayList<>(); - ids.add(current.getId()); - ids.add(other.getId()); - this.getManager().finishPlotMerge(ids, queue); - } - } - } - if (max >= 0 && (dir == Direction.ALL || dir == Direction.EAST) && !current.getMerged(Direction.EAST)) { - Plot other = current.getRelative(Direction.EAST); - if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) - || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { - current.mergePlot(other, removeRoads, queue); - merged.add(current.getId()); - merged.add(other.getId()); - toReturn = true; - - if (removeRoads) { - ArrayList ids = new ArrayList<>(); - ids.add(current.getId()); - ids.add(other.getId()); - this.getManager().finishPlotMerge(ids, queue); - } - } - } - if (max >= 0 && (dir == Direction.ALL || dir == Direction.SOUTH) && !getMerged(Direction.SOUTH)) { - Plot other = current.getRelative(Direction.SOUTH); - if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) - || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { - current.mergePlot(other, removeRoads, queue); - merged.add(current.getId()); - merged.add(other.getId()); - toReturn = true; - - if (removeRoads) { - ArrayList ids = new ArrayList<>(); - ids.add(current.getId()); - ids.add(other.getId()); - this.getManager().finishPlotMerge(ids, queue); - } - } - } - if (max >= 0 && (dir == Direction.ALL || dir == Direction.WEST) && !getMerged(Direction.WEST)) { - Plot other = current.getRelative(Direction.WEST); - if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) - || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { - current.mergePlot(other, removeRoads, queue); - merged.add(current.getId()); - merged.add(other.getId()); - toReturn = true; - - if (removeRoads) { - ArrayList ids = new ArrayList<>(); - ids.add(current.getId()); - ids.add(other.getId()); - this.getManager().finishPlotMerge(ids, queue); - } - } - } - if (queue.size() > 0) { - queue.enqueue(); - } - } - return toReturn; - } - /** * Merge the plot settings
* - Used when a plot is merged
@@ -2683,23 +2119,6 @@ public class Plot { } } - /** - * Remove the SE road (only effects terrain) - * - * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, - * otherwise writes to the queue but does not enqueue. - */ - public void removeRoadSouthEast(@Nullable QueueCoordinator queue) { - 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).withY(0); - Location pos2 = other.getBottomAbs().subtract(1, 0, 1).withY(MAX_HEIGHT); - this.regionManager.regenerateRegion(pos1, pos2, true, null); - } else if (this.area.getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove - this.area.getPlotManager().removeRoadSouthEast(this, queue); - } - } - /** * Gets the plot in a relative location
* Note: May be null if the partial plot area does not include the relative location @@ -2750,9 +2169,9 @@ public class Plot { Plot tmp; HashSet queuecache = new HashSet<>(); ArrayDeque frontier = new ArrayDeque<>(); - if (this.getMerged(Direction.NORTH)) { + if (this.isMerged(Direction.NORTH)) { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH)); - if (!tmp.getMerged(Direction.SOUTH)) { + if (!tmp.isMerged(Direction.SOUTH)) { // invalid merge if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.SOUTH, true); @@ -2765,10 +2184,10 @@ public class Plot { queuecache.add(tmp); frontier.add(tmp); } - if (this.getMerged(Direction.EAST)) { + if (this.isMerged(Direction.EAST)) { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.EAST)); assert tmp != null; - if (!tmp.getMerged(Direction.WEST)) { + if (!tmp.isMerged(Direction.WEST)) { // invalid merge if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.WEST, true); @@ -2781,10 +2200,10 @@ public class Plot { queuecache.add(tmp); frontier.add(tmp); } - if (this.getMerged(Direction.SOUTH)) { + if (this.isMerged(Direction.SOUTH)) { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.SOUTH)); assert tmp != null; - if (!tmp.getMerged(Direction.NORTH)) { + if (!tmp.isMerged(Direction.NORTH)) { // invalid merge if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.NORTH, true); @@ -2797,9 +2216,9 @@ public class Plot { queuecache.add(tmp); frontier.add(tmp); } - if (this.getMerged(Direction.WEST)) { + if (this.isMerged(Direction.WEST)) { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.WEST)); - if (!tmp.getMerged(Direction.EAST)) { + if (!tmp.isMerged(Direction.EAST)) { // invalid merge if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.EAST, true); @@ -2819,28 +2238,28 @@ public class Plot { } tmpSet.add(current); queuecache.remove(current); - if (current.getMerged(Direction.NORTH)) { + if (current.isMerged(Direction.NORTH)) { tmp = current.area.getPlotAbs(current.id.getRelative(Direction.NORTH)); if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) { queuecache.add(tmp); frontier.add(tmp); } } - if (current.getMerged(Direction.EAST)) { + if (current.isMerged(Direction.EAST)) { tmp = current.area.getPlotAbs(current.id.getRelative(Direction.EAST)); if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) { queuecache.add(tmp); frontier.add(tmp); } } - if (current.getMerged(Direction.SOUTH)) { + if (current.isMerged(Direction.SOUTH)) { tmp = current.area.getPlotAbs(current.id.getRelative(Direction.SOUTH)); if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) { queuecache.add(tmp); frontier.add(tmp); } } - if (current.getMerged(Direction.WEST)) { + if (current.isMerged(Direction.WEST)) { tmp = current.area.getPlotAbs(current.id.getRelative(Direction.WEST)); if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) { queuecache.add(tmp); @@ -2888,7 +2307,7 @@ public class Plot { boolean tmp = true; for (PlotId id : ids) { Plot plot = this.area.getPlotAbs(id); - if (plot == null || !plot.getMerged(Direction.SOUTH) || visited.contains(plot.getId())) { + if (plot == null || !plot.isMerged(Direction.SOUTH) || visited.contains(plot.getId())) { tmp = false; } } @@ -2901,7 +2320,7 @@ public class Plot { tmp = true; for (PlotId id : ids) { Plot plot = this.area.getPlotAbs(id); - if (plot == null || !plot.getMerged(Direction.WEST) || visited.contains(plot.getId())) { + if (plot == null || !plot.isMerged(Direction.WEST) || visited.contains(plot.getId())) { tmp = false; } } @@ -2914,7 +2333,7 @@ public class Plot { tmp = true; for (PlotId id : ids) { Plot plot = this.area.getPlotAbs(id); - if (plot == null || !plot.getMerged(Direction.NORTH) || visited.contains(plot.getId())) { + if (plot == null || !plot.isMerged(Direction.NORTH) || visited.contains(plot.getId())) { tmp = false; } } @@ -2927,7 +2346,7 @@ public class Plot { tmp = true; for (PlotId id : ids) { Plot plot = this.area.getPlotAbs(id); - if (plot == null || !plot.getMerged(Direction.EAST) || visited.contains(plot.getId())) { + if (plot == null || !plot.isMerged(Direction.EAST) || visited.contains(plot.getId())) { tmp = false; } } @@ -2941,7 +2360,7 @@ public class Plot { visited.addAll(Lists.newArrayList((Iterable) PlotId.PlotRangeIterator.range(bot, top))); for (int x = bot.getX(); x <= top.getX(); x++) { Plot plot = this.area.getPlotAbs(PlotId.of(x, top.getY())); - if (plot.getMerged(Direction.SOUTH)) { + if (plot.isMerged(Direction.SOUTH)) { // south wedge Location toploc = plot.getExtendedTopAbs(); Location botabs = plot.getBottomAbs(); @@ -2949,7 +2368,7 @@ public class Plot { BlockVector3 pos1 = BlockVector3.at(botabs.getX(), 0, topabs.getZ() + 1); BlockVector3 pos2 = BlockVector3.at(topabs.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); regions.add(new CuboidRegion(pos1, pos2)); - if (plot.getMerged(Direction.SOUTHEAST)) { + if (plot.isMerged(Direction.SOUTHEAST)) { pos1 = BlockVector3.at(topabs.getX() + 1, 0, topabs.getZ() + 1); pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); regions.add(new CuboidRegion(pos1, pos2)); @@ -2960,7 +2379,7 @@ public class Plot { for (int y = bot.getY(); y <= top.getY(); y++) { Plot plot = this.area.getPlotAbs(PlotId.of(top.getX(), y)); - if (plot.getMerged(Direction.EAST)) { + if (plot.isMerged(Direction.EAST)) { // east wedge Location toploc = plot.getExtendedTopAbs(); Location botabs = plot.getBottomAbs(); @@ -2968,7 +2387,7 @@ public class Plot { BlockVector3 pos1 = BlockVector3.at(topabs.getX() + 1, 0, botabs.getZ()); BlockVector3 pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, topabs.getZ()); regions.add(new CuboidRegion(pos1, pos2)); - if (plot.getMerged(Direction.SOUTHEAST)) { + if (plot.isMerged(Direction.SOUTHEAST)) { pos1 = BlockVector3.at(topabs.getX() + 1, 0, topabs.getZ() + 1); pos2 = BlockVector3.at(toploc.getX(), Plot.MAX_HEIGHT - 1, toploc.getZ()); regions.add(new CuboidRegion(pos1, pos2)); @@ -3034,40 +2453,13 @@ public class Plot { } } - /** - * Gets all the corners of the plot (supports non-rectangular shapes). - * - * @return A list of the plot corners - */ - public List getAllCorners() { - Area area = new Area(); - for (CuboidRegion region : this.getRegions()) { - Rectangle2D rect = new Rectangle2D.Double(region.getMinimumPoint().getX() - 0.6, region.getMinimumPoint().getZ() - 0.6, - region.getMaximumPoint().getX() - region.getMinimumPoint().getX() + 1.2, - region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + 1.2); - Area rectArea = new Area(rect); - area.add(rectArea); - } - List locs = new ArrayList<>(); - double[] coords = new double[6]; - for (PathIterator pi = area.getPathIterator(null); !pi.isDone(); pi.next()) { - int type = pi.currentSegment(coords); - int x = (int) MathMan.inverseRound(coords[0]); - int z = (int) MathMan.inverseRound(coords[1]); - if (type != 4) { - locs.add(Location.at(this.getWorldName(), x, 0, z)); - } - } - return locs; - } - /** * Teleport a player to a plot and send them the teleport message. * * @param player the player * @param result Called with the result of the teleportation */ - public void teleportPlayer(final PlotPlayer player, Consumer result) { + public void teleportPlayer(final PlotPlayer player, Consumer result) { teleportPlayer(player, TeleportCause.PLUGIN, result); } @@ -3078,7 +2470,7 @@ public class Plot { * @param cause the cause of the teleport * @param resultConsumer Called with the result of the teleportation */ - 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 = this.eventDispatcher.callTeleport(player, player.getLocation(), plot).getEventResult(); if (result == Result.DENY) { @@ -3142,24 +2534,6 @@ public class Plot { return false; } - /** - * Sets a component for a plot to the provided blocks
- * - E.g. floor, wall, border etc.
- * - The available components depend on the generator being used
- * - * @param component Component to set - * @param blocks Pattern to use the generation - * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, - * otherwise writes to the queue but does not enqueue. - * @return True if the component was set successfully - */ - public boolean setComponent(String component, Pattern blocks, @Nullable QueueCoordinator queue) { - PlotComponentSetEvent event = this.eventDispatcher.callComponentSet(this, component, blocks); - component = event.getComponent(); - blocks = event.getPattern(); - return this.getManager().setComponent(this.getId(), component, blocks, queue); - } - public int getDistanceFromOrigin() { Location bot = getManager().getPlotBottomLocAbs(id); Location top = getManager().getPlotTopLocAbs(id); @@ -3190,14 +2564,14 @@ public class Plot { */ public void mergePlot(Plot lesserPlot, boolean removeRoads, @Nullable QueueCoordinator queue) { Plot greaterPlot = this; - lesserPlot.removeSign(); + lesserPlot.getPlotModificationManager().removeSign(); if (lesserPlot.getId().getX() == greaterPlot.getId().getX()) { if (lesserPlot.getId().getY() > greaterPlot.getId().getY()) { Plot tmp = lesserPlot; lesserPlot = greaterPlot; greaterPlot = tmp; } - if (!lesserPlot.getMerged(Direction.SOUTH)) { + if (!lesserPlot.isMerged(Direction.SOUTH)) { lesserPlot.clearRatings(); greaterPlot.clearRatings(); lesserPlot.setMerged(Direction.SOUTH, true); @@ -3205,14 +2579,14 @@ public class Plot { lesserPlot.mergeData(greaterPlot); if (removeRoads) { //lesserPlot.removeSign(); - lesserPlot.removeRoadSouth(queue); + lesserPlot.getPlotModificationManager().removeRoadSouth(queue); Plot diagonal = greaterPlot.getRelative(Direction.EAST); - if (diagonal.getMerged(Direction.NORTHWEST)) { - lesserPlot.removeRoadSouthEast(queue); + if (diagonal.isMerged(Direction.NORTHWEST)) { + lesserPlot.plotModificationManager.removeRoadSouthEast(queue); } Plot below = greaterPlot.getRelative(Direction.WEST); - if (below.getMerged(Direction.NORTHEAST)) { - below.getRelative(Direction.NORTH).removeRoadSouthEast(queue); + if (below.isMerged(Direction.NORTHEAST)) { + below.getRelative(Direction.NORTH).plotModificationManager.removeRoadSouthEast(queue); } } } @@ -3222,7 +2596,7 @@ public class Plot { lesserPlot = greaterPlot; greaterPlot = tmp; } - if (!lesserPlot.getMerged(Direction.EAST)) { + if (!lesserPlot.isMerged(Direction.EAST)) { lesserPlot.clearRatings(); greaterPlot.clearRatings(); lesserPlot.setMerged(Direction.EAST, true); @@ -3231,234 +2605,27 @@ public class Plot { if (removeRoads) { //lesserPlot.removeSign(); Plot diagonal = greaterPlot.getRelative(Direction.SOUTH); - if (diagonal.getMerged(Direction.NORTHWEST)) { - lesserPlot.removeRoadSouthEast(queue); + if (diagonal.isMerged(Direction.NORTHWEST)) { + lesserPlot.plotModificationManager.removeRoadSouthEast(queue); } - lesserPlot.removeRoadEast(queue); + lesserPlot.plotModificationManager.removeRoadEast(queue); } Plot below = greaterPlot.getRelative(Direction.NORTH); - if (below.getMerged(Direction.SOUTHWEST)) { - below.getRelative(Direction.WEST).removeRoadSouthEast(queue); + if (below.isMerged(Direction.SOUTHWEST)) { + below.getRelative(Direction.WEST).getPlotModificationManager().removeRoadSouthEast(queue); } } } } /** - * Moves a plot physically, as well as the corresponding settings. + * Check if the plot is merged in a given direction * - * @param destination Plot moved to - * @param whenDone task when done - * @param allowSwap whether to swap plots - * @return success + * @param direction Direction + * @return {@code true} if the plot is merged in the given direction */ - public CompletableFuture move(final Plot destination, final Runnable whenDone, boolean allowSwap) { - final PlotId offset = PlotId.of(destination.getId().getX() - this.getId().getX(), destination.getId().getY() - this.getId().getY()); - Location db = destination.getBottomAbs(); - Location ob = this.getBottomAbs(); - final int offsetX = db.getX() - ob.getX(); - final int offsetZ = db.getZ() - ob.getZ(); - if (!this.hasOwner()) { - TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); - return CompletableFuture.completedFuture(false); - } - AtomicBoolean occupied = new AtomicBoolean(false); - Set plots = this.getConnectedPlots(); - for (Plot plot : plots) { - Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY()); - if (other.hasOwner()) { - if (!allowSwap) { - TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); - return CompletableFuture.completedFuture(false); - } - occupied.set(true); - } else { - plot.removeSign(); - } - } - // world border - destination.updateWorldBorder(); - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); - // move / swap data - final PlotArea originArea = getArea(); - - final Iterator plotIterator = plots.iterator(); - - CompletableFuture future = null; - if (plotIterator.hasNext()) { - while (plotIterator.hasNext()) { - final Plot plot = plotIterator.next(); - final Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY()); - final CompletableFuture swapResult = plot.swapData(other); - if (future == null) { - future = swapResult; - } else { - future = future.thenCombine(swapResult, (fn, th) -> fn); - } - } - } else { - future = CompletableFuture.completedFuture(true); - } - - return future.thenApply(result -> { - if (!result) { - return false; - } - // copy terrain - if (occupied.get()) { - new Runnable() { - @Override public void run() { - if (regions.isEmpty()) { - // Update signs - destination.setSign(); - Plot.this.setSign(); - // Run final tasks - TaskManager.runTask(whenDone); - } else { - CuboidRegion region = regions.poll(); - Location[] corners = getCorners(getWorldName(), region); - Location pos1 = corners[0]; - Location pos2 = corners[1]; - Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); - regionManager.swap(pos1, pos2, pos3, this); - } - } - }.run(); - } else { - new Runnable() { - @Override public void run() { - if (regions.isEmpty()) { - Plot plot = destination.getRelative(0, 0); - Plot originPlot = originArea.getPlotAbs(PlotId.of(plot.id.getX() - offset.getX(), plot.id.getY() - offset.getY())); - final Runnable clearDone = () -> { - QueueCoordinator queue = getArea().getQueue(); - for (final Plot current : plot.getConnectedPlots()) { - getManager().claimPlot(current, queue); - } - if (queue.size() > 0) { - queue.enqueue(); - } - plot.setSign(); - TaskManager.runTask(whenDone); - }; - if (originPlot != null) { - originPlot.clear(false, true, clearDone); - } else { - clearDone.run(); - } - return; - } - final Runnable task = this; - CuboidRegion region = regions.poll(); - Location[] corners = getCorners(getWorldName(), region); - final Location pos1 = corners[0]; - final Location pos2 = corners[1]; - Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); - regionManager.copyRegion(pos1, pos2, newPos, task); - } - }.run(); - } - return true; - }); - } - - /** - * Copy a plot to a location, both physically and the settings - * - * @param destination destination plot - * @param whenDone task to run when copy is complete - * @return success or not - */ - public boolean copy(final Plot destination, final Runnable whenDone) { - PlotId offset = PlotId.of(destination.getId().getX() - this.getId().getX(), destination.getId().getY() - this.getId().getY()); - Location db = destination.getBottomAbs(); - Location ob = this.getBottomAbs(); - final int offsetX = db.getX() - ob.getX(); - final int offsetZ = db.getZ() - ob.getZ(); - if (!this.hasOwner()) { - TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); - return false; - } - Set plots = this.getConnectedPlots(); - for (Plot plot : plots) { - Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY()); - if (other.hasOwner()) { - TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); - return false; - } - } - // world border - destination.updateWorldBorder(); - // copy data - for (Plot plot : plots) { - Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY()); - other.create(plot.getOwner(), false); - if (!plot.getFlagContainer().getFlagMap().isEmpty()) { - final Collection> existingFlags = other.getFlags(); - other.getFlagContainer().clearLocal(); - other.getFlagContainer().addAll(plot.getFlagContainer().getFlagMap().values()); - // Update the database - for (final PlotFlag flag : existingFlags) { - final PlotFlag newFlag = other.getFlagContainer().queryLocal(flag.getClass()); - if (other.getFlagContainer().queryLocal(flag.getClass()) == null) { - DBFunc.removeFlag(other, flag); - } else { - DBFunc.setFlag(other, newFlag); - } - } - } - if (plot.isMerged()) { - other.setMerged(plot.getMerged()); - } - if (plot.members != null && !plot.members.isEmpty()) { - other.members = plot.members; - for (UUID member : plot.members) { - DBFunc.setMember(other, member); - } - } - if (plot.trusted != null && !plot.trusted.isEmpty()) { - other.trusted = plot.trusted; - for (UUID trusted : plot.trusted) { - DBFunc.setTrusted(other, trusted); - } - } - if (plot.denied != null && !plot.denied.isEmpty()) { - other.denied = plot.denied; - for (UUID denied : plot.denied) { - DBFunc.setDenied(other, denied); - } - } - } - // copy terrain - final ArrayDeque regions = new ArrayDeque<>(this.getRegions()); - Runnable run = new Runnable() { - @Override public void run() { - if (regions.isEmpty()) { - QueueCoordinator queue = getArea().getQueue(); - for (Plot current : getConnectedPlots()) { - destination.getManager().claimPlot(current, queue); - } - if (queue.size() > 0) { - queue.enqueue(); - } - destination.setSign(); - TaskManager.runTask(whenDone); - return; - } - CuboidRegion region = regions.poll(); - Location[] corners = getCorners(getWorldName(), region); - Location pos1 = corners[0]; - Location pos2 = corners[1]; - Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); - regionManager.copyRegion(pos1, pos2, newPos, this); - } - }; - run.run(); - return true; - } - - public boolean getMerged(Direction direction) { - return getMerged(direction.getIndex()); + public boolean isMerged(@Nonnull final Direction direction) { + return isMerged(direction.getIndex()); } /** @@ -3470,7 +2637,7 @@ public class Plot { * @param the flag value type * @return The flag value */ - public T getFlag(final Class> flagClass) { + @Nonnull public T getFlag(@Nonnull final Class> flagClass) { return this.flagContainer.getFlag(flagClass).getValue(); } @@ -3484,7 +2651,7 @@ public class Plot { * @param the flag's value type * @return The flag value */ - public > T getFlag(final V flag) { + @Nonnull public > T getFlag(@Nonnull final V flag) { final Class flagClass = flag.getClass(); final PlotFlag flagInstance = this.flagContainer.getFlagErased(flagClass); return FlagContainer.castUnsafe(flagInstance).getValue(); @@ -3495,7 +2662,7 @@ public class Plot { int num = this.getConnectedPlots().size(); String alias = !this.getAlias().isEmpty() ? this.getAlias() : TranslatableCaption.of("info.none").getComponent(player); Location bot = this.getCorners()[0]; - PlotSquared.platform().getWorldUtil().getBiome(this.getWorldName(), bot.getX(), bot.getZ(), biome -> { + PlotSquared.platform().getWorldUtil().getBiome(Objects.requireNonNull(this.getWorldName()), bot.getX(), bot.getZ(), biome -> { String trusted = PlayerManager.getPlayerList(this.getTrusted()); String members = PlayerManager.getPlayerList(this.getMembers()); String denied = PlayerManager.getPlayerList(this.getDenied()); @@ -3667,4 +2834,13 @@ public class Plot { return this.plotCommentContainer; } + /** + * Get the plot modification manager + * + * @return Plot modification manager + */ + @Nonnull public PlotModificationManager getPlotModificationManager() { + return this.plotModificationManager; + } + } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index 38c452a90..36a0fe4d5 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -964,7 +964,7 @@ public abstract class PlotArea { members.addAll(plot.getMembers()); denied.addAll(plot.getDenied()); if (removeRoads) { - plot.removeSign(); + plot.getPlotModificationManager().removeSign(); } } } @@ -985,19 +985,19 @@ public abstract class PlotArea { Plot plot2; if (lx) { if (ly) { - if (!plot.getMerged(Direction.EAST) || !plot.getMerged(Direction.SOUTH)) { + if (!plot.isMerged(Direction.EAST) || !plot.isMerged(Direction.SOUTH)) { if (removeRoads) { - plot.removeRoadSouthEast(queue); + plot.getPlotModificationManager().removeRoadSouthEast(queue); } } } - if (!plot.getMerged(Direction.EAST)) { + if (!plot.isMerged(Direction.EAST)) { plot2 = plot.getRelative(1, 0); plot.mergePlot(plot2, removeRoads, queue); } } if (ly) { - if (!plot.getMerged(Direction.SOUTH)) { + if (!plot.isMerged(Direction.SOUTH)) { plot2 = plot.getRelative(0, 1); plot.mergePlot(plot2, removeRoads, queue); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java new file mode 100644 index 000000000..be26600fb --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotModificationManager.java @@ -0,0 +1,819 @@ +package com.plotsquared.core.plot; + +import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.ConfigurationUtil; +import com.plotsquared.core.configuration.caption.Caption; +import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.database.DBFunc; +import com.plotsquared.core.events.PlotComponentSetEvent; +import com.plotsquared.core.events.PlotMergeEvent; +import com.plotsquared.core.events.PlotUnlinkEvent; +import com.plotsquared.core.events.Result; +import com.plotsquared.core.generator.SquarePlotWorld; +import com.plotsquared.core.location.Direction; +import com.plotsquared.core.location.Location; +import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.flag.PlotFlag; +import com.plotsquared.core.queue.QueueCoordinator; +import com.plotsquared.core.util.PlayerManager; +import com.plotsquared.core.util.task.TaskManager; +import com.plotsquared.core.util.task.TaskTime; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BlockTypes; +import net.kyori.adventure.text.minimessage.Template; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +import static com.plotsquared.core.plot.Plot.MAX_HEIGHT; + +/** + * Manager that handles {@link Plot} modifications + */ +public final class PlotModificationManager { + + private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotModificationManager.class.getSimpleName()); + + private final Plot plot; + + PlotModificationManager(@Nonnull final Plot plot) { + this.plot = plot; + } + + + /** + * Copy a plot to a location, both physically and the settings + * + * @param destination destination plot + * @return Future that completes with {@code true} if the copy was successful, else {@code false} + */ + public CompletableFuture copy(@Nonnull final Plot destination) { + final CompletableFuture future = new CompletableFuture<>(); + final PlotId offset = PlotId.of(destination.getId().getX() - this.plot.getId().getX(), destination.getId().getY() - this.plot.getId().getY()); + final Location db = destination.getBottomAbs(); + final Location ob = this.plot.getBottomAbs(); + final int offsetX = db.getX() - ob.getX(); + final int offsetZ = db.getZ() - ob.getZ(); + if (!this.plot.hasOwner()) { + TaskManager.runTaskLater(() -> future.complete(false), TaskTime.ticks(1L)); + return future; + } + final Set plots = this.plot.getConnectedPlots(); + for (final Plot plot : plots) { + final Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY()); + if (other.hasOwner()) { + TaskManager.runTaskLater(() -> future.complete(false), TaskTime.ticks(1L)); + return future; + } + } + // world border + destination.updateWorldBorder(); + // copy data + for (final Plot plot : plots) { + final Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY()); + other.getPlotModificationManager().create(plot.getOwner(), false); + if (!plot.getFlagContainer().getFlagMap().isEmpty()) { + final Collection> existingFlags = other.getFlags(); + other.getFlagContainer().clearLocal(); + other.getFlagContainer().addAll(plot.getFlagContainer().getFlagMap().values()); + // Update the database + for (final PlotFlag flag : existingFlags) { + final PlotFlag newFlag = other.getFlagContainer().queryLocal(flag.getClass()); + if (other.getFlagContainer().queryLocal(flag.getClass()) == null) { + DBFunc.removeFlag(other, flag); + } else { + DBFunc.setFlag(other, newFlag); + } + } + } + if (plot.isMerged()) { + other.setMerged(plot.getMerged()); + } + if (plot.members != null && !plot.members.isEmpty()) { + other.members = plot.members; + for (UUID member : plot.members) { + DBFunc.setMember(other, member); + } + } + if (plot.trusted != null && !plot.trusted.isEmpty()) { + other.trusted = plot.trusted; + for (UUID trusted : plot.trusted) { + DBFunc.setTrusted(other, trusted); + } + } + if (plot.denied != null && !plot.denied.isEmpty()) { + other.denied = plot.denied; + for (UUID denied : plot.denied) { + DBFunc.setDenied(other, denied); + } + } + } + // copy terrain + final ArrayDeque regions = new ArrayDeque<>(this.plot.getRegions()); + final Runnable run = new Runnable() { + @Override public void run() { + if (regions.isEmpty()) { + final QueueCoordinator queue = plot.getArea().getQueue(); + for (final Plot current : plot.getConnectedPlots()) { + destination.getManager().claimPlot(current, queue); + } + if (queue.size() > 0) { + queue.enqueue(); + } + destination.getPlotModificationManager().setSign(); + future.complete(true); + return; + } + CuboidRegion region = regions.poll(); + Location[] corners = plot.getCorners(plot.getWorldName(), region); + Location pos1 = corners[0]; + Location pos2 = corners[1]; + Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); + PlotSquared.platform().getRegionManager().copyRegion(pos1, pos2, newPos, this); + } + }; + run.run(); + return future; + } + + /** + * Clear the plot + * + * @param whenDone A runnable to execute when clearing finishes, or null + * @see #clear(boolean, boolean, Runnable) + * @see #deletePlot(Runnable) to clear and delete a plot + */ + public void clear(@Nullable final Runnable whenDone) { + this.clear(false, false, whenDone); + } + + /** + * Clear the plot + * + * @param checkRunning Whether or not already executing tasks should be checked + * @param isDelete Whether or not the plot is being deleted + * @param whenDone A runnable to execute when clearing finishes, or null + * @see #deletePlot(Runnable) to clear and delete a plot + */ + public boolean clear(final boolean checkRunning, final boolean isDelete, @Nullable final Runnable whenDone) { + if (checkRunning && this.plot.getRunning() != 0) { + return false; + } + final Set regions = this.plot.getRegions(); + final Set plots = this.plot.getConnectedPlots(); + final ArrayDeque queue = new ArrayDeque<>(plots); + if (isDelete) { + this.removeSign(); + } + PlotUnlinkEvent event = PlotSquared.get().getEventDispatcher() + .callUnlink(this.plot.getArea(), this.plot, true, !isDelete, isDelete ? PlotUnlinkEvent.REASON.DELETE : PlotUnlinkEvent.REASON.CLEAR); + if (event.getEventResult() != Result.DENY) { + this.unlinkPlot(event.isCreateRoad(), event.isCreateSign()); + } + final PlotManager manager = this.plot.getArea().getPlotManager(); + Runnable run = new Runnable() { + @Override public void run() { + if (queue.isEmpty()) { + Runnable run = () -> { + for (CuboidRegion region : regions) { + Location[] corners = plot.getCorners(plot.getWorldName(), region); + PlotSquared.platform().getRegionManager().clearAllEntities(corners[0], corners[1]); + } + TaskManager.runTask(whenDone); + }; + QueueCoordinator queue = plot.getArea().getQueue(); + for (Plot current : plots) { + if (isDelete || !current.hasOwner()) { + manager.unClaimPlot(current, null, queue); + } else { + manager.claimPlot(current, queue); + } + } + if (queue.size() > 0) { + queue.enqueue(); + } + TaskManager.runTask(run); + return; + } + Plot current = queue.poll(); + if (plot.getArea().getTerrain() != PlotAreaTerrainType.NONE) { + try { + PlotSquared.platform().getRegionManager().regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false, this); + } catch (UnsupportedOperationException exception) { + exception.printStackTrace(); + return; + } + return; + } + manager.clearPlot(current, this, null); + } + }; + run.run(); + return true; + } + + /** + * Sets the biome for a plot asynchronously. + * + * @param biome The biome e.g. "forest" + * @param whenDone The task to run when finished, or null + */ + public void setBiome(@Nullable final BiomeType biome, @Nonnull final Runnable whenDone) { + final ArrayDeque regions = new ArrayDeque<>(this.plot.getRegions()); + final int extendBiome; + if (this.plot.getArea() instanceof SquarePlotWorld) { + extendBiome = (((SquarePlotWorld) this.plot.getArea()).ROAD_WIDTH > 0) ? 1 : 0; + } else { + extendBiome = 0; + } + Runnable run = new Runnable() { + @Override public void run() { + if (regions.isEmpty()) { + TaskManager.runTask(whenDone); + return; + } + CuboidRegion region = regions.poll(); + PlotSquared.platform().getRegionManager().setBiome(region, extendBiome, biome, plot.getWorldName(), this); + } + }; + run.run(); + } + + /** + * Unlink the plot and all connected plots. + * + * @param createRoad whether to recreate road + * @param createSign whether to recreate signs + * @return success/!cancelled + */ + public boolean unlinkPlot(final boolean createRoad, final boolean createSign) { + if (!this.plot.isMerged()) { + return false; + } + final Set plots = this.plot.getConnectedPlots(); + ArrayList ids = new ArrayList<>(plots.size()); + for (Plot current : plots) { + current.setHome(null); + ids.add(current.getId()); + } + this.plot.clearRatings(); + QueueCoordinator queue = null; + if (createSign) { + this.removeSign(); + queue = this.plot.getArea().getQueue(); + } + PlotManager manager = this.plot.getArea().getPlotManager(); + if (createRoad) { + manager.startPlotUnlink(ids, queue); + } + if (this.plot.getArea().getTerrain() != PlotAreaTerrainType.ALL && createRoad) { + for (Plot current : plots) { + if (current.isMerged(Direction.EAST)) { + manager.createRoadEast(current, queue); + if (current.isMerged(Direction.SOUTH)) { + manager.createRoadSouth(current, queue); + if (current.isMerged(Direction.SOUTHEAST)) { + manager.createRoadSouthEast(current, queue); + } + } + } + if (current.isMerged(Direction.SOUTH)) { + manager.createRoadSouth(current, queue); + } + } + } + for (Plot current : plots) { + boolean[] merged = new boolean[] {false, false, false, false}; + current.setMerged(merged); + } + if (createSign) { + queue.setCompleteTask(() -> TaskManager.runTaskAsync(() -> { + for (Plot current : plots) { + current.getPlotModificationManager().setSign(PlayerManager.getName(current.getOwnerAbs())); + } + })); + } + if (createRoad) { + manager.finishPlotUnlink(ids, queue); + } + return true; + } + + /** + * Sets the sign for a plot to a specific name + * + * @param name name + */ + public void setSign(@Nonnull final String name) { + if (!this.plot.isLoaded()) { + return; + } + PlotManager manager = this.plot.getArea().getPlotManager(); + if (this.plot.getArea().allowSigns()) { + Location location = manager.getSignLoc(this.plot); + String id = this.plot.getId().toString(); + Caption[] lines = + new Caption[] {TranslatableCaption.of("signs.owner_sign_line_1"), + TranslatableCaption.of("signs.owner_sign_line_2"), + TranslatableCaption.of("signs.owner_sign_line_3"), + TranslatableCaption.of("signs.owner_sign_line_4")}; + PlotSquared.platform().getWorldUtil().setSign(location, lines, Template.of("id", id), Template.of("owner", name)); + } + } + + /** + * Resend all chunks inside the plot to nearby players
+ * This should not need to be called + */ + public void refreshChunks() { + final HashSet chunks = new HashSet<>(); + for (final CuboidRegion region : this.plot.getRegions()) { + for (int x = region.getMinimumPoint().getX() >> 4; x <= region.getMaximumPoint().getX() >> 4; x++) { + for (int z = region.getMinimumPoint().getZ() >> 4; z <= region.getMaximumPoint().getZ() >> 4; z++) { + if (chunks.add(BlockVector2.at(x, z))) { + PlotSquared.platform().getWorldUtil().refreshChunk(x, z, this.plot.getWorldName()); + } + } + } + } + } + + /** + * Remove the plot sign if it is set. + */ + public void removeSign() { + PlotManager manager = this.plot.getArea().getPlotManager(); + if (!this.plot.getArea().allowSigns()) { + return; + } + Location location = manager.getSignLoc(this.plot); + QueueCoordinator queue = PlotSquared.platform().getGlobalBlockQueue() + .getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(this.plot.getWorldName())); + queue.setBlock(location.getX(), location.getY(), location.getZ(), BlockTypes.AIR.getDefaultState()); + queue.enqueue(); + } + + /** + * Sets the plot sign if plot signs are enabled. + */ + public void setSign() { + if (!this.plot.hasOwner()) { + this.setSign("unknown"); + return; + } + PlotSquared.get().getImpromptuUUIDPipeline().getSingle(this.plot.getOwnerAbs(), (username, sign) -> this.setSign(username)); + } + + /** + * Register a plot and create it in the database
+ * - The plot will not be created if the owner is null
+ * - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot + * creation. + * + * @return true if plot was created successfully + */ + public boolean create() { + return this.create(this.plot.getOwnerAbs(), true); + } + + /** + * Register a plot and create it in the database
+ * - The plot will not be created if the owner is null
+ * - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot + * creation. + * + * @param uuid the uuid of the plot owner + * @param notify notify + * @return {@code true} if plot was created successfully, else {@code false} + */ + public boolean create(@Nonnull final UUID uuid, final boolean notify) { + this.plot.setOwnerAbs(uuid); + Plot existing = this.plot.getArea().getOwnedPlotAbs(this.plot.getId()); + if (existing != null) { + throw new IllegalStateException("Plot already exists!"); + } + if (notify) { + Integer meta = (Integer) this.plot.getArea().getMeta("worldBorder"); + if (meta != null) { + this.plot.updateWorldBorder(); + } + } + Plot.connected_cache = null; + Plot.regions_cache = null; + this.plot.getTrusted().clear(); + this.plot.getMembers().clear(); + this.plot.getDenied().clear(); + this.plot.settings = new PlotSettings(); + if (this.plot.getArea().addPlot(this.plot)) { + DBFunc.createPlotAndSettings(this.plot, () -> { + PlotArea plotworld = plot.getArea(); + if (notify && plotworld.isAutoMerge()) { + final PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); + + PlotMergeEvent + event = PlotSquared.get().getEventDispatcher().callMerge(this.plot, Direction.ALL, Integer.MAX_VALUE, player); + + if (event.getEventResult() == Result.DENY) { + if (player != null) { + player.sendMessage(TranslatableCaption.of("events.event_denied"), + Template.of("value", "Auto merge on claim")); + } + return; + } + plot.getPlotModificationManager().autoMerge(event.getDir(), event.getMax(), uuid, true); + } + }); + return true; + } + logger.info("Failed to add plot {} to plot area {}", this.plot.getId().toCommaSeparatedString(), this.plot.getArea().toString()); + return false; + } + + /** + * Remove the south road section of a plot
+ * - Used when a plot is merged
+ * + * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, + * otherwise writes to the queue but does not enqueue. + */ + public void removeRoadSouth(@Nullable final QueueCoordinator queue) { + if (this.plot.getArea().getType() != PlotAreaType.NORMAL && this.plot.getArea().getTerrain() == PlotAreaTerrainType.ROAD) { + Plot other = this.plot.getRelative(Direction.SOUTH); + Location bot = other.getBottomAbs(); + Location top = this.plot.getTopAbs(); + Location pos1 = Location.at(this.plot.getWorldName(), bot.getX(), 0, top.getZ()); + Location pos2 = Location.at(this.plot.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ()); + PlotSquared.platform().getRegionManager().regenerateRegion(pos1, pos2, true, null); + } else if (this.plot.getArea().getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove + this.plot.getManager().removeRoadSouth(this.plot, queue); + } + } + + /** + * Auto merge a plot in a specific direction. + * + * @param dir the direction to merge + * @param max the max number of merges to do + * @param uuid the UUID it is allowed to merge with + * @param removeRoads whether to remove roads + * @return {@code true} if a merge takes place, else {@code false} + */ + public boolean autoMerge(@Nonnull final Direction dir, int max, @Nonnull final UUID uuid, final boolean removeRoads) { + //Ignore merging if there is no owner for the plot + if (!this.plot.hasOwner()) { + return false; + } + Set connected = this.plot.getConnectedPlots(); + HashSet merged = connected.stream().map(Plot::getId).collect(Collectors.toCollection(HashSet::new)); + ArrayDeque frontier = new ArrayDeque<>(connected); + Plot current; + boolean toReturn = false; + HashSet visited = new HashSet<>(); + QueueCoordinator queue = this.plot.getArea().getQueue(); + while ((current = frontier.poll()) != null && max >= 0) { + if (visited.contains(current)) { + continue; + } + visited.add(current); + Set plots; + if ((dir == Direction.ALL || dir == Direction.NORTH) && !this.plot.isMerged(Direction.NORTH)) { + Plot other = current.getRelative(Direction.NORTH); + if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) + || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { + current.mergePlot(other, removeRoads, queue); + merged.add(current.getId()); + merged.add(other.getId()); + toReturn = true; + + if (removeRoads) { + ArrayList ids = new ArrayList<>(); + ids.add(current.getId()); + ids.add(other.getId()); + this.plot.getManager().finishPlotMerge(ids, queue); + } + } + } + if (max >= 0 && (dir == Direction.ALL || dir == Direction.EAST) && !current.isMerged(Direction.EAST)) { + Plot other = current.getRelative(Direction.EAST); + if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) + || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { + current.mergePlot(other, removeRoads, queue); + merged.add(current.getId()); + merged.add(other.getId()); + toReturn = true; + + if (removeRoads) { + ArrayList ids = new ArrayList<>(); + ids.add(current.getId()); + ids.add(other.getId()); + this.plot.getManager().finishPlotMerge(ids, queue); + } + } + } + if (max >= 0 && (dir == Direction.ALL || dir == Direction.SOUTH) && !this.plot.isMerged(Direction.SOUTH)) { + Plot other = current.getRelative(Direction.SOUTH); + if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) + || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { + current.mergePlot(other, removeRoads, queue); + merged.add(current.getId()); + merged.add(other.getId()); + toReturn = true; + + if (removeRoads) { + ArrayList ids = new ArrayList<>(); + ids.add(current.getId()); + ids.add(other.getId()); + this.plot.getManager().finishPlotMerge(ids, queue); + } + } + } + if (max >= 0 && (dir == Direction.ALL || dir == Direction.WEST) && !this.plot.isMerged(Direction.WEST)) { + Plot other = current.getRelative(Direction.WEST); + if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) + || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { + current.mergePlot(other, removeRoads, queue); + merged.add(current.getId()); + merged.add(other.getId()); + toReturn = true; + + if (removeRoads) { + ArrayList ids = new ArrayList<>(); + ids.add(current.getId()); + ids.add(other.getId()); + this.plot.getManager().finishPlotMerge(ids, queue); + } + } + } + if (queue.size() > 0) { + queue.enqueue(); + } + } + return toReturn; + } + + /** + * Moves a plot physically, as well as the corresponding settings. + * + * @param destination Plot moved to + * @param whenDone task when done + * @param allowSwap whether to swap plots + * @return {@code true} if the move was successful, else {@code false} + */ + @Nonnull public CompletableFuture move(@Nonnull final Plot destination, + @Nonnull final Runnable whenDone, + final boolean allowSwap) { + final PlotId offset = PlotId.of(destination.getId().getX() - this.plot.getId().getX(), destination.getId().getY() - this.plot.getId().getY()); + Location db = destination.getBottomAbs(); + Location ob = this.plot.getBottomAbs(); + final int offsetX = db.getX() - ob.getX(); + final int offsetZ = db.getZ() - ob.getZ(); + if (!this.plot.hasOwner()) { + TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); + return CompletableFuture.completedFuture(false); + } + AtomicBoolean occupied = new AtomicBoolean(false); + Set plots = this.plot.getConnectedPlots(); + for (Plot plot : plots) { + Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY()); + if (other.hasOwner()) { + if (!allowSwap) { + TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L)); + return CompletableFuture.completedFuture(false); + } + occupied.set(true); + } else { + plot.getPlotModificationManager().removeSign(); + } + } + // world border + destination.updateWorldBorder(); + final ArrayDeque regions = new ArrayDeque<>(this.plot.getRegions()); + // move / swap data + final PlotArea originArea = this.plot.getArea(); + + final Iterator plotIterator = plots.iterator(); + + CompletableFuture future = null; + if (plotIterator.hasNext()) { + while (plotIterator.hasNext()) { + final Plot plot = plotIterator.next(); + final Plot other = plot.getRelative(destination.getArea(), offset.getX(), offset.getY()); + final CompletableFuture swapResult = plot.swapData(other); + if (future == null) { + future = swapResult; + } else { + future = future.thenCombine(swapResult, (fn, th) -> fn); + } + } + } else { + future = CompletableFuture.completedFuture(true); + } + + return future.thenApply(result -> { + if (!result) { + return false; + } + // copy terrain + if (occupied.get()) { + new Runnable() { + @Override public void run() { + if (regions.isEmpty()) { + // Update signs + destination.getPlotModificationManager().setSign(); + setSign(); + // Run final tasks + TaskManager.runTask(whenDone); + } else { + CuboidRegion region = regions.poll(); + Location[] corners = plot.getCorners(plot.getWorldName(), region); + Location pos1 = corners[0]; + Location pos2 = corners[1]; + Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); + PlotSquared.platform().getRegionManager().swap(pos1, pos2, pos3, this); + } + } + }.run(); + } else { + new Runnable() { + @Override public void run() { + if (regions.isEmpty()) { + Plot plot = destination.getRelative(0, 0); + Plot originPlot = originArea.getPlotAbs(PlotId.of(plot.getId().getX() - offset.getX(), plot.getId().getY() - offset.getY())); + final Runnable clearDone = () -> { + QueueCoordinator queue = PlotModificationManager.this.plot.getArea().getQueue(); + for (final Plot current : plot.getConnectedPlots()) { + PlotModificationManager.this.plot.getManager().claimPlot(current, queue); + } + if (queue.size() > 0) { + queue.enqueue(); + } + plot.getPlotModificationManager().setSign(); + TaskManager.runTask(whenDone); + }; + if (originPlot != null) { + originPlot.getPlotModificationManager().clear(false, true, clearDone); + } else { + clearDone.run(); + } + return; + } + final Runnable task = this; + CuboidRegion region = regions.poll(); + Location[] corners = PlotModificationManager.this.plot.getCorners(PlotModificationManager.this.plot.getWorldName(), region); + final Location pos1 = corners[0]; + final Location pos2 = corners[1]; + Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName()); + PlotSquared.platform().getRegionManager().copyRegion(pos1, pos2, newPos, task); + } + }.run(); + } + return true; + }); + } + + /** + * Unlink a plot and remove the roads + * + * @return true if plot was linked + * @see #unlinkPlot(boolean, boolean) + */ + public boolean unlink() { + return this.unlinkPlot(true, true); + } + + /** + * Swap the plot contents and settings with another location
+ * - The destination must correspond to a valid plot of equal dimensions + * + * @param destination The other plot to swap with + * @param whenDone A task to run when finished, or null + * @return Future that completes with {@code true} if the swap was successful, else {@code false} + */ + @Nonnull public CompletableFuture swap(@Nonnull final Plot destination, @Nonnull final Runnable whenDone) { + return this.move(destination, whenDone, true); + } + + /** + * Moves the plot to an empty location
+ * - The location must be empty + * + * @param destination Where to move the plot + * @param whenDone A task to run when done, or null + * @return Future that completes with {@code true} if the move was successful, else {@code false} + */ + @Nonnull public CompletableFuture move(@Nonnull final Plot destination, @Nonnull final Runnable whenDone) { + return this.move(destination, whenDone, false); + } + + /** + * Sets a component for a plot to the provided blocks
+ * - E.g. floor, wall, border etc.
+ * - The available components depend on the generator being used
+ * + * @param component Component to set + * @param blocks Pattern to use the generation + * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, + * otherwise writes to the queue but does not enqueue. + * @return {@code true} if the component was set successfully, else {@code false} + */ + public boolean setComponent(@Nonnull final String component, @Nonnull final Pattern blocks, @Nullable final QueueCoordinator queue) { + final PlotComponentSetEvent event = PlotSquared.get().getEventDispatcher().callComponentSet(this.plot, component, blocks); + return this.plot.getManager().setComponent(this.plot.getId(), event.getComponent(), event.getPattern(), queue); + } + + /** + * Delete a plot (use null for the runnable if you don't need to be notified on completion) + * + * @see PlotSquared#removePlot(Plot, boolean) + * @see PlotModificationManager#clear(boolean, boolean, Runnable) to simply clear a plot + * + * @param whenDone task to run when plot has been deleted. Nullable + * + * @return {@code true} if the deletion was successful, {@code false} if not + */ + public boolean deletePlot(final Runnable whenDone) { + if (!this.plot.hasOwner()) { + return false; + } + final Set plots = this.plot.getConnectedPlots(); + this.clear(false, true, () -> { + for (Plot current : plots) { + current.unclaim(); + } + TaskManager.runTask(whenDone); + }); + return true; + } + + /** + * Sets components such as border, wall, floor. + * (components are generator specific) + * + * @param component component to set + * @param blocks string of block(s) to set component to + * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, + * otherwise writes to the queue but does not enqueue. + * + * @return {@code true} if the update was successful, {@code false} if not + */ + @Deprecated public boolean setComponent(String component, String blocks, QueueCoordinator queue) { + final BlockBucket parsed = ConfigurationUtil.BLOCK_BUCKET.parseString(blocks); + if (parsed != null && parsed.isEmpty()) { + return false; + } + return this.setComponent(component, parsed.toPattern(), queue); + } + + /** + * Remove the east road section of a plot
+ * - Used when a plot is merged
+ * + * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, + * otherwise writes to the queue but does not enqueue. + */ + public void removeRoadEast(@Nullable QueueCoordinator queue) { + if (this.plot.getArea().getType() != PlotAreaType.NORMAL && this.plot.getArea().getTerrain() == PlotAreaTerrainType.ROAD) { + Plot other = this.plot.getRelative(Direction.EAST); + Location bot = other.getBottomAbs(); + Location top = this.plot.getTopAbs(); + Location pos1 = Location.at(this.plot.getWorldName(), top.getX(), 0, bot.getZ()); + Location pos2 = Location.at(this.plot.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ()); + PlotSquared.platform().getRegionManager().regenerateRegion(pos1, pos2, true, null); + } else if (this.plot.getArea().getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove + this.plot.getArea().getPlotManager().removeRoadEast(this.plot, queue); + } + } + + /** + * Remove the SE road (only effects terrain) + * + * @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues, + * otherwise writes to the queue but does not enqueue. + */ + public void removeRoadSouthEast(@Nullable QueueCoordinator queue) { + if (this.plot.getArea().getType() != PlotAreaType.NORMAL && this.plot.getArea().getTerrain() == PlotAreaTerrainType.ROAD) { + Plot other = this.plot.getRelative(1, 1); + Location pos1 = this.plot.getTopAbs().add(1, 0, 1).withY(0); + Location pos2 = other.getBottomAbs().subtract(1, 0, 1).withY(MAX_HEIGHT); + PlotSquared.platform().getRegionManager().regenerateRegion(pos1, pos2, true, null); + } else if (this.plot.getArea().getTerrain() != PlotAreaTerrainType.ALL) { // no road generated => no road to remove + this.plot.getArea().getPlotManager().removeRoadSouthEast(this.plot, queue); + } + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java index cf2b862f7..65e9c876c 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java @@ -399,10 +399,6 @@ public class ExpireManager { } } - public void storeAccountAge(UUID uuid, long time) { - this.account_age_cache.put(uuid, time); - } - public HashSet getPendingExpired() { return plotsToDelete == null ? new HashSet<>() : plotsToDelete; } @@ -413,7 +409,7 @@ public class ExpireManager { .callUnlink(plot.getArea(), plot, true, false, PlotUnlinkEvent.REASON.EXPIRE_DELETE); if (event.getEventResult() != Result.DENY) { - plot.unlinkPlot(event.isCreateRoad(), event.isCreateSign()); + plot.getPlotModificationManager().unlinkPlot(event.isCreateRoad(), event.isCreateSign()); } } for (UUID helper : plot.getTrusted()) { @@ -430,7 +426,7 @@ public class ExpireManager { Templates.of("plot", plot.toString())); } } - plot.deletePlot(whenDone); + plot.getPlotModificationManager().deletePlot(whenDone); } public long getAge(UUID uuid) { diff --git a/Core/src/main/java/com/plotsquared/core/util/task/AutoClaimFinishTask.java b/Core/src/main/java/com/plotsquared/core/util/task/AutoClaimFinishTask.java index 4080912e7..7dac88333 100644 --- a/Core/src/main/java/com/plotsquared/core/util/task/AutoClaimFinishTask.java +++ b/Core/src/main/java/com/plotsquared/core/util/task/AutoClaimFinishTask.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.util.task; -import com.plotsquared.core.command.Auto; import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.events.PlotMergeEvent; @@ -73,7 +72,7 @@ public final class AutoClaimFinishTask implements Callable { player.sendMessage(TranslatableCaption.of("events.event_denied"), Templates.of("value", "Auto Merge")); } else { - plot.autoMerge(event.getDir(), event.getMax(), player.getUUID(), true); + plot.getPlotModificationManager().autoMerge(event.getDir(), event.getMax(), player.getUUID(), true); } } return true;