From 1acd3878f5ac295b5fb5c9cf5958e710c5d05af2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 6 Oct 2020 23:39:47 +0200 Subject: [PATCH 1/6] Changed Fight Scoreboard to SWScoreboard --- .../fightsystem/utils/FightScoreboard.java | 106 +++++++++++------- 1 file changed, 66 insertions(+), 40 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index 5d75181..acb8b6a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -25,13 +25,13 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.winconditions.*; +import de.steamwar.scoreboard.SWScoreboard; +import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.Bukkit; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; import java.util.EnumSet; -import java.util.Objects; +import java.util.HashMap; import java.util.Set; public class FightScoreboard { @@ -39,85 +39,111 @@ public class FightScoreboard { private FightScoreboard(){} private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); - private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); - private static final Objective objective; private static int index = 0; - static{ - if(scoreboard.getObjective("AAA") == null) - //noinspection deprecation - objective = scoreboard.registerNewObjective("AAA", "BBB"); - else - objective = scoreboard.getObjective("AAA"); - } - public static void init(){ Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> { - objective.unregister(); - //noinspection deprecation - scoreboard.registerNewObjective("AAA", "BBB"); - objective.setDisplaySlot(DisplaySlot.SIDEBAR); + Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.removeScoreboard(player)); FightTeam fightTeam = getIndexDisplay(); + ScoreBoardObjective objective; if(fightTeam != null) - teamScoreboard(fightTeam); + objective = teamScoreboard(fightTeam); else - generalScoreboard(); + objective = generalScoreboard(); - Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard)); + Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.createScoreboard(player, new ScoreboardCallback() { + @Override + public HashMap getData() { + return objective.getScores(); + } + + @Override + public String getTitle() { + return objective.getTitle(); + } + })); }, 0, 200); } public static Scoreboard getScoreboard() { - return scoreboard; + return Bukkit.getScoreboardManager().getMainScoreboard(); } - private static void teamScoreboard(FightTeam fightTeam){ - objective.setDisplayName(fightTeam.getColoredName()); + private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){ + ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName()); fightTeam.getPlayers().forEach(fp -> { if(fp.isLiving()) - objective.getScore(fightTeam.getPrefix() + fp.getPlayer().getName()).setScore((int) Math.ceil(fp.getPlayer().getHealth())); + objective.addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth())); }); + return objective; } - private static void generalScoreboard(){ - objective.setDisplayName("§6Kampf"); + private static ScoreBoardObjective generalScoreboard(){ + ScoreBoardObjective objective = new ScoreBoardObjective("§6Kampf"); if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { int fightTime = FightSystem.getFightTime(); if (fightTime >= 60) - objective.getScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s").setScore(3); + objective.addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 3); else - objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3); + objective.addScore("§7Zeit: §a" + fightTime + "s", 3); } if(fullScoreboard.contains(FightSystem.getFightState())){ if (Config.PercentSystem){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%").setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%").setScore(0); + objective.addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1); + objective.addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0); }else if(Config.WaterTechKO){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater()).setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater()).setScore(0); + objective.addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1); + objective.addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0); }else if(Config.RelativePercent){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%").setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%").setScore(0); + objective.addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1); + objective.addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0); }else if(Config.Points){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints()).setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints()).setScore(0); + objective.addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1); + objective.addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0); }else if(Config.PumpkinTechKO){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins()).setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins()).setScore(0); + objective.addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1); + objective.addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0); } } + return objective; } private static FightTeam getIndexDisplay() { - index++; if(index == 1) return Fight.redTeam; if(index == 2) return Fight.blueTeam; - index = 0; return null; } + private static void nextIndexDisplay() { + index++; + if(index > 2) + return; + index = 0; + } + + private static class ScoreBoardObjective { + + private final String title; + private HashMap scores = new HashMap<>(); + + public ScoreBoardObjective(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void addScore(String string, int i) { + scores.put(string, i); + } + + public HashMap getScores() { + return scores; + } + } } From e575d7a493339e5664b0fb94cd021eacd286a786 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 11 Oct 2020 10:22:07 +0200 Subject: [PATCH 2/6] Scoreboard Improvement --- .../fightsystem/utils/FightScoreboard.java | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index acb8b6a..d7e582a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -28,48 +28,50 @@ import de.steamwar.fightsystem.winconditions.*; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Scoreboard; import java.util.EnumSet; import java.util.HashMap; import java.util.Set; -public class FightScoreboard { - - private FightScoreboard(){} +public class FightScoreboard implements Listener { private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); private static int index = 0; + private static ScoreBoardObjective objective; public static void init(){ - Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> { - Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.removeScoreboard(player)); - - FightTeam fightTeam = getIndexDisplay(); - ScoreBoardObjective objective; - if(fightTeam != null) - objective = teamScoreboard(fightTeam); - else - objective = generalScoreboard(); - - Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.createScoreboard(player, new ScoreboardCallback() { - @Override - public HashMap getData() { - return objective.getScores(); - } - - @Override - public String getTitle() { - return objective.getTitle(); - } - })); - }, 0, 200); + Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> nextIndexDisplay(), 0, 200); } public static Scoreboard getScoreboard() { return Bukkit.getScoreboardManager().getMainScoreboard(); } + @EventHandler() + public void onPlayerJoin(PlayerJoinEvent event) { + SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() { + @Override + public HashMap getData() { + return objective.getScores(); + } + + @Override + public String getTitle() { + return objective.getTitle(); + } + }); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + SWScoreboard.removeScoreboard(event.getPlayer()); + } + private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){ ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName()); fightTeam.getPlayers().forEach(fp -> { @@ -123,6 +125,11 @@ public class FightScoreboard { if(index > 2) return; index = 0; + FightTeam team = getIndexDisplay(); + if(team != null) + objective = teamScoreboard(team); + else + objective = generalScoreboard(); } private static class ScoreBoardObjective { From 2bc9bded5c85d7a333a2c2abc98855f32a492cd6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 15 Oct 2020 13:14:34 +0200 Subject: [PATCH 3/6] Fixing Scoreboard --- .../fightsystem/utils/FightScoreboard.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index d7e582a..3cf6766 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -45,7 +45,7 @@ public class FightScoreboard implements Listener { private static ScoreBoardObjective objective; public static void init(){ - Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> nextIndexDisplay(), 0, 200); + Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200); } public static Scoreboard getScoreboard() { @@ -54,7 +54,7 @@ public class FightScoreboard implements Listener { @EventHandler() public void onPlayerJoin(PlayerJoinEvent event) { - SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() { + SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() { @Override public HashMap getData() { return objective.getScores(); @@ -73,7 +73,7 @@ public class FightScoreboard implements Listener { } private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){ - ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName()); + final ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName()); fightTeam.getPlayers().forEach(fp -> { if(fp.isLiving()) objective.addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth())); @@ -82,7 +82,7 @@ public class FightScoreboard implements Listener { } private static ScoreBoardObjective generalScoreboard(){ - ScoreBoardObjective objective = new ScoreBoardObjective("§6Kampf"); + final ScoreBoardObjective objective = new ScoreBoardObjective("§6Kampf"); if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { int fightTime = FightSystem.getFightTime(); if (fightTime >= 60) @@ -123,9 +123,8 @@ public class FightScoreboard implements Listener { private static void nextIndexDisplay() { index++; if(index > 2) - return; - index = 0; - FightTeam team = getIndexDisplay(); + index = 0; + final FightTeam team = getIndexDisplay(); if(team != null) objective = teamScoreboard(team); else @@ -135,7 +134,7 @@ public class FightScoreboard implements Listener { private static class ScoreBoardObjective { private final String title; - private HashMap scores = new HashMap<>(); + private final HashMap scores = new HashMap<>(); public ScoreBoardObjective(String title) { this.title = title; From 7dbd3ab5cbf80bcf09537464872a51efb589cb50 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 16 Nov 2020 21:31:03 +0100 Subject: [PATCH 4/6] Fixing Scoreboard --- .../fightsystem/utils/FightScoreboard.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index 7f628ae..c99de72 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -24,7 +24,6 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.scoreboard.SWScoreboard; @@ -47,6 +46,7 @@ public class FightScoreboard implements Listener { private static ScoreBoardObjective objective; public static void init(){ + Bukkit.getPluginManager().registerEvents(new FightScoreboard(), FightSystem.getPlugin()); Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200); } @@ -88,12 +88,12 @@ public class FightScoreboard implements Listener { if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { int fightTime = FightSystem.getFightTime(); if (fightTime >= 60) - objective.addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 3); + objective.addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4); else - objective.addScore("§7Zeit: §a" + fightTime + "s", 3); + objective.addScore("§7Zeit: §a" + fightTime + "s", 4); } - setScore("§7TPS: §e" + TPSWatcher.getTPS(), 3); + objective.addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3); if(fullScoreboard.contains(FightSystem.getFightState())){ if (Config.PercentSystem){ @@ -116,12 +116,6 @@ public class FightScoreboard implements Listener { return objective; } - private static void setScore(String key, int value){ - objective.getScore(key).setScore(value); - if(Config.recording()) - RecordSystem.scoreboardData(key, value); - } - private static FightTeam getIndexDisplay() { if(index == 1) return Fight.redTeam; From 26e71da87a6e2ccbdff18a1d31ea0c0c945c0e1b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 16 Nov 2020 21:36:28 +0100 Subject: [PATCH 5/6] Add Record System --- .../steamwar/fightsystem/utils/FightScoreboard.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index c99de72..ee634a0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.scoreboard.SWScoreboard; @@ -59,6 +60,8 @@ public class FightScoreboard implements Listener { SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() { @Override public HashMap getData() { + + return objective.getScores(); } @@ -85,6 +88,8 @@ public class FightScoreboard implements Listener { private static ScoreBoardObjective generalScoreboard(){ final ScoreBoardObjective objective = new ScoreBoardObjective("§6Kampf"); + if(Config.recording()) + RecordSystem.scoreboardTitle(objective.getTitle()); if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { int fightTime = FightSystem.getFightTime(); if (fightTime >= 60) @@ -113,6 +118,8 @@ public class FightScoreboard implements Listener { objective.addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0); } } + if(Config.recording()) + objective.scores.forEach(RecordSystem::scoreboardData); return objective; } @@ -141,6 +148,8 @@ public class FightScoreboard implements Listener { private final HashMap scores = new HashMap<>(); public ScoreBoardObjective(String title) { + if(Config.recording()) + RecordSystem.scoreboardTitle(title); this.title = title; } @@ -149,6 +158,8 @@ public class FightScoreboard implements Listener { } public void addScore(String string, int i) { + if(Config.recording()) + RecordSystem.scoreboardData(string, i); scores.put(string, i); } From e460b04a678b99c9158dbaa61eb0c6115b999abf Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 17 Nov 2020 08:58:50 +0100 Subject: [PATCH 6/6] Fixing... --- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../listener/ScoreboardListener.java | 26 ++++ .../fightsystem/utils/FightScoreboard.java | 117 +++++++----------- 3 files changed, 69 insertions(+), 75 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/ScoreboardListener.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 8ad4146..9ddb221 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -102,6 +102,7 @@ public class FightSystem extends JavaPlugin { new RankedJoinListener(); new GameplayListener(); new PersonalKitCreator(); + new ScoreboardListener(); if(Core.getVersion() > 8) new VersionDependentListener(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ScoreboardListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ScoreboardListener.java new file mode 100644 index 0000000..49722fd --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ScoreboardListener.java @@ -0,0 +1,26 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.utils.FightScoreboard; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.EnumSet; + +public class ScoreboardListener extends BasicListener { + + public ScoreboardListener() { + super(EnumSet.allOf(FightState.class)); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + FightScoreboard.showScoreboard(event.getPlayer()); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + FightScoreboard.removeScoreboard(event.getPlayer()); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index ee634a0..8ceb2be 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -30,24 +30,21 @@ import de.steamwar.fightsystem.winconditions.*; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.entity.Player; import org.bukkit.scoreboard.Scoreboard; import java.util.EnumSet; import java.util.HashMap; import java.util.Set; -public class FightScoreboard implements Listener { +public class FightScoreboard { private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); private static int index = 0; - private static ScoreBoardObjective objective; + private static String title = ""; + private static HashMap scores; public static void init(){ - Bukkit.getPluginManager().registerEvents(new FightScoreboard(), FightSystem.getPlugin()); Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200); } @@ -55,116 +52,86 @@ public class FightScoreboard implements Listener { return Bukkit.getScoreboardManager().getMainScoreboard(); } - @EventHandler() - public void onPlayerJoin(PlayerJoinEvent event) { - SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() { + public static void showScoreboard(Player p) { + SWScoreboard.createScoreboard(p, new ScoreboardCallback() { @Override public HashMap getData() { - - - return objective.getScores(); + return scores; } @Override public String getTitle() { - return objective.getTitle(); + return title; } }); } - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - SWScoreboard.removeScoreboard(event.getPlayer()); + public static void removeScoreboard(Player p) { + SWScoreboard.removeScoreboard(p); } - private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){ - final ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName()); + private static void teamScoreboard(FightTeam fightTeam){ + title = fightTeam.getColoredName(); + if(Config.recording()) + RecordSystem.scoreboardTitle(title); fightTeam.getPlayers().forEach(fp -> { if(fp.isLiving()) - objective.addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth())); + addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth())); }); - return objective; } - private static ScoreBoardObjective generalScoreboard(){ - final ScoreBoardObjective objective = new ScoreBoardObjective("§6Kampf"); + private static void generalScoreboard(){ + title = "§6Kampf"; if(Config.recording()) - RecordSystem.scoreboardTitle(objective.getTitle()); + RecordSystem.scoreboardTitle(title); if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { int fightTime = FightSystem.getFightTime(); if (fightTime >= 60) - objective.addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4); + addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4); else - objective.addScore("§7Zeit: §a" + fightTime + "s", 4); + addScore("§7Zeit: §a" + fightTime + "s", 4); } - objective.addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3); + addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3); if(fullScoreboard.contains(FightSystem.getFightState())){ if (Config.PercentSystem){ - objective.addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1); - objective.addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0); + addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1); + addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0); }else if(Config.WaterTechKO){ - objective.addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1); - objective.addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0); + addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1); + addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0); }else if(Config.RelativePercent){ - objective.addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1); - objective.addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0); + addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1); + addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0); }else if(Config.Points){ - objective.addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1); - objective.addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0); + addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1); + addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0); }else if(Config.PumpkinTechKO){ - objective.addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1); - objective.addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0); + addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1); + addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0); } } - if(Config.recording()) - objective.scores.forEach(RecordSystem::scoreboardData); - return objective; - } - - private static FightTeam getIndexDisplay() { - if(index == 1) - return Fight.redTeam; - if(index == 2) - return Fight.blueTeam; - return null; } private static void nextIndexDisplay() { index++; if(index > 2) index = 0; - final FightTeam team = getIndexDisplay(); + FightTeam team = null; + if(index == 1) + team = Fight.redTeam; + if(index == 2) + team = Fight.blueTeam; if(team != null) - objective = teamScoreboard(team); + teamScoreboard(team); else - objective = generalScoreboard(); + generalScoreboard(); } - private static class ScoreBoardObjective { - - private final String title; - private final HashMap scores = new HashMap<>(); - - public ScoreBoardObjective(String title) { - if(Config.recording()) - RecordSystem.scoreboardTitle(title); - this.title = title; - } - - public String getTitle() { - return title; - } - - public void addScore(String string, int i) { - if(Config.recording()) - RecordSystem.scoreboardData(string, i); - scores.put(string, i); - } - - public HashMap getScores() { - return scores; - } + private static void addScore(String string, int i) { + if(Config.recording()) + RecordSystem.scoreboardData(string, i); + scores.put(string, i); } }