From 39c6d04daf12dca0eafc9d758dad1289b0abd350 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 24 Nov 2019 21:51:39 +0100 Subject: [PATCH] added full multiversion support --- .../steamwar/scoreboard/SWScoreboard_12.java | 44 ++++++++++++++ .../steamwar/scoreboard/SWScoreboard_14.java | 44 ++++++++++++++ .../steamwar/scoreboard/SWScoreboard_8.java | 44 ++++++++++++++ .../de/steamwar/scoreboard/SWScoreboard.java | 58 +++++++++++++------ 4 files changed, 172 insertions(+), 18 deletions(-) create mode 100644 SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java create mode 100644 SpigotCore_14/src/de/steamwar/scoreboard/SWScoreboard_14.java create mode 100644 SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java diff --git a/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java b/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java new file mode 100644 index 0000000..1f4b8ef --- /dev/null +++ b/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java @@ -0,0 +1,44 @@ +package de.steamwar.scoreboard; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; + +public class SWScoreboard_12 { + + private SWScoreboard_12() {} + + static PacketContainer getRemovePacket() { + PacketContainer remove = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); + remove.getStrings().write(0, "AAA"); + remove.getBytes().write(0, (byte) 1); + return remove; + } + + static PacketContainer getCreatePacket(String title) { + PacketContainer createpacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); + createpacket.getStrings().write(0, "AAA"); + createpacket.getBytes().write(0, (byte) 0); + createpacket.getStrings().write(1, title); + createpacket.getStrings().write(2, "integer"); + return createpacket; + } + + static PacketContainer getUpdatePacket(String content, Integer line) { + PacketContainer update = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_SCORE); + update.getStrings().write(0, content); + update.getBytes().write(0, (byte) 0); + update.getStrings().write(1, "AAA"); + update.getIntegers().write(0, line); + return update; + } + + static PacketContainer getDisplayPacket(String title) { + PacketContainer display = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE); + display.getBytes().write(0, (byte) 1); + display.getStrings().write(0, title); + return display; + } + + +} diff --git a/SpigotCore_14/src/de/steamwar/scoreboard/SWScoreboard_14.java b/SpigotCore_14/src/de/steamwar/scoreboard/SWScoreboard_14.java new file mode 100644 index 0000000..89e1f06 --- /dev/null +++ b/SpigotCore_14/src/de/steamwar/scoreboard/SWScoreboard_14.java @@ -0,0 +1,44 @@ +package de.steamwar.scoreboard; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; + +public class SWScoreboard_14 { + + private SWScoreboard_14() {} + + static PacketContainer getRemovePacket() { + PacketContainer remove = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); + remove.getStrings().write(0, "AAA"); + remove.getBytes().write(0, (byte) 1); + return remove; + } + + static PacketContainer getCreatePacket(String title) { + PacketContainer createpacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); + createpacket.getStrings().write(0, "AAA"); + createpacket.getBytes().write(0, (byte) 0); + createpacket.getStrings().write(1, title); + createpacket.getIntegers().write(0, 0); + return createpacket; + } + + static PacketContainer getUpdatePacket(String content, Integer line) { + PacketContainer update = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_SCORE); + update.getStrings().write(0, content); + update.getBytes().write(0, (byte) 0); + update.getStrings().write(1, "AAA"); + update.getIntegers().write(0, line); + return update; + } + + static PacketContainer getDisplayPacket(String title) { + PacketContainer display = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE); + display.getBytes().write(0, (byte) 1); + display.getStrings().write(0, title); + return display; + } + + +} diff --git a/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java b/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java new file mode 100644 index 0000000..c3d2441 --- /dev/null +++ b/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java @@ -0,0 +1,44 @@ +package de.steamwar.scoreboard; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; + +public class SWScoreboard_8 { + + private SWScoreboard_8() {} + + static PacketContainer getRemovePacket() { + PacketContainer remove = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); + remove.getStrings().write(0, "AAA"); + remove.getBytes().write(0, (byte) 1); + return remove; + } + + static PacketContainer getCreatePacket(String title) { + PacketContainer createpacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); + createpacket.getStrings().write(0, "AAA"); + createpacket.getBytes().write(0, (byte) 0); + createpacket.getStrings().write(1, title); + createpacket.getStrings().write(2, "integer"); + return createpacket; + } + + static PacketContainer getUpdatePacket(String content, Integer line) { + PacketContainer update = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_SCORE); + update.getStrings().write(0, content); + update.getBytes().write(0, (byte) 0); + update.getStrings().write(1, "AAA"); + update.getIntegers().write(0, line); + return update; + } + + static PacketContainer getDisplayPacket(String title) { + PacketContainer display = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE); + display.getBytes().write(0, (byte) 1); + display.getStrings().write(0, title); + return display; + } + + +} diff --git a/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java b/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java index 4a12581..b8ec5ff 100644 --- a/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java +++ b/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java @@ -1,6 +1,5 @@ package de.steamwar.scoreboard; -import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import de.steamwar.core.Core; @@ -23,15 +22,21 @@ public class SWScoreboard { } private void sendScoreboard(Player player) { - PacketContainer remove = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); - remove.getStrings().write(0, "AAA"); - remove.getBytes().write(0, (byte) 1); - - PacketContainer createpacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); - createpacket.getStrings().write(0, "AAA"); - createpacket.getBytes().write(0, (byte) 0); - createpacket.getStrings().write(1, this.callback.getTitle()); - createpacket.getIntegers().write(0, 0); + PacketContainer remove; + PacketContainer createpacket; + switch (Core.getVersion()) { + case 8: + remove = SWScoreboard_8.getRemovePacket(); + createpacket = SWScoreboard_8.getCreatePacket(this.callback.getTitle()); + break; + case 14: + remove = SWScoreboard_14.getRemovePacket(); + createpacket = SWScoreboard_14.getCreatePacket(this.callback.getTitle()); + break; + default: + remove = SWScoreboard_12.getRemovePacket(); + createpacket = SWScoreboard_12.getCreatePacket(this.callback.getTitle()); + } try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, remove); @@ -41,11 +46,18 @@ public class SWScoreboard { } for(Map.Entry entry : this.callback.getData().entrySet()) { - PacketContainer update = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_SCORE); - update.getStrings().write(0, entry.getKey()); - update.getBytes().write(0, (byte) 0); - update.getStrings().write(1, "AAA"); - update.getIntegers().write(0, entry.getValue()); + PacketContainer update; + + switch (Core.getVersion()) { + case 8: + update = SWScoreboard_8.getUpdatePacket(entry.getKey(), entry.getValue()); + break; + case 14: + update = SWScoreboard_14.getUpdatePacket(entry.getKey(), entry.getValue()); + break; + default: + update = SWScoreboard_12.getUpdatePacket(entry.getKey(), entry.getValue()); + } try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, update); @@ -57,9 +69,19 @@ public class SWScoreboard { } private void display(Player player) { - PacketContainer display = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE); - display.getBytes().write(0, (byte) 1); - display.getStrings().write(0, this.callback.getTitle()); + PacketContainer display; + + switch (Core.getVersion()) { + case 8: + display = SWScoreboard_8.getDisplayPacket(this.callback.getTitle()); + break; + case 14: + display = SWScoreboard_14.getDisplayPacket(this.callback.getTitle()); + break; + default: + display = SWScoreboard_12.getDisplayPacket(this.callback.getTitle()); + + } try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, display);