From 4b1afc593568b7a124def25bcbed6ff1d8bf4691 Mon Sep 17 00:00:00 2001 From: MinusKube Date: Wed, 10 Jun 2020 02:53:57 +0200 Subject: [PATCH] Don't clear when using setAll, to avoid blinking --- .../fr/minuskube/netherboard/bukkit/BPlayerBoard.java | 10 ++++++++-- .../java/fr/minuskube/netherboard/api/PlayerBoard.java | 2 +- .../fr/minuskube/netherboard/sponge/SPlayerBoard.java | 10 ++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) 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 3741792..cd4536f 100644 --- a/bukkit/src/main/java/fr/minuskube/netherboard/bukkit/BPlayerBoard.java +++ b/bukkit/src/main/java/fr/minuskube/netherboard/bukkit/BPlayerBoard.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Set; public class BPlayerBoard implements PlayerBoard { @@ -121,13 +122,18 @@ public void setAll(String... lines) { if(this.deleted) throw new IllegalStateException("The PlayerBoard is deleted!"); - clear(); - for(int i = 0; i < lines.length; i++) { String line = lines[i]; set(line, lines.length - i); } + + Set scores = new HashSet<>(this.lines.keySet()); + for (int score : scores) { + if (score <= 0 || score > lines.length) { + remove(score); + } + } } @Override diff --git a/core/src/main/java/fr/minuskube/netherboard/api/PlayerBoard.java b/core/src/main/java/fr/minuskube/netherboard/api/PlayerBoard.java index 8b793ef..bad3fb4 100644 --- a/core/src/main/java/fr/minuskube/netherboard/api/PlayerBoard.java +++ b/core/src/main/java/fr/minuskube/netherboard/api/PlayerBoard.java @@ -25,7 +25,7 @@ public interface PlayerBoard { * Sets all the lines of the scoreboard. * This will clear all of the current board lines, then set * all of the given lines, from top to down, by giving them each a score - * determined by {@code 16 - index}. + * determined by {@code lines.length - index}. * * @param lines the new board lines */ diff --git a/sponge/src/main/java/fr/minuskube/netherboard/sponge/SPlayerBoard.java b/sponge/src/main/java/fr/minuskube/netherboard/sponge/SPlayerBoard.java index 3ab3e29..44d9864 100644 --- a/sponge/src/main/java/fr/minuskube/netherboard/sponge/SPlayerBoard.java +++ b/sponge/src/main/java/fr/minuskube/netherboard/sponge/SPlayerBoard.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Set; public class SPlayerBoard implements PlayerBoard { @@ -125,13 +126,18 @@ public void setAll(Text... lines) { if(this.deleted) throw new IllegalStateException("The PlayerBoard is deleted!"); - clear(); - for(int i = 0; i < lines.length; i++) { Text line = lines[i]; set(line, lines.length - i); } + + Set scores = new HashSet<>(this.lines.keySet()); + for (int score : scores) { + if (score <= 0 || score > lines.length) { + remove(score); + } + } } @Override