Fix some load-order issues probably.

Edge cases might still exist around plugins which use WE for initial
world-gen, or in general plugins that try to access the platform
before it's ready.
This commit is contained in:
wizjany 2019-07-27 11:45:09 -04:00
parent 8f33e0d550
commit 0f420f02ff

View File

@ -96,7 +96,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
private static final Logger log = LoggerFactory.getLogger(WorldEditPlugin.class); private static final Logger log = LoggerFactory.getLogger(WorldEditPlugin.class);
public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui"; public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui";
private static WorldEditPlugin INSTANCE; private static WorldEditPlugin INSTANCE;
private static WorldInitListener worldInitListener = null;
private BukkitImplAdapter bukkitAdapter; private BukkitImplAdapter bukkitAdapter;
private BukkitServerInterface server; private BukkitServerInterface server;
@ -139,22 +138,19 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
getServer().getPluginManager().registerEvents(new AsyncTabCompleteListener(), this); getServer().getPluginManager().registerEvents(new AsyncTabCompleteListener(), this);
} }
// register this so we can load world-dependent data right as the first world is loading initializeRegistries(); // this creates the objects matching Bukkit's enums - but doesn't fill them with data yet
if (worldInitListener != null) { if (Bukkit.getWorlds().isEmpty()) {
setupPreWorldData();
// register this so we can load world-dependent data right as the first world is loading
getServer().getPluginManager().registerEvents(new WorldInitListener(), this);
} else {
getLogger().warning("Server reload detected. This may cause various issues with WorldEdit and dependent plugins."); getLogger().warning("Server reload detected. This may cause various issues with WorldEdit and dependent plugins.");
try { try {
// these don't stick around between reload setupPreWorldData();
loadAdapter(); // since worlds are loaded already, we can do this now
loadConfig(); setupWorldData();
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
} catch (Throwable ignored) { } catch (Throwable ignored) {
} }
} else {
getServer().getPluginManager().registerEvents((worldInitListener = new WorldInitListener()), this);
loadAdapter(); // Need an adapter to work with special blocks with NBT data
setupRegistries();
WorldEdit.getInstance().loadMappings();
loadConfig(); // Load configuration
} }
// Enable metrics // Enable metrics
@ -162,12 +158,19 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
PaperLib.suggestPaper(this); PaperLib.suggestPaper(this);
} }
private void setupPreWorldData() {
loadAdapter();
loadConfig();
WorldEdit.getInstance().loadMappings();
}
private void setupWorldData() { private void setupWorldData() {
setupTags(); setupTags(); // datapacks aren't loaded until just before the world is, and bukkit has no event for this
// so the earliest we can do this is in WorldInit
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent()); WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
} }
private void setupRegistries() { private void initializeRegistries() {
// Biome // Biome
for (Biome biome : Biome.values()) { for (Biome biome : Biome.values()) {
String lowerCaseBiomeName = biome.name().toLowerCase(Locale.ROOT); String lowerCaseBiomeName = biome.name().toLowerCase(Locale.ROOT);
@ -487,9 +490,9 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
if (!event.isCommand()) return; if (!event.isCommand()) return;
String buffer = event.getBuffer(); String buffer = event.getBuffer();
final String[] parts = buffer.split(" "); int firstSpace = buffer.indexOf(' ');
if (parts.length < 1) return; if (firstSpace < 0) return;
final String label = parts[0]; final String label = buffer.substring(0, firstSpace);
final Optional<org.enginehub.piston.Command> command final Optional<org.enginehub.piston.Command> command
= WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label); = WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().getCommand(label);
if (!command.isPresent()) return; if (!command.isPresent()) return;