From b95cd479e02e7fae2725862ea3508cf007ebf1ae Mon Sep 17 00:00:00 2001 From: lixfel Date: Sun, 14 Apr 2019 15:07:40 +0200 Subject: [PATCH] TechKO & FightTeamRemove fix (untested due to Server "belegt") --- .../yaruma/fightsystem/fight/FightTeam.java | 14 ++--- .../listener/PlayerQuitListener.java | 61 +++++-------------- .../winconditions/WinconditionTechKO.java | 16 ++--- 3 files changed, 26 insertions(+), 65 deletions(-) diff --git a/src/me/yaruma/fightsystem/fight/FightTeam.java b/src/me/yaruma/fightsystem/fight/FightTeam.java index 83291c0..3f53d4e 100644 --- a/src/me/yaruma/fightsystem/fight/FightTeam.java +++ b/src/me/yaruma/fightsystem/fight/FightTeam.java @@ -100,7 +100,11 @@ public class FightTeam { } public void removePlayer(Player player) { - FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player); + FightPlayer fightPlayer = getFightPlayer(player); + if(fightPlayer == null){ + System.out.println("FightPlayer == null! : " + player.getName()); + return; + } players.remove(fightPlayer); if(fightPlayer.isLeader()) this.leader = null; @@ -152,13 +156,6 @@ public class FightTeam { } schem.paste(w, v, false, true, aT).flushQueue(); teleportToSpawn(); - Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), new Runnable() { - @Override - public void run() { - Bukkit.broadcastMessage("ADD WATER"); - WinconditionTechKO.addWater(); - } - }, 20*10L); } public void setSchematic(Schematic schematic){ @@ -166,6 +163,7 @@ public class FightTeam { if(Fight.getOpposite(this).hasSchematic()){ pasteSchematic(); Fight.getOpposite(this).pasteSchematic(); + Bukkit.getScheduler().scheduleSyncDelayedTask(FightSystem.getPlugin(), () -> WinconditionTechKO.addWater(), 20*10L); } } diff --git a/src/me/yaruma/fightsystem/listener/PlayerQuitListener.java b/src/me/yaruma/fightsystem/listener/PlayerQuitListener.java index 47d1c32..d46671b 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerQuitListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerQuitListener.java @@ -2,21 +2,18 @@ package me.yaruma.fightsystem.listener; import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.fight.Fight; -import me.yaruma.fightsystem.fight.FightPlayer; import me.yaruma.fightsystem.fight.FightState; import me.yaruma.fightsystem.fight.FightTeam; -import me.yaruma.fightsystem.utils.Config; -import me.yaruma.fightsystem.utils.countdown.Countdown; -import me.yaruma.fightsystem.utils.countdown.FinishNoPlayersOnline; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; public class PlayerQuitListener implements Listener { - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void handlePlayerQuit(PlayerQuitEvent event) { event.setQuitMessage(null); @@ -25,51 +22,21 @@ public class PlayerQuitListener implements Listener { FightTeam fightTeam = Fight.getPlayerTeam(player); FightState fightState = FightSystem.getPlugin().getFightState(); - if(!fightTeam.getFightPlayer(player).isLeader()) { - if(fightState == FightState.PRE_RUNNING - || fightState == FightState.RUNNING) { - fightTeam.getFightPlayer(player).setOut(true); - } else if(fightState == FightState.SETUP) { - fightTeam.removePlayer(player); - } - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler §6" + player.getName() + " §chat den Kampf verlassen!"); - } else { - if(fightState == FightState.SETUP) { - fightTeam.removePlayer(player); + if(fightState == FightState.SETUP){ + fightTeam.removePlayer(player); + + if(fightTeam.isPlayerLeader(player)){ if(!fightTeam.getPlayers().isEmpty()) { fightTeam.setLeader(fightTeam.getPlayers().get(0)); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightTeam.getLeader().getPlayer().getDisplayName() + " §aist nun Leader von Team " + (fightTeam.getName() == Fight.getRedTeam().getName() ? - Config.TeamRedPrefix + Config.TeamRedName : Config.TeamBluePrefix + Config.TeamBlueName + "§a!")); - } else { - for(Player players : Bukkit.getServer().getOnlinePlayers()) { - if(Fight.getPlayerTeam(players) == null) { - if(fightTeam.getLeader() == null) { - FightPlayer fightPlayer = new FightPlayer(players, false); - fightTeam.setLeader(fightPlayer); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightTeam.getLeader().getPlayer().getDisplayName() + " §aist nun Leader von Team " + (fightTeam.getName() == Fight.getRedTeam().getName() ? - Config.TeamRedPrefix + Config.TeamRedName : Config.TeamBluePrefix + Config.TeamBlueName + "§a!")); - } - } - } - - if(fightTeam.getLeader() == null) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Es gibt keine Spieler mehr die den Leader ersetzen können! \n Server stoppt..."); - Bukkit.shutdown(); - } + Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightTeam.getLeader().getPlayer().getName() + " §aist nun Leader von Team " + fightTeam.getName() + "§a!"); + }else{ + Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Team " + fightTeam.getName() + " hat keine Spieler mehr.\n Server stoppt..."); + Bukkit.shutdown(); } - } else if(fightState == FightState.PRE_RUNNING || fightState == FightState.RUNNING) { - fightTeam.getFightPlayer(player).setOut(true); - if(!Config.AllDead && !Config.CaptainDead) - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler §6" + player.getName() + " §chat den Kampf verlassen!"); } - } - - if(fightTeam.getPlayers().isEmpty() && FightSystem.getPlugin().getFightState() == FightState.SETUP) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cAlle Spieler aus dem Team " + fightTeam.getName() + " §chaben den Kampf verlassen!"); - Countdown countdown = new Countdown(30, new FinishNoPlayersOnline()); - countdown.startTimer(FightSystem.getPlugin()); + }else if(fightState == FightState.PRE_RUNNING || fightState == FightState.RUNNING){ + fightTeam.getFightPlayer(player).setOut(true); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler §6" + player.getName() + " §chat den Kampf verlassen!"); } } - - -} +} \ No newline at end of file diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java b/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java index 578b38e..b6ad22f 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java @@ -62,18 +62,19 @@ public class WinconditionTechKO { if(teamRedWater.isEmpty()) { Bukkit.getScheduler().cancelTask(taskID); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + Config.TeamRedPrefix + Config.TeamRedName + " §6ist Tech K.O. !"); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + Config.TeamRedPrefix + Config.TeamRedName + " §6ist Tech K.O.!"); FightSystem.getPlugin().setSpectateState(Fight.getBlueTeam()); FightSystem.getPlugin().getWaterRemover().stop(); } else if(teamBlueWater.isEmpty()) { Bukkit.getScheduler().cancelTask(taskID); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + Config.TeamBluePrefix + Config.TeamBlueName + " §6ist Tech K.O. !"); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + Config.TeamBluePrefix + Config.TeamBlueName + " §6ist Tech K.O.!"); FightSystem.getPlugin().setSpectateState(Fight.getRedTeam()); FightSystem.getPlugin().getWaterRemover().stop(); } } public static void removeWater() { + if(!Config.TechKO) return; //Team Red Iterator itrRed = teamRedWater.iterator(); @@ -85,7 +86,7 @@ public class WinconditionTechKO { } if(teamRedWater.isEmpty()) { Bukkit.getScheduler().cancelTask(taskID); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + Config.TeamRedPrefix + Config.TeamRedName + " §6ist Tech K.O. !"); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + Config.TeamRedPrefix + Config.TeamRedName + " §6ist Tech K.O.!"); FightSystem.getPlugin().setSpectateState(Fight.getBlueTeam()); FightSystem.getPlugin().getWaterRemover().stop(); } @@ -100,7 +101,7 @@ public class WinconditionTechKO { } if(teamBlueWater.isEmpty()) { Bukkit.getScheduler().cancelTask(taskID); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + Config.TeamBluePrefix + Config.TeamBlueName + " §6ist Tech K.O. !"); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + Config.TeamBluePrefix + Config.TeamBlueName + " §6ist Tech K.O.!"); FightSystem.getPlugin().setSpectateState(Fight.getRedTeam()); FightSystem.getPlugin().getWaterRemover().stop(); } @@ -108,12 +109,7 @@ public class WinconditionTechKO { public static void startAutoChecker() { if(!Config.TechKO) return; - taskID = Bukkit.getScheduler().scheduleAsyncRepeatingTask(FightSystem.getPlugin(), new Runnable() { - @Override - public void run() { - addWater(); - } - }, 0, 20*20); + taskID = Bukkit.getScheduler().scheduleAsyncRepeatingTask(FightSystem.getPlugin(), () -> addWater(), 0, 20*20); } }