From fce272f366f0f29b60bbaf6de776666925ebf75a Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sat, 11 Jan 2020 17:31:38 +0100 Subject: [PATCH] complete rework --- .../steamwar/scoreboard/SWScoreboard_10.java | 38 ++++++++++++++----- .../steamwar/scoreboard/SWScoreboard_12.java | 38 ++++++++++++++----- .../steamwar/scoreboard/SWScoreboard_14.java | 38 ++++++++++++++----- .../steamwar/scoreboard/SWScoreboard_15.java | 34 +++++++++++++---- .../steamwar/scoreboard/SWScoreboard_8.java | 38 ++++++++++++++----- .../steamwar/scoreboard/SWScoreboard_9.java | 38 ++++++++++++++----- .../de/steamwar/scoreboard/SWScoreboard.java | 29 ++++++++++---- 7 files changed, 188 insertions(+), 65 deletions(-) diff --git a/SpigotCore_10/src/de/steamwar/scoreboard/SWScoreboard_10.java b/SpigotCore_10/src/de/steamwar/scoreboard/SWScoreboard_10.java index cb37c31..d4c44fd 100644 --- a/SpigotCore_10/src/de/steamwar/scoreboard/SWScoreboard_10.java +++ b/SpigotCore_10/src/de/steamwar/scoreboard/SWScoreboard_10.java @@ -4,6 +4,8 @@ import net.minecraft.server.v1_10_R1.*; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class SWScoreboard_10 { @@ -11,32 +13,42 @@ public class SWScoreboard_10 { ScoreboardCallback callback; private Scoreboard scoreboard; private ScoreboardObjective obj; + private int switcher; public SWScoreboard_10(ScoreboardCallback callback) { this.callback = callback; - this.scoreboard = new Scoreboard(); - this.obj = this.scoreboard.registerObjective("MainBord", IScoreboardCriteria.b); - obj.setDisplayName(this.callback.getTitle()); + this.switcher = 0; } public void sendScoreboard(Player player) { - PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1); - PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0); + //Komplett neues Scoreboard + this.scoreboard = new Scoreboard(); + this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.b); + obj.setDisplayName(this.callback.getTitle()); + switcher(); - sendPacket(player, removePacket); - sendPacket(player, createpacket); + //Packets senden + PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(obj, 1); + PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(obj, 0); + + List scores = new ArrayList<>(); for(Map.Entry currentEntry : this.callback.getData().entrySet()) { ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey()); score.setScore(currentEntry.getValue()); + scores.add(score); + } + + sendPacket(player, removePacket); + sendPacket(player, createpacket); + + for(ScoreboardScore score : scores) { PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(score); sendPacket(player, scorePacket); } - - display(player); } - private void display(Player player) { + public void display(Player player) { PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj); sendPacket(player, displayPacket); } @@ -50,5 +62,11 @@ public class SWScoreboard_10 { ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet); } + private void switcher() { + switcher++; + if(switcher > 1) + switcher = 0; + } + } diff --git a/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java b/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java index d8af5e2..fe5d0e9 100644 --- a/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java +++ b/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java @@ -4,6 +4,8 @@ import net.minecraft.server.v1_12_R1.*; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class SWScoreboard_12 { @@ -11,32 +13,42 @@ public class SWScoreboard_12 { ScoreboardCallback callback; private Scoreboard scoreboard; private ScoreboardObjective obj; + private int switcher; public SWScoreboard_12(ScoreboardCallback callback) { this.callback = callback; - this.scoreboard = new Scoreboard(); - this.obj = this.scoreboard.registerObjective("MainBord", IScoreboardCriteria.b); - obj.setDisplayName(this.callback.getTitle()); + this.switcher = 0; } public void sendScoreboard(Player player) { - PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1); - PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0); + //Komplett neues Scoreboard + this.scoreboard = new Scoreboard(); + this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.b); + obj.setDisplayName(this.callback.getTitle()); + switcher(); - sendPacket(player, removePacket); - sendPacket(player, createpacket); + //Packets senden + PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(obj, 1); + PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(obj, 0); + + List scores = new ArrayList<>(); for(Map.Entry currentEntry : this.callback.getData().entrySet()) { ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey()); score.setScore(currentEntry.getValue()); + scores.add(score); + } + + sendPacket(player, removePacket); + sendPacket(player, createpacket); + + for(ScoreboardScore score : scores) { PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(score); sendPacket(player, scorePacket); } - - display(player); } - private void display(Player player) { + public void display(Player player) { PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj); sendPacket(player, displayPacket); } @@ -50,4 +62,10 @@ public class SWScoreboard_12 { ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet); } + private void switcher() { + switcher++; + if(switcher > 1) + switcher = 0; + } + } diff --git a/SpigotCore_14/src/de/steamwar/scoreboard/SWScoreboard_14.java b/SpigotCore_14/src/de/steamwar/scoreboard/SWScoreboard_14.java index 7054a1c..ef7f332 100644 --- a/SpigotCore_14/src/de/steamwar/scoreboard/SWScoreboard_14.java +++ b/SpigotCore_14/src/de/steamwar/scoreboard/SWScoreboard_14.java @@ -4,6 +4,8 @@ import net.minecraft.server.v1_14_R1.*; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class SWScoreboard_14 { @@ -11,32 +13,42 @@ public class SWScoreboard_14 { ScoreboardCallback callback; private Scoreboard scoreboard; private ScoreboardObjective obj; + private int switcher; public SWScoreboard_14(ScoreboardCallback callback) { this.callback = callback; - this.scoreboard = new Scoreboard(); - this.obj = this.scoreboard.registerObjective("MainBord", IScoreboardCriteria.DUMMY, new ChatMessage("USELESS"), IScoreboardCriteria.EnumScoreboardHealthDisplay.HEARTS); - obj.setDisplayName(new ChatMessage(this.callback.getTitle())); + this.switcher = 0; } public void sendScoreboard(Player player) { - PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1); - PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0); + //Komplett neues Scoreboard + this.scoreboard = new Scoreboard(); + this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.DUMMY, new ChatMessage("USELESS"), IScoreboardCriteria.EnumScoreboardHealthDisplay.HEARTS); + obj.setDisplayName(new ChatMessage(this.callback.getTitle())); + switcher(); - sendPacket(player, removePacket); - sendPacket(player, createpacket); + //Packets senden + PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(obj, 1); + PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(obj, 0); + + List scores = new ArrayList<>(); for(Map.Entry currentEntry : this.callback.getData().entrySet()) { ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey()); score.setScore(currentEntry.getValue()); + scores.add(score); + } + + sendPacket(player, removePacket); + sendPacket(player, createpacket); + + for(ScoreboardScore score : scores) { PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(ScoreboardServer.Action.CHANGE, this.obj.getName(), score.getPlayerName(), score.getScore()); sendPacket(player, scorePacket); } - - display(player); } - private void display(Player player) { + public void display(Player player) { PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj); sendPacket(player, displayPacket); } @@ -50,4 +62,10 @@ public class SWScoreboard_14 { ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet); } + private void switcher() { + switcher++; + if(switcher > 1) + switcher = 0; + } + } diff --git a/SpigotCore_15/src/de/steamwar/scoreboard/SWScoreboard_15.java b/SpigotCore_15/src/de/steamwar/scoreboard/SWScoreboard_15.java index f752367..4fa0b09 100644 --- a/SpigotCore_15/src/de/steamwar/scoreboard/SWScoreboard_15.java +++ b/SpigotCore_15/src/de/steamwar/scoreboard/SWScoreboard_15.java @@ -4,6 +4,8 @@ import net.minecraft.server.v1_15_R1.*; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class SWScoreboard_15 { @@ -11,32 +13,42 @@ public class SWScoreboard_15 { ScoreboardCallback callback; private Scoreboard scoreboard; private ScoreboardObjective obj; + private int switcher; public SWScoreboard_15(ScoreboardCallback callback) { this.callback = callback; - this.scoreboard = new Scoreboard(); - this.obj = this.scoreboard.registerObjective("MainBord", IScoreboardCriteria.DUMMY, new ChatMessage("USELESS"), IScoreboardCriteria.EnumScoreboardHealthDisplay.HEARTS); - obj.setDisplayName(new ChatMessage(this.callback.getTitle())); + this.switcher = 0; } public void sendScoreboard(Player player) { + //Komplett neues Scoreboard + this.scoreboard = new Scoreboard(); + this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.DUMMY, new ChatMessage("USELESS"), IScoreboardCriteria.EnumScoreboardHealthDisplay.HEARTS); + obj.setDisplayName(new ChatMessage(this.callback.getTitle())); + switcher(); + + //Packets senden PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(obj, 1); PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(obj, 0); - sendPacket(player, removePacket); - sendPacket(player, createpacket); + List scores = new ArrayList<>(); for(Map.Entry currentEntry : this.callback.getData().entrySet()) { ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey()); score.setScore(currentEntry.getValue()); + scores.add(score); + } + + sendPacket(player, removePacket); + sendPacket(player, createpacket); + + for(ScoreboardScore score : scores) { PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(ScoreboardServer.Action.CHANGE, this.obj.getName(), score.getPlayerName(), score.getScore()); sendPacket(player, scorePacket); } - - display(player); } - private void display(Player player) { + public void display(Player player) { PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj); sendPacket(player, displayPacket); } @@ -50,4 +62,10 @@ public class SWScoreboard_15 { ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet); } + private void switcher() { + switcher++; + if(switcher > 1) + switcher = 0; + } + } diff --git a/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java b/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java index 672aacf..23f2b04 100644 --- a/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java +++ b/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java @@ -4,6 +4,8 @@ import net.minecraft.server.v1_8_R3.*; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class SWScoreboard_8 { @@ -11,32 +13,42 @@ public class SWScoreboard_8 { ScoreboardCallback callback; private Scoreboard scoreboard; private ScoreboardObjective obj; + private int switcher; public SWScoreboard_8(ScoreboardCallback callback) { this.callback = callback; - this.scoreboard = new Scoreboard(); - this.obj = this.scoreboard.registerObjective("MainBord", IScoreboardCriteria.b); - obj.setDisplayName(this.callback.getTitle()); + this.switcher = 0; } public void sendScoreboard(Player player) { - PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1); - PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0); + //Komplett neues Scoreboard + this.scoreboard = new Scoreboard(); + this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.b); + obj.setDisplayName(this.callback.getTitle()); + switcher(); - sendPacket(player, removePacket); - sendPacket(player, createpacket); + //Packets senden + PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(obj, 1); + PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(obj, 0); + + List scores = new ArrayList<>(); for(Map.Entry currentEntry : this.callback.getData().entrySet()) { ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey()); score.setScore(currentEntry.getValue()); + scores.add(score); + } + + sendPacket(player, removePacket); + sendPacket(player, createpacket); + + for(ScoreboardScore score : scores) { PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(score); sendPacket(player, scorePacket); } - - display(player); } - private void display(Player player) { + public void display(Player player) { PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj); sendPacket(player, displayPacket); } @@ -50,4 +62,10 @@ public class SWScoreboard_8 { ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet); } + private void switcher() { + switcher++; + if(switcher > 1) + switcher = 0; + } + } diff --git a/SpigotCore_9/src/de/steamwar/scoreboard/SWScoreboard_9.java b/SpigotCore_9/src/de/steamwar/scoreboard/SWScoreboard_9.java index 41a713e..0fd381c 100644 --- a/SpigotCore_9/src/de/steamwar/scoreboard/SWScoreboard_9.java +++ b/SpigotCore_9/src/de/steamwar/scoreboard/SWScoreboard_9.java @@ -4,6 +4,8 @@ import net.minecraft.server.v1_9_R2.*; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class SWScoreboard_9 { @@ -11,32 +13,42 @@ public class SWScoreboard_9 { ScoreboardCallback callback; private Scoreboard scoreboard; private ScoreboardObjective obj; + private int switcher; public SWScoreboard_9(ScoreboardCallback callback) { this.callback = callback; - this.scoreboard = new Scoreboard(); - this.obj = this.scoreboard.registerObjective("MainBord", IScoreboardCriteria.b); - obj.setDisplayName(this.callback.getTitle()); + this.switcher = 0; } public void sendScoreboard(Player player) { - PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(this.obj, 1); - PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(this.obj, 0); + //Komplett neues Scoreboard + this.scoreboard = new Scoreboard(); + this.obj = this.scoreboard.registerObjective("MainBord" + switcher, IScoreboardCriteria.b); + obj.setDisplayName(this.callback.getTitle()); + switcher(); - sendPacket(player, removePacket); - sendPacket(player, createpacket); + //Packets senden + PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(obj, 1); + PacketPlayOutScoreboardObjective createpacket = new PacketPlayOutScoreboardObjective(obj, 0); + + List scores = new ArrayList<>(); for(Map.Entry currentEntry : this.callback.getData().entrySet()) { ScoreboardScore score = new ScoreboardScore(this.scoreboard, this.obj, currentEntry.getKey()); score.setScore(currentEntry.getValue()); + scores.add(score); + } + + sendPacket(player, removePacket); + sendPacket(player, createpacket); + + for(ScoreboardScore score : scores) { PacketPlayOutScoreboardScore scorePacket = new PacketPlayOutScoreboardScore(score); sendPacket(player, scorePacket); } - - display(player); } - private void display(Player player) { + public void display(Player player) { PacketPlayOutScoreboardDisplayObjective displayPacket = new PacketPlayOutScoreboardDisplayObjective(1, this.obj); sendPacket(player, displayPacket); } @@ -50,4 +62,10 @@ public class SWScoreboard_9 { ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet); } + private void switcher() { + switcher++; + if(switcher > 1) + switcher = 0; + } + } diff --git a/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java b/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java index bbe6ed2..223f0b2 100644 --- a/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java +++ b/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java @@ -45,6 +45,10 @@ public class SWScoreboard { if(!playerBoards.containsKey(player)) return false; + playerBoards.remove(player); + if(player == null) + return true; + switch (Core.getVersion()) { case 8: ((SWScoreboard_8) playerBoards.get(player)).deleteScoreboard(player); @@ -67,7 +71,6 @@ public class SWScoreboard { default: return false; } - playerBoards.remove(player); return true; } @@ -78,22 +81,34 @@ public class SWScoreboard { for(Map.Entry entry : playerBoards.entrySet()) { switch (Core.getVersion()) { case 8: - ((SWScoreboard_8) entry.getValue()).sendScoreboard(entry.getKey()); + SWScoreboard_8 swScoreboard_8 = (SWScoreboard_8) entry.getValue(); + swScoreboard_8.sendScoreboard(entry.getKey()); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> swScoreboard_8.display(entry.getKey()), 2); break; case 9: - ((SWScoreboard_9) entry.getValue()).sendScoreboard(entry.getKey()); + SWScoreboard_9 swScoreboard_9 = (SWScoreboard_9) entry.getValue(); + swScoreboard_9.sendScoreboard(entry.getKey()); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> swScoreboard_9.display(entry.getKey()), 2); break; case 10: - ((SWScoreboard_10) entry.getValue()).sendScoreboard(entry.getKey()); + SWScoreboard_10 swScoreboard_10 = (SWScoreboard_10) entry.getValue(); + swScoreboard_10.sendScoreboard(entry.getKey()); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> swScoreboard_10.display(entry.getKey()), 2); break; case 12: - ((SWScoreboard_12) entry.getValue()).sendScoreboard(entry.getKey()); + SWScoreboard_12 swScoreboard_12 = (SWScoreboard_12) entry.getValue(); + swScoreboard_12.sendScoreboard(entry.getKey()); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> swScoreboard_12.display(entry.getKey()), 2); break; case 14: - ((SWScoreboard_14) entry.getValue()).sendScoreboard(entry.getKey()); + SWScoreboard_14 swScoreboard_14 = (SWScoreboard_14) entry.getValue(); + swScoreboard_14.sendScoreboard(entry.getKey()); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> swScoreboard_14.display(entry.getKey()), 2); break; case 15: - ((SWScoreboard_15) entry.getValue()).sendScoreboard(entry.getKey()); + SWScoreboard_15 swScoreboard_15 = (SWScoreboard_15) entry.getValue(); + swScoreboard_15.sendScoreboard(entry.getKey()); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> swScoreboard_15.display(entry.getKey()), 2); break; } }