From 320363e5ff7d06f417b4e36340ff2fe15bfbbec6 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 9 Jun 2022 21:38:06 +0100 Subject: [PATCH] QueryCapability is effectively a "dumb" method --- .../bukkit/generator/BukkitPlotGenerator.java | 6 +---- .../com/plotsquared/core/PlotSquared.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 5cbf70b47..7b7cbd2c3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -37,8 +37,6 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.ScopedQueueCoordinator; import com.plotsquared.core.util.ChunkManager; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.math.BlockVector2; import org.bukkit.World; import org.bukkit.block.Biome; @@ -135,9 +133,7 @@ public class BukkitPlotGenerator extends ChunkGenerator private synchronized void checkLoaded(@NonNull World world) { // Do not attempt to load configurations until WorldEdit has a platform ready. - try { - WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING); - } catch (Throwable t) { + if (!PlotSquared.get().isWeInitialised()) { return; } if (!this.loaded) { diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 9c9bb09f3..9ec881447 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -72,7 +72,10 @@ import com.plotsquared.core.util.ReflectionUtils; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.uuid.UUIDPipeline; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.util.eventbus.EventHandler; +import com.sk89q.worldedit.util.eventbus.Subscribe; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @@ -153,6 +156,8 @@ public class PlotSquared { private EventDispatcher eventDispatcher; private PlotListener plotListener; + private boolean weInitialised; + /** * Initialize PlotSquared with the desired Implementation class. * @@ -223,6 +228,7 @@ public class PlotSquared { } this.worldedit = WorldEdit.getInstance(); + WorldEdit.getInstance().getEventBus().register(new WEPlatformReadyListener()); // Create Event utility class this.eventDispatcher = new EventDispatcher(this.worldedit); @@ -1574,6 +1580,13 @@ public class PlotSquared { return this.plotListener; } + /** + * Get if the {@link PlatformReadyEvent} has been sent by WE. There is no way to query this within WE itself. + */ + public boolean isWeInitialised() { + return weInitialised; + } + /** * Different ways of sorting {@link Plot plots} */ @@ -1596,4 +1609,14 @@ public class PlotSquared { DISTANCE_FROM_ORIGIN } + private final class WEPlatformReadyListener { + + @Subscribe(priority = EventHandler.Priority.VERY_EARLY) + public void onPlatformReady(PlatformReadyEvent event) { + weInitialised = true; + WorldEdit.getInstance().getEventBus().unregister(WEPlatformReadyListener.this); + } + + } + }