diff --git a/src/me/yaruma/fightsystem/FightSystem.java b/src/me/yaruma/fightsystem/FightSystem.java index 87971dc..7552012 100644 --- a/src/me/yaruma/fightsystem/FightSystem.java +++ b/src/me/yaruma/fightsystem/FightSystem.java @@ -230,7 +230,7 @@ public class FightSystem extends JavaPlugin { if(this.fightState != FightState.SETUP) return; this.fightState = FightState.PRE_RUNNING; - Countdown.cancelAllTimers(plugin); + Countdown.cancelAllTimers(); int time = fileManager.getIntegerFromConfig("Times.PreFightDuration"); Countdown countdown = new Countdown(time, new FinishPreRunning()); @@ -259,7 +259,7 @@ public class FightSystem extends JavaPlugin { if(this.fightState != FightState.PRE_RUNNING) return; this.fightState = FightState.RUNNING; - Countdown.cancelAllTimers(plugin); + Countdown.cancelAllTimers(); setAllPlayersGM(GameMode.SURVIVAL); @@ -275,7 +275,7 @@ public class FightSystem extends JavaPlugin { if(this.fightState != FightState.RUNNING) return; this.fightState = FightState.SPECTATE; - Countdown.cancelAllTimers(plugin); + Countdown.cancelAllTimers(); setAllPlayersGM(GameMode.SPECTATOR); entern = true; @@ -305,7 +305,7 @@ public class FightSystem extends JavaPlugin { } Countdown cancelAllCountdowns = new Countdown(); - cancelAllCountdowns.cancelAllTimers(FightSystem.getPlugin()); + cancelAllCountdowns.cancelAllTimers(); Countdown countdown = new Countdown(20*60, new FinishSpectateOver()); countdown.startTimer(FightSystem.getPlugin()); } diff --git a/src/me/yaruma/fightsystem/listener/PlayerChatListener.java b/src/me/yaruma/fightsystem/listener/PlayerChatListener.java index f5a7009..2488f4d 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerChatListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerChatListener.java @@ -27,12 +27,12 @@ public class PlayerChatListener implements Listener { String prefixColorCode = fightTeam.getPrefix(); String teamName = fightTeam.getName(); if(message.startsWith(teamChatDetection)) { - fightTeam.broadcast(prefixColorCode + player.getName() + "» " + prefixColorCode + message); + fightTeam.broadcast(prefixColorCode + player.getName() + "» " + prefixColorCode + message.substring(1)); } else { Bukkit.broadcastMessage(prefixColorCode + teamName + " " + player.getName() + " §8» §7" + message); } }else{ - Bukkit.broadcastMessage("§7" + player.getName() + " §8» §7" + message.substring(1)); + Bukkit.broadcastMessage("§7" + player.getName() + " §8» §7" + message); } event.setCancelled(true); diff --git a/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java b/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java index 27eaa52..6e3cbb7 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerInteractListener.java @@ -51,7 +51,7 @@ public class PlayerInteractListener implements Listener { player.getInventory().clear(); if(Fight.getOpposite(fightTeam).getLeader().getPlayer() != null) Fight.getOpposite(fightTeam).getLeader().getPlayer().getInventory().clear(); - Countdown.cancelAllTimers(instance); + Countdown.cancelAllTimers(); Countdown countdown = new Countdown(30, new FinishNoPlayersOnline()); countdown.startTimer(instance); break; diff --git a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java index c498399..5207b38 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java +++ b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java @@ -8,6 +8,8 @@ import java.util.ArrayList; public class Countdown { + private static ArrayList countdowns = new ArrayList<>(); + private int time; private CountdownCallback countdownCallback; private int taskID; @@ -19,6 +21,7 @@ public class Countdown { public Countdown(int time, CountdownCallback countdownCallback) { this.time = time; this.countdownCallback = countdownCallback; + countdowns.add(this); if(countdownCallback == new FinishTimeOver()) FightSystem.getPlugin().fightTime = time; } @@ -49,11 +52,24 @@ public class Countdown { }, 0, 20); } - public void cancelTimer(int taskID) { - Bukkit.getScheduler().cancelTask(taskID); + public void cancelTimer() { + Bukkit.getScheduler().cancelTask(this.taskID); + countdowns.remove(this); } - public static void cancelAllTimers(FightSystem plugin) { - Bukkit.getScheduler().cancelTasks(plugin); + public static void cancelAllTimers() { + for(Countdown countdown : countdowns) { + countdown.cancelTimer(); + } + } + + public static void cancelTimerType(CountdownType countdownType) { + for(Countdown countdown : countdowns) { + if(countdown.getType() == countdownType) countdown.cancelTimer(); + } + } + + public CountdownType getType() { + return countdownCallback.getType(); } } diff --git a/src/me/yaruma/fightsystem/utils/countdown/CountdownCallback.java b/src/me/yaruma/fightsystem/utils/countdown/CountdownCallback.java index 0f4e733..766756f 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/CountdownCallback.java +++ b/src/me/yaruma/fightsystem/utils/countdown/CountdownCallback.java @@ -4,6 +4,7 @@ public interface CountdownCallback { String countdownCounting(); void countdownFinished(); + CountdownType getType(); } diff --git a/src/me/yaruma/fightsystem/utils/countdown/CountdownType.java b/src/me/yaruma/fightsystem/utils/countdown/CountdownType.java new file mode 100644 index 0000000..66489c5 --- /dev/null +++ b/src/me/yaruma/fightsystem/utils/countdown/CountdownType.java @@ -0,0 +1,13 @@ +package me.yaruma.fightsystem.utils.countdown; + +public enum CountdownType { + + NO_ENTERN, + NO_PLAYERS_ONLINE, + PRE_RUNNING, + SETUP_OVER, + SPECTATE_OVER, + TIME_OVER; + + +} diff --git a/src/me/yaruma/fightsystem/utils/countdown/FinishNoPlayersOnline.java b/src/me/yaruma/fightsystem/utils/countdown/FinishNoPlayersOnline.java index cc864d4..78defbf 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/FinishNoPlayersOnline.java +++ b/src/me/yaruma/fightsystem/utils/countdown/FinishNoPlayersOnline.java @@ -14,4 +14,9 @@ public class FinishNoPlayersOnline implements CountdownCallback { Bukkit.broadcastMessage("§aStoppe Server..."); Bukkit.getServer().shutdown(); } + + @Override + public CountdownType getType() { + return CountdownType.NO_PLAYERS_ONLINE; + } } diff --git a/src/me/yaruma/fightsystem/utils/countdown/FinishNoneEntern.java b/src/me/yaruma/fightsystem/utils/countdown/FinishNoneEntern.java index ebabd91..75c982d 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/FinishNoneEntern.java +++ b/src/me/yaruma/fightsystem/utils/countdown/FinishNoneEntern.java @@ -15,4 +15,9 @@ public class FinishNoneEntern implements CountdownCallback { FightSystem.getPlugin().entern = true; Bukkit.broadcastMessage("§aEntern ist nun erlaubt!"); } + + @Override + public CountdownType getType() { + return CountdownType.NO_ENTERN; + } } diff --git a/src/me/yaruma/fightsystem/utils/countdown/FinishPreRunning.java b/src/me/yaruma/fightsystem/utils/countdown/FinishPreRunning.java index 7563301..3831c29 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/FinishPreRunning.java +++ b/src/me/yaruma/fightsystem/utils/countdown/FinishPreRunning.java @@ -17,4 +17,9 @@ public class FinishPreRunning implements CountdownCallback { public void countdownFinished() { FightSystem.getPlugin().setRunningState(); } + + @Override + public CountdownType getType() { + return CountdownType.PRE_RUNNING; + } } diff --git a/src/me/yaruma/fightsystem/utils/countdown/FinishSetupOver.java b/src/me/yaruma/fightsystem/utils/countdown/FinishSetupOver.java index 4f2f0e5..411c9e6 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/FinishSetupOver.java +++ b/src/me/yaruma/fightsystem/utils/countdown/FinishSetupOver.java @@ -14,4 +14,9 @@ public class FinishSetupOver implements CountdownCallback { Bukkit.broadcastMessage("Fight wird abgebrochen! \n Stoppe Server..."); Bukkit.getServer().shutdown(); } + + @Override + public CountdownType getType() { + return CountdownType.SETUP_OVER; + } } diff --git a/src/me/yaruma/fightsystem/utils/countdown/FinishSpectateOver.java b/src/me/yaruma/fightsystem/utils/countdown/FinishSpectateOver.java index 2add84b..ed77a48 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/FinishSpectateOver.java +++ b/src/me/yaruma/fightsystem/utils/countdown/FinishSpectateOver.java @@ -14,4 +14,9 @@ public class FinishSpectateOver implements CountdownCallback { Bukkit.broadcastMessage("§aStoppe Server..."); Bukkit.getServer().shutdown(); } + + @Override + public CountdownType getType() { + return CountdownType.SPECTATE_OVER; + } } diff --git a/src/me/yaruma/fightsystem/utils/countdown/FinishTimeOver.java b/src/me/yaruma/fightsystem/utils/countdown/FinishTimeOver.java index fb6c4c3..1e284d5 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/FinishTimeOver.java +++ b/src/me/yaruma/fightsystem/utils/countdown/FinishTimeOver.java @@ -15,4 +15,9 @@ public class FinishTimeOver implements CountdownCallback { Bukkit.broadcastMessage("§aZeit abgelaufen!"); FightSystem.getPlugin().setSpectateState(null); } + + @Override + public CountdownType getType() { + return CountdownType.TIME_OVER; + } } diff --git a/src/me/yaruma/fightsystem/utils/scoreboard/Scoreboard.java b/src/me/yaruma/fightsystem/utils/scoreboard/Scoreboard.java index 29ff56e..a824af6 100644 --- a/src/me/yaruma/fightsystem/utils/scoreboard/Scoreboard.java +++ b/src/me/yaruma/fightsystem/utils/scoreboard/Scoreboard.java @@ -33,18 +33,22 @@ public class Scoreboard { public void run() { FightTeam fightTeam = getIndexDisplay(index); if(fightTeam != null) { + objective.unregister(); + scoreboard.registerNewObjective("AAA", "BBB"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); objective.setDisplayName("§6Info " + fightTeam.getPrefix() + fightTeam.getName()); for(FightPlayer fp : fightTeam.getPlayers()) { - objective.getScore(fightTeam.getPrefix() + fp.getPlayer().getDisplayName()).setScore(fp.getPlayer().getHealth()); + objective.getScore(fightTeam.getPrefix() + fp.getPlayer().getName()).setScore((int) fp.getPlayer().getHealth()); } - } else { - index = 0; + index++; - String gameName = FightSystem.getPlugin().getFileManager().getStringFromConfig("Output.GameName"); + } else { + + objective.unregister(); + scoreboard.registerNewObjective("AAA", "BBB"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); objective.setDisplayName("§6Fight Info"); @@ -54,7 +58,7 @@ public class Scoreboard { if(Methods.isEnabled("WinConditions.PercentSystem")) objective.getScore("§eSchaden BLAU: §c" + FightSystem.getPlugin().getGetDamageBlue() + "%").setScore(3); } player.setScoreboard(scoreboard); - index++; + index = 0; } }, 0, delay); }