diff --git a/module/classes/src/main/java/org/battleplugins/arena/module/classes/Classes.java b/module/classes/src/main/java/org/battleplugins/arena/module/classes/Classes.java index 8fde74df..100a579b 100644 --- a/module/classes/src/main/java/org/battleplugins/arena/module/classes/Classes.java +++ b/module/classes/src/main/java/org/battleplugins/arena/module/classes/Classes.java @@ -1,8 +1,10 @@ package org.battleplugins.arena.module.classes; +import org.battleplugins.arena.BattleArena; import org.battleplugins.arena.config.ArenaConfigParser; import org.battleplugins.arena.config.ParseException; import org.battleplugins.arena.event.BattleArenaPostInitializeEvent; +import org.battleplugins.arena.event.BattleArenaReloadedEvent; import org.battleplugins.arena.event.action.EventActionType; import org.battleplugins.arena.event.arena.ArenaCreateExecutorEvent; import org.battleplugins.arena.module.ArenaModule; @@ -35,30 +37,44 @@ public class Classes implements ArenaModuleInitializer { @EventHandler public void onPostInitialize(BattleArenaPostInitializeEvent event) { - ArenaModuleContainer container = event.getBattleArena() + this.onLoad(event.getBattleArena(), true); + } + + @EventHandler + public void onReloaded(BattleArenaReloadedEvent event) { + this.onLoad(event.getBattleArena(), false); + } + + private void onLoad(BattleArena plugin, boolean initial) { + ArenaModuleContainer container = plugin .module(ID) .orElseThrow(); - Path dataFolder = event.getBattleArena().getDataFolder().toPath(); + Path dataFolder = plugin.getDataFolder().toPath(); Path classesPath = dataFolder.resolve("classes.yml"); if (Files.notExists(classesPath)) { InputStream inputStream = container.getResource("classes.yml"); try { Files.copy(inputStream, classesPath); } catch (Exception e) { - event.getBattleArena().error("Failed to copy classes.yml to data folder!", e); - container.disable("Failed to copy classes.yml to data folder!"); + plugin.error("Failed to copy classes.yml to data folder!", e); + + if (initial) { + container.disable("Failed to copy classes.yml to data folder!"); + } return; } } Configuration classesConfig = YamlConfiguration.loadConfiguration(classesPath.toFile()); try { - this.classes = ArenaConfigParser.newInstance(classesPath, ClassesConfig.class, classesConfig, event.getBattleArena()); + this.classes = ArenaConfigParser.newInstance(classesPath, ClassesConfig.class, classesConfig, plugin); } catch (ParseException e) { ParseException.handle(e); - container.disable("Failed to parse classes.yml!"); + if (initial) { + container.disable("Failed to parse classes.yml!"); + } } } diff --git a/module/scoreboards/src/main/java/org/battleplugins/arena/module/scoreboard/Scoreboards.java b/module/scoreboards/src/main/java/org/battleplugins/arena/module/scoreboard/Scoreboards.java index 1ca82a71..27ead7da 100644 --- a/module/scoreboards/src/main/java/org/battleplugins/arena/module/scoreboard/Scoreboards.java +++ b/module/scoreboards/src/main/java/org/battleplugins/arena/module/scoreboard/Scoreboards.java @@ -1,9 +1,11 @@ package org.battleplugins.arena.module.scoreboard; +import org.battleplugins.arena.BattleArena; import org.battleplugins.arena.config.ArenaConfigParser; import org.battleplugins.arena.config.ParseException; import org.battleplugins.arena.event.ArenaListener; import org.battleplugins.arena.event.BattleArenaPostInitializeEvent; +import org.battleplugins.arena.event.BattleArenaReloadedEvent; import org.battleplugins.arena.event.action.EventActionType; import org.battleplugins.arena.event.arena.ArenaInitializeEvent; import org.battleplugins.arena.module.ArenaModule; @@ -38,19 +40,31 @@ public Scoreboards() { @EventHandler public void onPostInitialize(BattleArenaPostInitializeEvent event) { - ArenaModuleContainer container = event.getBattleArena() + this.onLoad(event.getBattleArena(), true); + } + + @EventHandler + public void onReloaded(BattleArenaReloadedEvent event) { + this.onLoad(event.getBattleArena(), false); + } + + private void onLoad(BattleArena plugin, boolean initial) { + ArenaModuleContainer container = plugin .module(ID) .orElseThrow(); - Path dataFolder = event.getBattleArena().getDataFolder().toPath(); + Path dataFolder = plugin.getDataFolder().toPath(); Path scoreboardsPath = dataFolder.resolve("scoreboards.yml"); if (Files.notExists(scoreboardsPath)) { InputStream inputStream = container.getResource("scoreboards.yml"); try { Files.copy(inputStream, scoreboardsPath); } catch (Exception e) { - event.getBattleArena().error("Failed to copy scoreboards.yml to data folder!", e); - container.disable("Failed to copy scoreboards.yml to data folder!"); + plugin.error("Failed to copy scoreboards.yml to data folder!", e); + + if (initial) { + container.disable("Failed to copy scoreboards.yml to data folder!"); + } return; } } @@ -61,7 +75,9 @@ public void onPostInitialize(BattleArenaPostInitializeEvent event) { } catch (ParseException e) { ParseException.handle(e); - container.disable("Failed to parse scoreboards.yml!"); + if (initial) { + container.disable("Failed to parse scoreboards.yml!"); + } } } diff --git a/module/tournaments/src/main/java/org/battleplugins/arena/module/tournaments/Tournaments.java b/module/tournaments/src/main/java/org/battleplugins/arena/module/tournaments/Tournaments.java index b27e7953..fdc9f1c7 100644 --- a/module/tournaments/src/main/java/org/battleplugins/arena/module/tournaments/Tournaments.java +++ b/module/tournaments/src/main/java/org/battleplugins/arena/module/tournaments/Tournaments.java @@ -5,6 +5,7 @@ import org.battleplugins.arena.config.ArenaConfigParser; import org.battleplugins.arena.config.ParseException; import org.battleplugins.arena.event.BattleArenaPostInitializeEvent; +import org.battleplugins.arena.event.BattleArenaReloadedEvent; import org.battleplugins.arena.module.ArenaModule; import org.battleplugins.arena.module.ArenaModuleContainer; import org.battleplugins.arena.module.ArenaModuleInitializer; @@ -13,7 +14,6 @@ import org.bukkit.event.EventHandler; import org.jetbrains.annotations.Nullable; -import java.io.File; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; @@ -38,19 +38,30 @@ public Tournaments() { @EventHandler public void onPostInitialize(BattleArenaPostInitializeEvent event) { - ArenaModuleContainer container = event.getBattleArena() + this.onLoad(event.getBattleArena(), true); + } + + @EventHandler + public void onReloaded(BattleArenaReloadedEvent event) { + this.onLoad(event.getBattleArena(), false); + } + + private void onLoad(BattleArena plugin, boolean initial) { + ArenaModuleContainer container = plugin .module(ID) .orElseThrow(); - Path dataFolder = event.getBattleArena().getDataFolder().toPath(); + Path dataFolder = plugin.getDataFolder().toPath(); Path tournamentPath = dataFolder.resolve("tournament-config.yml"); if (Files.notExists(tournamentPath)) { InputStream inputStream = container.getResource("tournament-config.yml"); try { Files.copy(inputStream, tournamentPath); } catch (Exception e) { - event.getBattleArena().error("Failed to copy tournament-config.yml to data folder!", e); - container.disable("Failed to copy tournament-config.yml to data folder!"); + plugin.error("Failed to copy tournament-config.yml to data folder!", e); + if (initial) { + container.disable("Failed to copy tournament-config.yml to data folder!"); + } return; } } @@ -61,7 +72,9 @@ public void onPostInitialize(BattleArenaPostInitializeEvent event) { } catch (ParseException e) { ParseException.handle(e); - container.disable("Failed to parse tournament-config.yml!"); + if (initial) { + container.disable("Failed to parse tournament-config.yml!"); + } } }