From 82f47af92409c909e507289659589c4efc511ffc Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:08:38 +0800 Subject: [PATCH] Completely remove the old WorldManager from startup --- .../MultiverseCore/MultiverseCore.java | 50 ++++++------------- .../MultiverseCore/worldnew/WorldManager.java | 4 +- .../worldnew/config/WorldsConfigManager.java | 4 +- 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index acaf568f..d69f316e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -11,8 +11,6 @@ import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.anchor.AnchorManager; import com.onarandombox.MultiverseCore.api.Destination; import com.onarandombox.MultiverseCore.api.MVCore; -import com.onarandombox.MultiverseCore.api.MVWorld; -import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand; import com.onarandombox.MultiverseCore.commandtools.PluginLocales; @@ -60,9 +58,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore { @Inject private Provider<MVCoreConfig> configProvider; @Inject - private Provider<MVWorldManager> worldManagerProvider; - @Inject - private Provider<WorldManager> newWorldManagerProvider; + private Provider<WorldManager> worldManagerProvider; @Inject private Provider<AnchorManager> anchorManagerProvider; @Inject @@ -116,39 +112,24 @@ public class MultiverseCore extends JavaPlugin implements MVCore { this.getServer().getPluginManager().disablePlugin(this); return; } - Logging.setShowingConfig(shouldShowConfig()); - var worldManager = worldManagerProvider.get(); + // Initialize the worlds + worldManagerProvider.get().initAllWorlds(); - worldManager.loadWorldsConfig(); -// worldManager.getDefaultWorldGenerators(); -// worldManager.loadDefaultWorlds(); -// worldManager.loadWorlds(true); -// -// // Now set the firstspawnworld (after the worlds are loaded): -// worldManager.setFirstSpawnWorld(config.getFirstSpawnLocation()); -// MVWorld firstSpawnWorld = worldManager.getFirstSpawnWorld(); -// if (firstSpawnWorld != null) { -// config.setFirstSpawnLocation(firstSpawnWorld.getName()); -// } - - var newWorldManager = newWorldManagerProvider.get(); - newWorldManager.initAllWorlds(); // TODO: Possibly move this to constructor of WorldManager - - //Setup economy here so vault is loaded - this.loadEconomist(); + // Setup economy here so vault is loaded + loadEconomist(); // Init all the other stuff - this.loadAnchors(); - this.registerEvents(); - this.setUpLocales(); - this.registerCommands(); - this.registerDestinations(); - this.setupMetrics(); - this.loadPlaceholderAPIIntegration(); - this.saveAllConfigs(); - this.logEnableMessage(); + loadAnchors(); + registerEvents(); + setUpLocales(); + registerCommands(); + registerDestinations(); + setupMetrics(); + loadPlaceholderAPIIntegration(); + saveAllConfigs(); + logEnableMessage(); } /** @@ -156,7 +137,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore { */ @Override public void onDisable() { - this.saveAllConfigs(); + saveAllConfigs(); shutdownDependencyInjection(); Logging.shutdown(); } @@ -382,7 +363,6 @@ public class MultiverseCore extends JavaPlugin implements MVCore { && anchorManagerProvider.get().saveAnchors(); } - /** * Gets the best service from this plugin that implements the given contract or has the given implementation. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java index 487b6ff2..317f15da 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java @@ -379,7 +379,7 @@ public class WorldManager { return worldsMap.containsKey(worldName); } - public void saveWorldsConfig() { - worldsConfigManager.save(); + public boolean saveWorldsConfig() { + return worldsConfigManager.save(); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigManager.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigManager.java index 61806b3f..74e1d694 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigManager.java @@ -41,12 +41,14 @@ public class WorldsConfigManager { return worldsConfig != null; } - public void save() { + public boolean save() { try { worldsConfig.save(worldConfigFile); + return true; } catch (IOException e) { e.printStackTrace(); } + return false; } public Set<String> getAllWorldsInConfig() {