From 473d78ce7546de64abe72f24668c1761a8d0ff85 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 5 Dec 2019 19:33:34 +0100 Subject: [PATCH] untested rework of dependent scoreboard source --- .../steamwar/scoreboard/SWScoreboard_12.java | 18 ++++--- .../steamwar/scoreboard/SWScoreboard_8.java | 29 ++++++++-- .../de/steamwar/scoreboard/SWScoreboard.java | 53 +++++-------------- 3 files changed, 47 insertions(+), 53 deletions(-) diff --git a/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java b/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java index 41fc384..494d264 100644 --- a/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java +++ b/SpigotCore_12/src/de/steamwar/scoreboard/SWScoreboard_12.java @@ -1,23 +1,25 @@ package de.steamwar.scoreboard; +import org.bukkit.entity.Player; + public class SWScoreboard_12 { private SWScoreboard_12() {} - static void sendRemovePacket() { - SWScoreboard_8.sendRemovePacket(); + static void sendRemovePacket(Player player) { + SWScoreboard_8.sendRemovePacket(player); } - static void sendCreatePacket(String title) { - SWScoreboard_8.sendCreatePacket(title); + static void sendCreatePacket(String title, Player player) { + SWScoreboard_8.sendCreatePacket(title, player); } - static void sendUpdatePacket(String content, Integer line) { - SWScoreboard_8.sendUpdatePacket(content, line); + static void sendUpdatePacket(String content, Integer line, Player player) { + SWScoreboard_8.sendUpdatePacket(content, line, player); } - static void sendDisplayPacket() { - SWScoreboard_8.sendDisplayPacket(); + static void sendDisplayPacket(Player player) { + SWScoreboard_8.sendDisplayPacket(player); } diff --git a/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java b/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java index 6069df4..9afcbc9 100644 --- a/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java +++ b/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard_8.java @@ -3,38 +3,59 @@ package de.steamwar.scoreboard; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; public class SWScoreboard_8 { private SWScoreboard_8() {} - static void sendRemovePacket() { + static void sendRemovePacket(Player player) { PacketContainer removePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); removePacket.getStrings().write(0, "AAA"); removePacket.getIntegers().write(0, 1); //TODO kann vlt entfernt werden -> remove.getStrings().write(1, "integer"); + + sendPacket(player, removePacket); } - static void sendCreatePacket(String title) { + static void sendCreatePacket(String title, Player player) { PacketContainer createPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); createPacket.getStrings().write(0, "AAA"); createPacket.getIntegers().write(0, 0); createPacket.getStrings().write(1, title); createPacket.getStrings().write(2, "integer"); + + sendPacket(player, createPacket); } - static void sendUpdatePacket(String content, Integer line) { + static void sendUpdatePacket(String content, Integer line, Player player) { PacketContainer updatePacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_SCORE); updatePacket.getStrings().write(0, content); updatePacket.getStrings().write(1, "AAA"); updatePacket.getIntegers().write(0, line); updatePacket.getBytes().write(0, (byte) 0); + + sendPacket(player, updatePacket); } - static void sendDisplayPacket() { + static void sendDisplayPacket(Player player) { PacketContainer displayPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE); displayPacket.getIntegers().write(0, 1); displayPacket.getStrings().write(0, "AAA"); + + sendPacket(player, displayPacket); + } + + private static void sendPacket(Player player, PacketContainer packetContainer) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer); + } catch (InvocationTargetException ex) { + Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex); + } } diff --git a/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java b/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java index b8ec5ff..4b329f3 100644 --- a/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java +++ b/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java @@ -1,15 +1,11 @@ package de.steamwar.scoreboard; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketContainer; import de.steamwar.core.Core; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; public class SWScoreboard { @@ -22,72 +18,47 @@ public class SWScoreboard { } private void sendScoreboard(Player player) { - PacketContainer remove; - PacketContainer createpacket; switch (Core.getVersion()) { case 8: - remove = SWScoreboard_8.getRemovePacket(); - createpacket = SWScoreboard_8.getCreatePacket(this.callback.getTitle()); + SWScoreboard_8.sendRemovePacket(player); + SWScoreboard_8.sendCreatePacket(this.callback.getTitle(), player); break; case 14: - remove = SWScoreboard_14.getRemovePacket(); - createpacket = SWScoreboard_14.getCreatePacket(this.callback.getTitle()); + //Todo remove = SWScoreboard_14.getRemovePacket(); + //Todo 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); - ProtocolLibrary.getProtocolManager().sendServerPacket(player, createpacket); - } catch (InvocationTargetException ex) { - Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex); + SWScoreboard_12.sendRemovePacket(player); + SWScoreboard_12.sendCreatePacket(this.callback.getTitle(), player); } for(Map.Entry entry : this.callback.getData().entrySet()) { - PacketContainer update; - switch (Core.getVersion()) { case 8: - update = SWScoreboard_8.getUpdatePacket(entry.getKey(), entry.getValue()); + SWScoreboard_8.sendUpdatePacket(entry.getKey(), entry.getValue(), player); break; case 14: - update = SWScoreboard_14.getUpdatePacket(entry.getKey(), entry.getValue()); + //Todo update = SWScoreboard_14.getUpdatePacket(entry.getKey(), entry.getValue()); break; default: - update = SWScoreboard_12.getUpdatePacket(entry.getKey(), entry.getValue()); - } - - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, update); - } catch (InvocationTargetException ex) { - Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex); + SWScoreboard_12.sendUpdatePacket(entry.getKey(), entry.getValue(), player); } } } private void display(Player player) { - PacketContainer display; - switch (Core.getVersion()) { case 8: - display = SWScoreboard_8.getDisplayPacket(this.callback.getTitle()); + SWScoreboard_8.sendDisplayPacket(player); break; case 14: - display = SWScoreboard_14.getDisplayPacket(this.callback.getTitle()); + //Todo display = SWScoreboard_14.getDisplayPacket(this.callback.getTitle()); break; default: - display = SWScoreboard_12.getDisplayPacket(this.callback.getTitle()); + SWScoreboard_12.sendDisplayPacket(player); } - - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, display); - } catch (InvocationTargetException ex) { - Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex); - } } static {