Add an on-complete task to PlotArea#mergePlots

This commit is contained in:
dordsor21 2022-06-11 14:25:49 +01:00
parent bf646be482
commit 2802939112
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -65,7 +65,6 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes; 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.MiniMessage;
import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.minimessage.Template;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -965,7 +964,31 @@ public abstract class PlotArea {
return this.plots.remove(id) != null; 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<PlotId> plotIds, final boolean removeRoads) { public boolean mergePlots(final @NonNull List<PlotId> 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<PlotId> plotIds, final boolean removeRoads, final @Nullable Runnable whenDone
) {
if (plotIds.size() < 2) { if (plotIds.size() < 2) {
return false; return false;
} }
@ -1028,6 +1051,9 @@ public abstract class PlotArea {
} }
} }
manager.finishPlotMerge(plotIds, queue); manager.finishPlotMerge(plotIds, queue);
if (whenDone != null) {
queue.setCompleteTask(whenDone);
}
queue.enqueue(); queue.enqueue();
return true; return true;
} }