From 6304ddffff6c7621334b3482da3f4d52f717a022 Mon Sep 17 00:00:00 2001 From: MinusKube Date: Wed, 10 Jun 2020 02:33:51 +0200 Subject: [PATCH] Add Netherboard#hasBoard method, fix error on clear() --- .../java/fr/minuskube/netherboard/Netherboard.java | 10 ++++++++++ .../fr/minuskube/netherboard/bukkit/BPlayerBoard.java | 5 +++-- .../java/fr/minuskube/netherboard/Netherboard.java | 10 ++++++++++ .../fr/minuskube/netherboard/sponge/SPlayerBoard.java | 5 +++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bukkit/src/main/java/fr/minuskube/netherboard/Netherboard.java b/bukkit/src/main/java/fr/minuskube/netherboard/Netherboard.java index 96bedca..3a8b563 100644 --- a/bukkit/src/main/java/fr/minuskube/netherboard/Netherboard.java +++ b/bukkit/src/main/java/fr/minuskube/netherboard/Netherboard.java @@ -70,6 +70,16 @@ public void removeBoard(Player player) { boards.remove(player); } + /** + * Checks if the player has a board. + * + * @param player the player + * @return true if the player has a board, otherwise false + */ + public boolean hasBoard(Player player) { + return boards.containsKey(player); + } + /** * Gets the board of a player. * 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 24b3a48..3741792 100644 --- a/bukkit/src/main/java/fr/minuskube/netherboard/bukkit/BPlayerBoard.java +++ b/bukkit/src/main/java/fr/minuskube/netherboard/bukkit/BPlayerBoard.java @@ -12,6 +12,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; public class BPlayerBoard implements PlayerBoard { @@ -125,13 +126,13 @@ public void setAll(String... lines) { for(int i = 0; i < lines.length; i++) { String line = lines[i]; - set(line, 16 - i); + set(line, lines.length - i); } } @Override public void clear() { - this.lines.keySet().forEach(this::remove); + new HashSet<>(this.lines.keySet()).forEach(this::remove); this.lines.clear(); } diff --git a/sponge/src/main/java/fr/minuskube/netherboard/Netherboard.java b/sponge/src/main/java/fr/minuskube/netherboard/Netherboard.java index 7973ac4..c29afff 100644 --- a/sponge/src/main/java/fr/minuskube/netherboard/Netherboard.java +++ b/sponge/src/main/java/fr/minuskube/netherboard/Netherboard.java @@ -71,6 +71,16 @@ public void removeBoard(Player player) { boards.remove(player); } + /** + * Checks if the player has a board. + * + * @param player the player + * @return true if the player has a board, otherwise false + */ + public boolean hasBoard(Player player) { + return boards.containsKey(player); + } + /** * Gets the board of a player. * 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 36ab296..3ab3e29 100644 --- a/sponge/src/main/java/fr/minuskube/netherboard/sponge/SPlayerBoard.java +++ b/sponge/src/main/java/fr/minuskube/netherboard/sponge/SPlayerBoard.java @@ -13,6 +13,7 @@ import org.spongepowered.api.text.Text; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; public class SPlayerBoard implements PlayerBoard { @@ -129,13 +130,13 @@ public void setAll(Text... lines) { for(int i = 0; i < lines.length; i++) { Text line = lines[i]; - set(line, 16 - i); + set(line, lines.length - i); } } @Override public void clear() { - this.lines.keySet().forEach(this::remove); + new HashSet<>(this.lines.keySet()).forEach(this::remove); this.lines.clear(); }