diff --git a/build.gradle b/build.gradle index 83188e6..45e462d 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ subprojects { sourceCompatibility = '1.8' group 'fr.minuskube' - version '1.0.4' + version '1.0.5' configurations { provided } diff --git a/bukkit/src/main/java/fr/minuskube/netherboard/Netherboard.java b/bukkit/src/main/java/fr/minuskube/netherboard/Netherboard.java index dceeeda..03d77e3 100644 --- a/bukkit/src/main/java/fr/minuskube/netherboard/Netherboard.java +++ b/bukkit/src/main/java/fr/minuskube/netherboard/Netherboard.java @@ -42,8 +42,7 @@ public BPlayerBoard createBoard(Player player, String name) { * @return the newly created board */ public BPlayerBoard createBoard(Player player, Scoreboard scoreboard, String name) { - if(boards.containsKey(player)) - boards.get(player).delete(); + deleteBoard(player); BPlayerBoard board = new BPlayerBoard(player, scoreboard, name); diff --git a/bukkit/src/main/java/fr/minuskube/netherboard/bukkit/BPlayerBoard.java b/bukkit/src/main/java/fr/minuskube/netherboard/bukkit/BPlayerBoard.java index 3c4ff69..67cd73a 100644 --- a/bukkit/src/main/java/fr/minuskube/netherboard/bukkit/BPlayerBoard.java +++ b/bukkit/src/main/java/fr/minuskube/netherboard/bukkit/BPlayerBoard.java @@ -62,11 +62,11 @@ public BPlayerBoard(Player player, Scoreboard scoreboard, String name) { this.buffer = this.scoreboard.registerNewObjective("bf" + subName, "dummy"); this.objective.setDisplayName(name); - sendObjectiveCreate(this.objective); - sendObjective(this.objective); + sendObjective(this.objective, ObjectiveMode.CREATE); + sendObjectiveDisplay(this.objective); this.buffer.setDisplayName(name); - sendObjectiveCreate(this.buffer); + sendObjective(this.buffer, ObjectiveMode.CREATE); this.player.setScoreboard(this.scoreboard); } @@ -113,7 +113,7 @@ public void set(String name, Integer score) { } private void swapBuffers() { - sendObjective(this.buffer); + sendObjectiveDisplay(this.buffer); Objective temp = this.buffer; @@ -121,24 +121,24 @@ private void swapBuffers() { this.objective = temp; } - private void sendObjectiveCreate(Objective obj) { + private void sendObjective(Objective obj, ObjectiveMode mode) { try { Object objHandle = NMS.getHandle(obj); Object packetObj = NMS.PACKET_OBJ.newInstance( objHandle, - 0 + mode.ordinal() ); NMS.sendPacket(packetObj, player); } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - LOGGER.error("Error while creating and sending display packet. (Unsupported Minecraft version?)", e); + LOGGER.error("Error while creating and sending objective packet. (Unsupported Minecraft version?)", e); } } - private void sendObjective(Objective obj) { + private void sendObjectiveDisplay(Objective obj) { try { Object objHandle = NMS.getHandle(obj); @@ -240,6 +240,9 @@ public void delete() { Netherboard.instance().removeBoard(player); + sendObjective(this.objective, ObjectiveMode.REMOVE); + sendObjective(this.buffer, ObjectiveMode.REMOVE); + this.objective.unregister(); this.objective = null; @@ -273,6 +276,9 @@ public void setName(String name) { this.objective.setDisplayName(name); this.buffer.setDisplayName(name); + + sendObjective(this.objective, ObjectiveMode.UPDATE); + sendObjective(this.buffer, ObjectiveMode.UPDATE); } public Player getPlayer() { @@ -281,4 +287,7 @@ public Player getPlayer() { public Scoreboard getScoreboard() { return scoreboard; } + + private enum ObjectiveMode { CREATE, REMOVE, UPDATE } + } diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 8c1fbce..68b20a8 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: Netherboard -version: 1.0.4 +version: 1.0.5 description: Scoreboard API for your Bukkit Plugins. author: MinusKube website: https://github.com/MinusKube/netherboard diff --git a/sponge/src/main/java/fr/minuskube/netherboard/Netherboard.java b/sponge/src/main/java/fr/minuskube/netherboard/Netherboard.java index 0d9efc9..07c1ee0 100644 --- a/sponge/src/main/java/fr/minuskube/netherboard/Netherboard.java +++ b/sponge/src/main/java/fr/minuskube/netherboard/Netherboard.java @@ -43,8 +43,7 @@ public SPlayerBoard createBoard(Player player, Text name) { * @return the newly created board */ public SPlayerBoard createBoard(Player player, Scoreboard scoreboard, Text name) { - if(boards.containsKey(player)) - boards.get(player).delete(); + deleteBoard(player); SPlayerBoard board = new SPlayerBoard(player, scoreboard, name); diff --git a/sponge/src/main/java/fr/minuskube/netherboard/sponge/NetherboardPlugin.java b/sponge/src/main/java/fr/minuskube/netherboard/sponge/NetherboardPlugin.java index 27023f1..95f4c9e 100644 --- a/sponge/src/main/java/fr/minuskube/netherboard/sponge/NetherboardPlugin.java +++ b/sponge/src/main/java/fr/minuskube/netherboard/sponge/NetherboardPlugin.java @@ -6,5 +6,5 @@ description = "Scoreboard API for your Sponge Plugins.", authors = "MinusKube", url = "https://github.com/MinusKube/netherboard", - version = "1.0.4") + version = "1.0.5") public class NetherboardPlugin {} \ No newline at end of file