From 48fb6691197cbf476dceab9dc837815019819762 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sat, 25 May 2019 18:11:23 -0400 Subject: [PATCH] Guard against reloads breaking too much. --- .../worldedit/bukkit/WorldEditPlugin.java | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 3c147456c..1fb7633bf 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -87,8 +87,9 @@ import static com.google.common.base.Preconditions.checkNotNull; public class WorldEditPlugin extends JavaPlugin implements TabCompleter { private static final Logger log = LoggerFactory.getLogger(WorldEditPlugin.class); - public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui"; + static final String CUI_PLUGIN_CHANNEL = "worldedit:cui"; private static WorldEditPlugin INSTANCE; + private static WorldInitListener worldInitListener = null; private BukkitImplAdapter bukkitAdapter; private BukkitServerInterface server; @@ -123,13 +124,33 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { getServer().getPluginManager().registerEvents(new WorldEditListener(this), this); // register this so we can load world-dependent data right as the first world is loading - getServer().getPluginManager().registerEvents(new WorldInitListener(), this); + if (worldInitListener != null) { + getLogger().warning("Server reload detected. This may cause various issues with WorldEdit and dependant plugins."); + try { + // these don't stick around between reload + loadAdapter(); + loadConfig(); + } catch (Throwable ignored) { + } + } else { + getServer().getPluginManager().registerEvents((worldInitListener = new WorldInitListener()), this); + } // Enable metrics new Metrics(this); } - public void setupRegistries() { + private void setupWorldData() { + loadAdapter(); // Need an adapter to work with special blocks with NBT data + setupRegistries(); + WorldEdit.getInstance().loadMappings(); + loadConfig(); // Load configuration + setupTags(); + + WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent()); + } + + private void setupRegistries() { // Biome for (Biome biome : Biome.values()) { String lowerCaseBiomeName = biome.name().toLowerCase(Locale.ROOT); @@ -434,14 +455,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { public void onWorldInit(@SuppressWarnings("unused") WorldInitEvent event) { if (loaded) return; loaded = true; - - loadAdapter(); // Need an adapter to work with special blocks with NBT data - setupRegistries(); - WorldEdit.getInstance().loadMappings(); - loadConfig(); // Load configuration - setupTags(); - - WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent()); + setupWorldData(); } } }