diff --git a/SpigotCore_12/SpigotCore_12.iml b/SpigotCore_12/SpigotCore_12.iml new file mode 100644 index 0000000..435bce5 --- /dev/null +++ b/SpigotCore_12/SpigotCore_12.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SpigotCore_14/SpigotCore_14.iml b/SpigotCore_14/SpigotCore_14.iml new file mode 100644 index 0000000..e977297 --- /dev/null +++ b/SpigotCore_14/SpigotCore_14.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SpigotCore_8/SpigotCore_8.iml b/SpigotCore_8/SpigotCore_8.iml new file mode 100644 index 0000000..9c3822a --- /dev/null +++ b/SpigotCore_8/SpigotCore_8.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SpigotCore_Main/SpigotCore_Main.iml b/SpigotCore_Main/SpigotCore_Main.iml new file mode 100644 index 0000000..71dcca5 --- /dev/null +++ b/SpigotCore_Main/SpigotCore_Main.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java b/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java new file mode 100644 index 0000000..ac95ad1 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/scoreboard/SWScoreboard.java @@ -0,0 +1,89 @@ +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.HashMap; +import java.util.Map; +import java.util.logging.Level; + +public class SWScoreboard { + + HashMap data; + private Player player; + private String title; + + public SWScoreboard(Player player, HashMap data, String title) { + this.data = data; + this.player = player; + this.title = title; + } + + public void sendScoreboard() { + 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.title); + createpacket.getIntegers().write(0, 0); + + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, remove); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, createpacket); + } catch (InvocationTargetException ex) { + Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex); + } + + for(Map.Entry entry : data.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()); + + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, update); + } catch (InvocationTargetException ex) { + Bukkit.getLogger().log(Level.SEVERE, "COULD NOT SEND PACKAGE", ex); + } + } + + } + + public void display() { + PacketContainer display = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE); + display.getBytes().write(0, (byte) 1); + display.getStrings().write(0, this.title); + } + + public HashMap getData() { + return data; + } + + public void setData(HashMap data) { + this.data = data; + } + + public Player getPlayer() { + return player; + } + + public void setPlayer(Player player) { + this.player = player; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/SpigotCore_Main/src/de/steamwar/scoreboard/ScoreboardCallback.java b/SpigotCore_Main/src/de/steamwar/scoreboard/ScoreboardCallback.java new file mode 100644 index 0000000..44ad47b --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/scoreboard/ScoreboardCallback.java @@ -0,0 +1,12 @@ +package de.steamwar.scoreboard; + +import java.util.HashMap; + +public interface ScoreboardCallback { + + public HashMap getData(); + + public String getTitle(); + + +} diff --git a/SpigotCore_Main/src/de/steamwar/scoreboard/ScoreboardContainer.java b/SpigotCore_Main/src/de/steamwar/scoreboard/ScoreboardContainer.java new file mode 100644 index 0000000..8389c22 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/scoreboard/ScoreboardContainer.java @@ -0,0 +1,57 @@ +package de.steamwar.scoreboard; + +import de.steamwar.core.Core; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.UUID; + +public class ScoreboardContainer { + + private static HashMap containers = new HashMap<>(); + + Player player; + ScoreboardCallback callback; + + public ScoreboardContainer(Player player, ScoreboardCallback callback) { + this.player = player; + this.callback = callback; + } + + public void update() { + + //Update + SWScoreboard update = new SWScoreboard(player, callback.getData(), callback.getTitle()); + update.sendScoreboard(); + Bukkit.getScheduler().runTaskLater(Core.getInstance(), new Runnable() { + @Override + public void run() { + update.display(); + } + }, 2); + } + + public void startScoreboard() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.getInstance(), new Runnable() { + @Override + public void run() { + for(ScoreboardContainer container : ScoreboardContainer.getContainers().values()) { + container.update(); + } + } + }, 10, 5); + } + + public Player getPlayer() { + return player; + } + + public void setPlayer(Player player) { + this.player = player; + } + + public static HashMap getContainers() { + return containers; + } +} diff --git a/pom.xml b/pom.xml index dbc56a3..5d1491f 100644 --- a/pom.xml +++ b/pom.xml @@ -42,4 +42,13 @@ SpigotCore_14 SpigotCore_Main + + + + steamwar + ProtocolLib + 1.0 + provided + + \ No newline at end of file