From ae63a166ddc38f1a63ac655c5b03e763082c8f8b Mon Sep 17 00:00:00 2001 From: Tigerpanzer_02 <37453987+Tigerpanzer02@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:51:20 +0200 Subject: [PATCH] Changed onDisable process to make sure all data gets saved even on mysql --- .../projects/minigamesbox/classic/PluginMain.java | 10 ++++++---- .../minigamesbox/classic/arena/PluginArenaManager.java | 10 ++++++++-- .../classic/arena/states/PluginRestartingState.java | 1 - .../projects/minigamesbox/classic/user/User.java | 4 +--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/PluginMain.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/PluginMain.java index 967c48e9..66e0dea2 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/PluginMain.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/PluginMain.java @@ -386,11 +386,13 @@ public void onDisable() { Bukkit.getLogger().removeHandler(getExceptionLogHandler()); if(getArenaRegistry() != null) { - for(IPluginArena arena : getArenaRegistry().getArenas()) { - for(Player player : new ArrayList<>(arena.getPlayers())) { - getArenaManager().leaveAttempt(player, arena); + try { + for(IPluginArena arena : getArenaRegistry().getArenas()) { + getArenaManager().stopGame(true, arena); + arena.getMapRestorerManager().fullyRestoreArena(); } - arena.getMapRestorerManager().fullyRestoreArena(); + } catch(Exception exception) { + getDebugger().debug("Error while disabling arenas: {0}", exception.getMessage()); } } if(getUserManager() != null) { diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaManager.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaManager.java index e494dd7e..e6fad302 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaManager.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/PluginArenaManager.java @@ -274,8 +274,14 @@ public void stopGame(boolean quickStop, @NotNull IPluginArena arena) { } } } - arena.setTimer(quickStop ? 0 : plugin.getConfig().getInt("Time-Manager.Ending", 10), true); - arena.setArenaState(IArenaState.ENDING, true); + if(quickStop) { + arena.setTimer(0, true); + arena.setArenaState(IArenaState.RESTARTING, true); + } else { + arena.setTimer(plugin.getConfig().getInt("Time-Manager.Ending", 10), true); + arena.setArenaState(IArenaState.ENDING, true); + } + for(Player players : arena.getPlayers()) { plugin.getSpecialItemManager().removeSpecialItemsOfStage(players, SpecialItem.DisplayStage.IN_GAME); plugin.getSpecialItemManager().addSpecialItemsOfStage(players, SpecialItem.DisplayStage.ENDING); diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/states/PluginRestartingState.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/states/PluginRestartingState.java index ed33ad96..be533293 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/states/PluginRestartingState.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/arena/states/PluginRestartingState.java @@ -77,7 +77,6 @@ public void handleCall(PluginArena arena) { arenaState = IArenaState.WAITING_FOR_PLAYERS; } plugin.getDebugger().performance("ArenaUpdate", "END Arena {0} Running state {1} value for state {2} and time {3}", arena.getId(), IArenaState.RESTARTING, arenaState, arenaTimer); - } @Override diff --git a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/user/User.java b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/user/User.java index ee3c8703..21371898 100644 --- a/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/user/User.java +++ b/MiniGamesBox Classic/src/main/java/plugily/projects/minigamesbox/classic/user/User.java @@ -138,9 +138,7 @@ private void changeUserStatistic(IStatisticType statisticType, int value) { plugin.getDebugger().debug("Set User {0} statistic to {1} for {2} ", statisticType.getName(), value, player.getName()); //statistics manipulation events are called async when using mysql - Bukkit.getScheduler().runTask(plugin, () -> { - Bukkit.getPluginManager().callEvent(new PlugilyPlayerStatisticChangeEvent(plugin.getArenaRegistry().getArena(player), player, statisticType, value)); - }); + Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getPluginManager().callEvent(new PlugilyPlayerStatisticChangeEvent(plugin.getArenaRegistry().getArena(player), player, statisticType, value))); } }