From 2802939112a960a14214d284b20bf419483037e9 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 11 Jun 2022 14:25:49 +0100 Subject: [PATCH] Add an on-complete task to PlotArea#mergePlots --- .../com/plotsquared/core/plot/PlotArea.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 a45451aeb..b51cb1c55 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -65,7 +65,6 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; -import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import org.apache.logging.log4j.LogManager; @@ -965,7 +964,31 @@ public abstract class PlotArea { return this.plots.remove(id) != null; } + /** + * Merge a list of plots together. This is non-blocking for the world-changes that will be made. To run a tasks when the + * world changes are complete, use {@link PlotArea#mergePlots(List, boolean, Runnable)}; + * + * @param plotIds List of plot IDs to merge + * @param removeRoads If the roads between plots should be removed + * @return if merges were completed successfully. + */ public boolean mergePlots(final @NonNull List plotIds, final boolean removeRoads) { + return mergePlots(plotIds, removeRoads, null); + } + + /** + * Merge a list of plots together. This is non-blocking for the world-changes that will be made. + * + * @param plotIds List of plot IDs to merge + * @param removeRoads If the roads between plots should be removed + * @param whenDone Task to run when any merge world changes are complete. Also runs if no changes were made. Does not + * run if there was an error or if too few plots IDs were supplied. + * @return if merges were completed successfully. + * @since TODO + */ + public boolean mergePlots( + final @NonNull List plotIds, final boolean removeRoads, final @Nullable Runnable whenDone + ) { if (plotIds.size() < 2) { return false; } @@ -1028,6 +1051,9 @@ public abstract class PlotArea { } } manager.finishPlotMerge(plotIds, queue); + if (whenDone != null) { + queue.setCompleteTask(whenDone); + } queue.enqueue(); return true; }