From 2a8859ed56db61e2a270bcca3d90212d47d0463f Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 30 Jan 2021 13:49:01 +0100 Subject: [PATCH] Add PlayTime to FightScoreboard --- .../steamwar/misslewars/FightScoreboard.java | 19 ++++++++++++++++++- .../steamwar/misslewars/StateDependent.java | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/misslewars/FightScoreboard.java b/src/de/steamwar/misslewars/FightScoreboard.java index 89a6f8d..768f334 100644 --- a/src/de/steamwar/misslewars/FightScoreboard.java +++ b/src/de/steamwar/misslewars/FightScoreboard.java @@ -24,6 +24,8 @@ import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Objects; /** @@ -35,6 +37,9 @@ class FightScoreboard { private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); private static final Objective objective; + private static final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); + + private static long startTime = 0; static{ if(scoreboard.getObjective("AAA") == null) @@ -48,8 +53,16 @@ class FightScoreboard { objective.unregister(); scoreboard.registerNewObjective("AAA", "BBB", "MissleWars"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); - objective.setDisplayName("§eSpieler"); + objective.setDisplayName("§eMissileWars"); + objective.getScore("§eSpielzeit").setScore(5); + if (startTime == 0) { + objective.getScore("§7??:??:??").setScore(4); + } else { + objective.getScore("§7" + format.format(new Date(System.currentTimeMillis() - startTime))).setScore(4); + } + objective.getScore("").setScore(3); + objective.getScore("§eSpieler").setScore(2); MissileWars.getBlueTeam().teamScoreboard(objective); MissileWars.getRedTeam().teamScoreboard(objective); @@ -61,4 +74,8 @@ class FightScoreboard { return scoreboard; } + static void startTime() { + startTime = System.currentTimeMillis(); + } + } diff --git a/src/de/steamwar/misslewars/StateDependent.java b/src/de/steamwar/misslewars/StateDependent.java index be9a5e7..155d824 100644 --- a/src/de/steamwar/misslewars/StateDependent.java +++ b/src/de/steamwar/misslewars/StateDependent.java @@ -38,6 +38,9 @@ public abstract class StateDependent { public abstract void disable(); static void setupState(FightState state){ + if (state == FightState.FIGHTING) { + FightScoreboard.startTime(); + } for(StateDependent listener : listeners){ if(listener.running && !listener.active.contains(state)){ listener.disable();