From 0657ac404b39d049668c782886fd77750e438ea6 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Tue, 7 Jan 2020 23:22:31 +0100 Subject: [PATCH 1/5] added scoreboard --- .gitignore | 3 +- .../src/de/steamwar/bausystem/BauSystem.java | 4 +- .../bausystem/world/BauScoreboard.java | 42 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java diff --git a/.gitignore b/.gitignore index 7eae63f..02142ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea target -dependency-reduced-pom.xml \ No newline at end of file +dependency-reduced-pom.xml +*.iml \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 7054767..d67bbf3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.commands.*; import de.steamwar.bausystem.world.ArenaSection; +import de.steamwar.bausystem.world.BauScoreboard; import de.steamwar.bausystem.world.RegionListener; import de.steamwar.bausystem.world.TNTListener; import de.steamwar.core.CommandRemover; @@ -83,6 +84,7 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new TNTListener(), this); + Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); } public static BauSystem getPlugin(){ @@ -114,7 +116,7 @@ public class BauSystem extends JavaPlugin implements Listener { } @EventHandler - public void onLeave(PlayerQuitEvent e){ + public void onLeave(PlayerQuitEvent e) { if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(e.getPlayer()))) Bukkit.shutdown(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java new file mode 100644 index 0000000..4adc7f1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -0,0 +1,42 @@ +package de.steamwar.bausystem.world; + +import de.steamwar.bausystem.commands.CommandFreeze; +import de.steamwar.bausystem.commands.CommandTNT; +import de.steamwar.scoreboard.SWScoreboard; +import de.steamwar.scoreboard.ScoreboardCallback; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.HashMap; + +public class BauScoreboard implements Listener { + + @EventHandler + public void handlePlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + SWScoreboard.createScoreboard(player, new ScoreboardCallback() { + @Override + public HashMap getData() { + HashMap data = new HashMap<>(); + data.put("§1 ", 5); + data.put("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()), 4); + data.put("§2 ", 3); + data.put("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"), 2); + data.put("§eFreeze§8: " + (!CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"), 1); + return data; + } + + @Override + public String getTitle() { + return "§eSteam§8War"; + } + }); + } + + +} From 3fdb9072f8b39868ec72122ccacdb5ea041b52ea Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Wed, 8 Jan 2020 23:50:07 +0100 Subject: [PATCH 2/5] hotfix --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index d67bbf3..cd4ccb3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -6,6 +6,7 @@ import de.steamwar.bausystem.world.BauScoreboard; import de.steamwar.bausystem.world.RegionListener; import de.steamwar.bausystem.world.TNTListener; import de.steamwar.core.CommandRemover; +import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.configuration.InvalidConfigurationException; @@ -117,6 +118,7 @@ public class BauSystem extends JavaPlugin implements Listener { @EventHandler public void onLeave(PlayerQuitEvent e) { + SWScoreboard.removeScoreboard(e.getPlayer()); if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(e.getPlayer()))) Bukkit.shutdown(); } From fc14d83754e5bd5edb6673420a032e54a8c41d17 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sat, 11 Jan 2020 12:48:45 +0100 Subject: [PATCH 3/5] added tps --- .../bausystem/commands/CommandInfo.java | 22 ++++++++++++++----- .../bausystem/world/BauScoreboard.java | 3 +++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index db20493..aed3ced 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -31,19 +31,29 @@ public class CommandInfo implements CommandExecutor { } sender.sendMessage(membermessage.toString()); + StringBuilder tpsmessage = new StringBuilder().append(BauSystem.PREFIX).append("TPS:§e"); + for(float tps : getTps()){ + tpsmessage.append(tps); + } + sender.sendMessage(tpsmessage.toString()); + return false; + } + + public static float[] getTps() { double[] tps; - switch(Core.getVersion()){ + + switch (Core.getVersion()) { case 15: tps = CommandInfo_15.getTps(); break; default: tps = CommandInfo_12.getTps(); } - StringBuilder tpsmessage = new StringBuilder().append(BauSystem.PREFIX).append("TPS:§e"); - for(double t : tps){ - tpsmessage.append(String.format(" %.1f", t)); + + float[] roundedTps = new float[3]; + for(int i = 0; i < tps.length; i++) { + roundedTps[i] = Float.parseFloat(String.format("%.1f", tps[0])); } - sender.sendMessage(tpsmessage.toString()); - return false; + return roundedTps; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 4adc7f1..48e30a9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -1,6 +1,7 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.commands.CommandFreeze; +import de.steamwar.bausystem.commands.CommandInfo; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; @@ -28,6 +29,8 @@ public class BauScoreboard implements Listener { data.put("§2 ", 3); data.put("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"), 2); data.put("§eFreeze§8: " + (!CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"), 1); + data.put("§3 ", 2); + data.put("§eTPS§8: " + CommandInfo.getTps()[0], 1); return data; } From 43e40665d3afa1518fe99736175235e5f97fab23 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sat, 11 Jan 2020 21:38:34 +0100 Subject: [PATCH 4/5] hotfix --- .../src/de/steamwar/bausystem/world/BauScoreboard.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 48e30a9..683fc09 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -24,11 +24,11 @@ public class BauScoreboard implements Listener { @Override public HashMap getData() { HashMap data = new HashMap<>(); - data.put("§1 ", 5); - data.put("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()), 4); - data.put("§2 ", 3); - data.put("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"), 2); - data.put("§eFreeze§8: " + (!CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"), 1); + data.put("§1 ", 7); + data.put("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()), 6); + data.put("§2 ", 5); + data.put("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"), 4); + data.put("§eFreeze§8: " + (!CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"), 3); data.put("§3 ", 2); data.put("§eTPS§8: " + CommandInfo.getTps()[0], 1); return data; From a27344af1c3a5e6d927ab275628f91f59ad4add6 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sun, 12 Jan 2020 15:31:27 +0100 Subject: [PATCH 5/5] hotfix and code cleanup --- .../src/de/steamwar/bausystem/commands/CommandInfo.java | 4 ++-- .../src/de/steamwar/bausystem/world/BauScoreboard.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index aed3ced..9555a61 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -33,7 +33,7 @@ public class CommandInfo implements CommandExecutor { StringBuilder tpsmessage = new StringBuilder().append(BauSystem.PREFIX).append("TPS:§e"); for(float tps : getTps()){ - tpsmessage.append(tps); + tpsmessage.append(" " + tps); } sender.sendMessage(tpsmessage.toString()); return false; @@ -52,7 +52,7 @@ public class CommandInfo implements CommandExecutor { float[] roundedTps = new float[3]; for(int i = 0; i < tps.length; i++) { - roundedTps[i] = Float.parseFloat(String.format("%.1f", tps[0])); + roundedTps[i] = Math.round(tps[0]); } return roundedTps; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 683fc09..4618077 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -30,7 +30,7 @@ public class BauScoreboard implements Listener { data.put("§eTNT§8: " + (!CommandTNT.getInstance().isOn() ? "§aan" : "§caus"), 4); data.put("§eFreeze§8: " + (!CommandFreeze.getInstance().isOn() ? "§aan" : "§caus"), 3); data.put("§3 ", 2); - data.put("§eTPS§8: " + CommandInfo.getTps()[0], 1); + data.put("§eTPS§8: §7" + CommandInfo.getTps()[0], 1); return data; }