diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index f539015e..163739b4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -88,14 +88,14 @@ public class MultiverseCore extends JavaPlugin implements MVCore { // Load our configs first as we need them for everything else. this.loadConfigs(); - if (configProvider.getConfig().isEmpty()) { + if (!configProvider.isConfigLoaded()) { Logging.severe("Your configs were not loaded."); Logging.severe("Please check your configs and restart the server."); this.getServer().getPluginManager().disablePlugin(this); return; } - configProvider.getConfig().peek(config -> Logging.setShowingConfig(!config.getSilentStart())); + Logging.setShowingConfig(shouldShowConfig()); var worldManager = worldManagerProvider.get(); @@ -104,13 +104,11 @@ public class MultiverseCore extends JavaPlugin implements MVCore { worldManager.loadWorlds(true); // Now set the firstspawnworld (after the worlds are loaded): - configProvider.getConfig().peek(config -> { - worldManager.setFirstSpawnWorld(config.getFirstSpawnWorld()); - MVWorld firstSpawnWorld = worldManager.getFirstSpawnWorld(); - if (firstSpawnWorld != null) { - config.setFirstSpawnWorld(firstSpawnWorld.getName()); - } - }); + worldManager.setFirstSpawnWorld(configProvider.getConfig().getFirstSpawnWorld()); + MVWorld firstSpawnWorld = worldManager.getFirstSpawnWorld(); + if (firstSpawnWorld != null) { + configProvider.getConfig().setFirstSpawnWorld(firstSpawnWorld.getName()); + } //Setup economy here so vault is loaded // TODO we may need to change MVEconomist to have an enable method or something @@ -157,6 +155,10 @@ public class MultiverseCore extends JavaPlugin implements MVCore { } } + private boolean shouldShowConfig() { + return !configProvider.getConfig().getSilentStart(); + } + /** * Function to Register all the Events needed. */ @@ -211,12 +213,10 @@ public class MultiverseCore extends JavaPlugin implements MVCore { private void logEnableMessage() { Logging.config("Version %s (API v%s) Enabled - By %s", this.getDescription().getVersion(), PROTOCOL, getAuthors()); - configProvider.getConfig().peek(config -> { - if (config.isShowingDonateMessage()) { - getLogger().config("Help dumptruckman keep this project alive. Become a patron! https://www.patreon.com/dumptruckman"); - getLogger().config("One time donations are also appreciated: https://www.paypal.me/dumptruckman"); - } - }); + if (configProvider.getConfig().isShowingDonateMessage()) { + getLogger().config("Help dumptruckman keep this project alive. Become a patron! https://www.patreon.com/dumptruckman"); + getLogger().config("One time donations are also appreciated: https://www.paypal.me/dumptruckman"); + } } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/anchor/AnchorManager.java b/src/main/java/com/onarandombox/MultiverseCore/anchor/AnchorManager.java index 08e14a74..18cfa0d5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/anchor/AnchorManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/anchor/AnchorManager.java @@ -160,8 +160,8 @@ public class AnchorManager { // Add to the list if we're not enforcing access // OR // We are enforcing access and the user has the permission. - if (!this.configProvider.getConfigUnsafe().getEnforceAccess() || - (this.configProvider.getConfigUnsafe().getEnforceAccess() && p.hasPermission(worldPerm))) { + if (!this.configProvider.getConfig().getEnforceAccess() || + (this.configProvider.getConfig().getEnforceAccess() && p.hasPermission(worldPerm))) { myAnchors.add(anchor); } else { Logging.finer(String.format("Not adding anchor %s to the list, user %s doesn't have the %s " + diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java index 16bb48aa..cabe4cc1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java @@ -53,13 +53,13 @@ public class DebugCommand extends MultiverseCommand { @Description("{@@mv-core.debug.change.level.description}") int level) { - this.configProvider.getConfigUnsafe().setGlobalDebug(level); + this.configProvider.getConfig().setGlobalDebug(level); this.plugin.saveAllConfigs(); this.displayDebugMode(issuer); } private void displayDebugMode(BukkitCommandIssuer issuer) { - final int debugLevel = this.configProvider.getConfigUnsafe().getGlobalDebug(); + final int debugLevel = this.configProvider.getConfig().getGlobalDebug(); if (debugLevel == 0) { issuer.sendInfo(MVCorei18n.DEBUG_INFO_OFF); return; diff --git a/src/main/java/com/onarandombox/MultiverseCore/config/MVCoreConfigProvider.java b/src/main/java/com/onarandombox/MultiverseCore/config/MVCoreConfigProvider.java index 17ddf0f2..11d78775 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/config/MVCoreConfigProvider.java +++ b/src/main/java/com/onarandombox/MultiverseCore/config/MVCoreConfigProvider.java @@ -15,7 +15,6 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jvnet.hk2.annotations.Service; import java.io.BufferedReader; @@ -41,7 +40,7 @@ public final class MVCoreConfigProvider { private final Provider worldManagerProvider; // TODO remove this dependency @Inject - public MVCoreConfigProvider( + MVCoreConfigProvider( MultiverseCore plugin, PluginManager pluginManager, Provider worldManagerProvider @@ -51,19 +50,26 @@ public final class MVCoreConfigProvider { this.worldManagerProvider = worldManagerProvider; } - @NotNull - public Option getConfig() { - return Option.of(config); + /** + * Checks if the config is loaded. + * + * @return True if the config is loaded, false otherwise + */ + public boolean isConfigLoaded() { + return config != null; } /** - * Provided to make porting code to use DI easier for now. + * Gets the Core configuration instance. * - * @deprecated Use the {@link #getConfig()} method instead when possible. + * @return The config + * @throws IllegalStateException If the config is not loaded */ - @Nullable - @Deprecated - public MVConfig getConfigUnsafe() { + @NotNull + public MVConfig getConfig() throws IllegalStateException { + if (config == null) { + throw new IllegalStateException("Config is not loaded"); + } return config; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java index 73d0a7bc..7e3f1aaa 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java @@ -42,7 +42,7 @@ public class MVChatListener implements Listener { } // Check whether the Server is set to prefix the chat with the World name. // If not we do nothing, if so we need to check if the World has an Alias. - if (configProvider.getConfigUnsafe().getPrefixChat()) { + if (configProvider.getConfig().getPrefixChat()) { String world = playerListener.getPlayerWorld().get(event.getPlayer().getName()); if (world == null) { world = event.getPlayer().getWorld().getName(); @@ -60,7 +60,7 @@ public class MVChatListener implements Listener { prefix = mvworld.getColoredWorldString(); String chat = event.getFormat(); - String prefixChatFormat = configProvider.getConfigUnsafe().getPrefixChatFormat(); + String prefixChatFormat = configProvider.getConfig().getPrefixChatFormat(); prefixChatFormat = prefixChatFormat.replace("%world%", prefix).replace("%chat%", chat); prefixChatFormat = ChatColor.translateAlternateColorCodes('&', prefixChatFormat); diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java index 331807d2..b9e96e2e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java @@ -8,7 +8,6 @@ package com.onarandombox.MultiverseCore.listeners; import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MVWorld; import com.onarandombox.MultiverseCore.api.WorldPurger; @@ -128,8 +127,8 @@ public class MVEntityListener implements Listener { if (event.isCancelled() || event.getTo() == null) { return; } - if (!this.configProvider.getConfigUnsafe().isUsingDefaultPortalSearch()) { - event.setSearchRadius(this.configProvider.getConfigUnsafe().getPortalSearchRadius()); + if (!this.configProvider.getConfig().isUsingDefaultPortalSearch()) { + event.setSearchRadius(this.configProvider.getConfig().getPortalSearchRadius()); } } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index d38058c6..96719cc8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -37,7 +37,6 @@ import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; import org.jvnet.hk2.annotations.Service; /** @@ -143,7 +142,7 @@ public class MVPlayerListener implements Listener { Player p = event.getPlayer(); if (!p.hasPlayedBefore()) { Logging.finer("Player joined for the FIRST time!"); - if (configProvider.getConfigUnsafe().getFirstSpawnOverride()) { + if (configProvider.getConfig().getFirstSpawnOverride()) { Logging.fine("Moving NEW player to(firstspawnoverride): " + getWorldManager().getFirstSpawnWorld().getSpawnLocation()); this.sendPlayerToDefaultWorld(p); @@ -151,7 +150,7 @@ public class MVPlayerListener implements Listener { return; } else { Logging.finer("Player joined AGAIN!"); - if (this.configProvider.getConfigUnsafe().getEnforceAccess() // check this only if we're enforcing access! + if (this.configProvider.getConfig().getEnforceAccess() // check this only if we're enforcing access! && !this.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) { p.sendMessage("[MV] - Sorry you can't be in this world anymore!"); this.sendPlayerToDefaultWorld(p); @@ -223,7 +222,7 @@ public class MVPlayerListener implements Listener { } // Check if player is allowed to enter the world if we're enforcing permissions - if (configProvider.getConfigUnsafe().getEnforceAccess()) { + if (configProvider.getConfig().getEnforceAccess()) { event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee)); if (event.isCancelled() && teleporter != null) { Logging.fine("Player '" + teleportee.getName() @@ -315,7 +314,7 @@ public class MVPlayerListener implements Listener { + "' because they don't have the FUNDS required to enter."); return; } - if (configProvider.getConfigUnsafe().getEnforceAccess()) { + if (configProvider.getConfig().getEnforceAccess()) { event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer())); if (event.isCancelled()) { Logging.fine("Player '" + event.getPlayer().getName() @@ -327,8 +326,8 @@ public class MVPlayerListener implements Listener { + "' was allowed to go to '" + event.getTo().getWorld().getName() + "' because enforceaccess is off."); } - if (!this.configProvider.getConfigUnsafe().isUsingDefaultPortalSearch()) { - event.setSearchRadius(this.configProvider.getConfigUnsafe().getPortalSearchRadius()); + if (!this.configProvider.getConfig().isUsingDefaultPortalSearch()) { + event.setSearchRadius(this.configProvider.getConfig().getPortalSearchRadius()); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java index bec14475..fbcd0502 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java @@ -108,7 +108,7 @@ public class MVPermissions { */ public boolean canEnterWorld(Player p, MVWorld w) { // If we're not enforcing access, anyone can enter. - if (!configProvider.getConfigUnsafe().getEnforceAccess()) { + if (!configProvider.getConfig().getEnforceAccess()) { Logging.finest("EnforceAccess is OFF. Player was allowed in " + w.getAlias()); return true; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index bffd6908..14c5c32d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -123,7 +123,7 @@ public class PermissionTools { */ public boolean playerHasMoneyToEnter(MVWorld fromWorld, MVWorld toWorld, CommandSender teleporter, Player teleportee, boolean pay) { Player teleporterPlayer; - if (configProvider.getConfigUnsafe().getTeleportIntercept()) { + if (configProvider.getConfig().getTeleportIntercept()) { if (teleporter instanceof ConsoleCommandSender) { return true; } @@ -219,7 +219,7 @@ public class PermissionTools { Logging.finest("Checking '" + teleporter + "' can send '" + teleportee + "' somewhere"); Player teleporterPlayer; - if (configProvider.getConfigUnsafe().getTeleportIntercept()) { + if (configProvider.getConfig().getTeleportIntercept()) { // The console can send anyone anywhere if (teleporter instanceof ConsoleCommandSender) { return true; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/UnsafeCallWrapper.java b/src/main/java/com/onarandombox/MultiverseCore/utils/UnsafeCallWrapper.java index 4f95688b..f37b6697 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/UnsafeCallWrapper.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/UnsafeCallWrapper.java @@ -40,7 +40,7 @@ public class UnsafeCallWrapper { actualFormatArgs[formatArgs.length] = t; Logging.warning(action, actualFormatArgs); Logging.warning("This is a bug in %s, NOT a bug in Multiverse!", plugin); - if (configProvider.getConfigUnsafe().getGlobalDebug() >= 1) + if (configProvider.getConfig().getGlobalDebug() >= 1) t.printStackTrace(); return null; }