From 2e84c34ad569fa8bb95a0423723ffbd4b2cc9d68 Mon Sep 17 00:00:00 2001 From: Maik E Date: Fri, 29 Dec 2023 19:36:00 +0100 Subject: [PATCH] Refactor variables and handle empty accessor data The variable name in the loop has been changed from 'string' to 'accessorUUID' in PlayerInteract.java for better clarity. Alongside this renaming, the code in ChestShopSign.java has been updated to return an empty HashSet when no accessor data exists to avoid any potential errors or misinterpretations. --- .../Acrobot/ChestShop/Listeners/Player/PlayerInteract.java | 4 ++-- src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java index 25b4762ef..2e8af12d2 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -150,10 +150,10 @@ private static void showShopInfo(Player player, Sign sign) { player.sendMessage(Messages.prefix(Messages.SHOP_OWNER_INFO)); Collection accessors = ChestShopSign.getAccessors(sign); StringBuilder accessorNames = new StringBuilder(); - for (String string : accessors) { + for (String accessorUUID : accessors) { if (!accessorNames.isEmpty()) accessorNames.append(", "); - accessorNames.append(NameManager.getFullNameFor(UUID.fromString(string))); + accessorNames.append(NameManager.getFullNameFor(UUID.fromString(accessorUUID))); } player.sendMessage(" " + Messages.SHOP_ACCESSORS.replace("%accessor_list", accessorNames.toString())); diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java index 0e8e698aa..07baaa234 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -163,6 +163,9 @@ public static Collection getAccessors(Sign sign) { return new HashSet<>(); String data = persistentDataContainer.get(ACCESSORS_NAMESPACED_KEY, PersistentDataType.STRING); + if (data.isEmpty()) + return new HashSet<>(); + String[] split = data.split(";"); return new HashSet<>(Arrays.asList(split));