diff --git a/plugin/src/main/java/org/battleplugins/arena/BattleArena.java b/plugin/src/main/java/org/battleplugins/arena/BattleArena.java index 1dd3c6fd..fdb16b6a 100644 --- a/plugin/src/main/java/org/battleplugins/arena/BattleArena.java +++ b/plugin/src/main/java/org/battleplugins/arena/BattleArena.java @@ -88,11 +88,13 @@ public void onLoad() { this.info("Loading BattleArena {} for {}", this.getPluginMeta().getVersion(), Version.getServerVersion()); + this.loadConfig(); + Path dataFolder = this.getDataFolder().toPath(); this.arenasPath = dataFolder.resolve("arenas"); Path modulesPath = dataFolder.resolve("modules"); - Util.copyDirectories(this.getFile(), modulesPath, "modules"); + Util.copyDirectories(this.getFile(), modulesPath, "modules", this.config.getDisabledModules().toArray(String[]::new)); this.moduleLoader = new ArenaModuleLoader(this, this.getClassLoader(), modulesPath); try { @@ -118,21 +120,6 @@ public void onEnable() { } private void enable() { - // Copy our default configs - this.saveDefaultConfig(); - - File configFile = new File(this.getDataFolder(), "config.yml"); - Configuration config = YamlConfiguration.loadConfiguration(configFile); - try { - this.config = ArenaConfigParser.newInstance(configFile.toPath(), BattleArenaConfig.class, config); - } catch (ParseException e) { - ParseException.handle(e); - - this.error("Failed to load BattleArena configuration! Disabling plugin."); - this.getServer().getPluginManager().disablePlugin(this); - return; - } - this.debugMode = this.config.isDebugMode(); if (Files.notExists(this.arenasPath)) { @@ -267,6 +254,10 @@ public void reload() { new BattleArenaReloadEvent(this).callEvent(); this.disable(); + + // Reload the config + this.loadConfig(); + this.enable(); // Reload loaders - has to be done this way for third party @@ -750,6 +741,22 @@ private void clearDynamicMaps() { } } + private void loadConfig() { + this.saveDefaultConfig(); + + File configFile = new File(this.getDataFolder(), "config.yml"); + Configuration config = YamlConfiguration.loadConfiguration(configFile); + try { + this.config = ArenaConfigParser.newInstance(configFile.toPath(), BattleArenaConfig.class, config); + } catch (ParseException e) { + ParseException.handle(e); + + this.error("Failed to load BattleArena configuration! Disabling plugin."); + this.getServer().getPluginManager().disablePlugin(this); + return; + } + } + /** * Returns the instance of the plugin. * diff --git a/plugin/src/main/java/org/battleplugins/arena/BattleArenaConfig.java b/plugin/src/main/java/org/battleplugins/arena/BattleArenaConfig.java index 1e3457f3..fd0901c8 100644 --- a/plugin/src/main/java/org/battleplugins/arena/BattleArenaConfig.java +++ b/plugin/src/main/java/org/battleplugins/arena/BattleArenaConfig.java @@ -23,9 +23,12 @@ public class BattleArenaConfig { @ArenaOption(name = "max-dynamic-maps", description = "The maximum number of dynamic maps an Arena can have allocated at once.", required = true) private int maxDynamicMaps; + @ArenaOption(name = "disabled-modules", description = "Modules that are disabled by default.") + private List disabledModules; + @ArenaOption(name = "events", description = "The configured events.", required = true) private Map> events; - + @ArenaOption(name = "debug-mode", description = "Whether debug mode is enabled.") private boolean debugMode; @@ -45,8 +48,12 @@ public int getMaxDynamicMaps() { return this.maxDynamicMaps; } + public List getDisabledModules() { + return this.disabledModules == null ? List.of() : List.copyOf(this.disabledModules); + } + public Map> getEvents() { - return this.events; + return Map.copyOf(this.events); } public boolean isDebugMode() { diff --git a/plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java b/plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java index 82d149e7..1a081105 100644 --- a/plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java +++ b/plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java @@ -105,6 +105,11 @@ public void loadModules() throws IOException { public void enableModules() { this.modules.values().forEach(module -> { + if (this.plugin.getMainConfig().getDisabledModules().contains(module.module().id())) { + this.plugin.info("Module {} is disabled in the configuration. Skipping...", module.module().name()); + return; + } + if (module.mainClass() instanceof ArenaModuleInitializer moduleInitializer) { Bukkit.getPluginManager().registerEvents(moduleInitializer, this.plugin); } diff --git a/plugin/src/main/java/org/battleplugins/arena/util/Util.java b/plugin/src/main/java/org/battleplugins/arena/util/Util.java index 8b3d4e25..e254b977 100644 --- a/plugin/src/main/java/org/battleplugins/arena/util/Util.java +++ b/plugin/src/main/java/org/battleplugins/arena/util/Util.java @@ -151,7 +151,7 @@ public static void copyFields(T oldInstance, T newInstance) { } } - public static void copyDirectories(File jarFile, Path outputPath, String directory) { + public static void copyDirectories(File jarFile, Path outputPath, String directory, String... ignoredFiles) { Path jarPath = jarFile.toPath(); try { if (Files.notExists(outputPath)) { @@ -177,6 +177,12 @@ public static void copyDirectories(File jarFile, Path outputPath, String directo return; } + for (String ignoredFile : ignoredFiles) { + if (relativePath.toString().startsWith(ignoredFile)) { + return; + } + } + try { Files.createDirectories(targetPath.getParent()); Files.copy(path, targetPath); diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index e77a1619..84061b28 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -17,6 +17,10 @@ max-backups: 5 # Set to -1 to disable this limit. max-dynamic-maps: 5 +# Modules that are disabled by default. BattleArena comes pre-installed with +# multiple modules that can be disabled below if their behavior is not desired +disabled-modules: [] + # Event configurations events: FFA: