From 79bec4177f4b04bc7601887a0799109cee529f20 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 18 Sep 2019 06:51:20 +0200 Subject: [PATCH] Nice shutdown --- src/de/steamwar/fightsystem/FightSystem.java | 9 +++++++++ .../fightsystem/countdown/SpectateOverCountdown.java | 4 ++-- src/de/steamwar/fightsystem/fight/FightTeam.java | 3 +-- src/de/steamwar/fightsystem/kit/KitManager.java | 2 +- .../fightsystem/listener/HotbarGUIListener.java | 10 ++++------ src/de/steamwar/fightsystem/listener/TestListener.java | 2 +- src/de/steamwar/fightsystem/utils/Config.java | 8 ++++---- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/de/steamwar/fightsystem/FightSystem.java b/src/de/steamwar/fightsystem/FightSystem.java index 2ae6b0c..1b257e3 100644 --- a/src/de/steamwar/fightsystem/FightSystem.java +++ b/src/de/steamwar/fightsystem/FightSystem.java @@ -178,6 +178,8 @@ public class FightSystem extends JavaPlugin { private static void loadKits(FightTeam team){ for(FightPlayer allFightPlayers : team.getPlayers()) { + if(allFightPlayers.getPlayer() == null) + continue; allFightPlayers.getPlayer().getInventory().clear(); allFightPlayers.getKit().loadToPlayer(allFightPlayers.getPlayer()); } @@ -232,4 +234,11 @@ public class FightSystem extends JavaPlugin { public static boolean isEntern() { return entern; } + + public static void shutdown(String reason){ + if(reason != null) + Bukkit.broadcastMessage(reason); + Bukkit.getOnlinePlayers().forEach(player -> player.kickPlayer(null)); + Bukkit.shutdown(); + } } \ No newline at end of file diff --git a/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java b/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java index 27c4035..c9b1d1a 100644 --- a/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java +++ b/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java @@ -1,7 +1,7 @@ package de.steamwar.fightsystem.countdown; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.utils.Config; -import org.bukkit.Bukkit; import org.bukkit.Sound; public class SpectateOverCountdown extends Countdown { @@ -17,6 +17,6 @@ public class SpectateOverCountdown extends Countdown { @Override public void countdownFinished() { - Bukkit.shutdown(); + FightSystem.shutdown(null); } } diff --git a/src/de/steamwar/fightsystem/fight/FightTeam.java b/src/de/steamwar/fightsystem/fight/FightTeam.java index 528e4fd..1494200 100644 --- a/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -164,8 +164,7 @@ public class FightTeam { setLeader(players.iterator().next()); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + leader.getPlayer().getName() + " §aist nun Leader von Team " + getName() + "§a!"); }else if(!Config.event()){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + getName() + " §chat keine Spieler mehr.\n Arena schließt..."); - Bukkit.shutdown(); + FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getName() + " §chat keine Spieler mehr.\n Arena schließt..."); }else{ setLeader(null); } diff --git a/src/de/steamwar/fightsystem/kit/KitManager.java b/src/de/steamwar/fightsystem/kit/KitManager.java index 4d49e19..f877c88 100644 --- a/src/de/steamwar/fightsystem/kit/KitManager.java +++ b/src/de/steamwar/fightsystem/kit/KitManager.java @@ -45,7 +45,7 @@ public class KitManager { if(!new File(KITS_PATH).exists()) { saveAllKits(); Bukkit.getLogger().log(Level.INFO, "kits.data erstellt!"); - Bukkit.shutdown(); + FightSystem.shutdown(null); return; } diff --git a/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java b/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java index 595fa33..e0092db 100644 --- a/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java +++ b/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java @@ -1,12 +1,11 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.utils.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.commands.GUI; +import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightState; -import org.bukkit.Bukkit; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.utils.Config; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractEvent; @@ -49,8 +48,7 @@ public class HotbarGUIListener extends BasicListener { fightTeam.setReady(false); break; case "§4Abbrechen": - Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team von §a" + fightTeam.getLeader().getPlayer().getName() + " §6hat den Kampf abgebrochen! \n Server stoppt..."); - Bukkit.shutdown(); + FightSystem.shutdown(FightSystem.PREFIX + "§6Das Team von §a" + fightTeam.getLeader().getPlayer().getName() + " §6hat den Kampf abgebrochen! \n Server stoppt..."); break; case "§eKit wählen": GUI.kitSelection(player); diff --git a/src/de/steamwar/fightsystem/listener/TestListener.java b/src/de/steamwar/fightsystem/listener/TestListener.java index 7053394..a997cc7 100644 --- a/src/de/steamwar/fightsystem/listener/TestListener.java +++ b/src/de/steamwar/fightsystem/listener/TestListener.java @@ -38,7 +38,7 @@ public class TestListener extends BasicListener { @EventHandler public void handlePlayerQuit(PlayerQuitEvent event){ if(Bukkit.getOnlinePlayers().isEmpty()) - Bukkit.shutdown(); + FightSystem.shutdown(null); } @Override diff --git a/src/de/steamwar/fightsystem/utils/Config.java b/src/de/steamwar/fightsystem/utils/Config.java index e0d2074..ec0b2bb 100644 --- a/src/de/steamwar/fightsystem/utils/Config.java +++ b/src/de/steamwar/fightsystem/utils/Config.java @@ -106,11 +106,11 @@ public class Config { if(!new File(Bukkit.getWorldContainer().getPath() + '/' + Bukkit.getWorlds().get(0).getName() + "/config.yml").exists()) { FightSystem.getPlugin().saveDefaultConfig(); System.out.println(FightSystem.PREFIX + "config.yml erstellt und geladen!"); - Bukkit.shutdown(); + FightSystem.shutdown(null); } if(!new File("plugins/" + FightSystem.getPlugin().getName() + "/config.yml").exists()) { System.out.println(FightSystem.PREFIX + "config.yml fehlt!"); - Bukkit.shutdown(); + FightSystem.shutdown(null); } FileConfiguration config = FightSystem.getPlugin().getConfig(); YamlConfiguration worldconfig = YamlConfiguration.loadConfiguration(new File(Bukkit.getWorldContainer().getPath() + '/' + Bukkit.getWorlds().get(0).getName() + "/config.yml")); @@ -244,7 +244,7 @@ public class Config { EventFight eventFight = EventFight.get(EventKampfID); if(eventFight == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight"); - Bukkit.shutdown(); + FightSystem.shutdown(null); return; } @@ -253,7 +253,7 @@ public class Config { if(team1 == null || team2 == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load Team"); - Bukkit.shutdown(); + FightSystem.shutdown(null); return; }