From 7bea5815453888d7d756c9589cbff321bb2f55d5 Mon Sep 17 00:00:00 2001 From: Maik E Date: Thu, 21 Dec 2023 00:14:15 +0100 Subject: [PATCH] Add method for UUID retrieval and improve sign management Introduced a function in the NameManager class to fetch UUIDs using short names. In the ChestShopSign class, enhanced the management of admin shop signs by refining checks for the same and optimizing the way in which owner data is stored. This will facilitate easier updating of existing signs, improved admin shops' management, and the efficiency of all operations related to the owner. --- .../ChestShop/Signs/ChestShopSign.java | 22 ++++++++++++------- .../Acrobot/ChestShop/UUIDs/NameManager.java | 11 ++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java index 3faa461b6..ba03dae7f 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -64,11 +64,10 @@ public static boolean isAdminShop(Sign sign) { PersistentDataContainer persistentDataContainer = sign.getPersistentDataContainer(); if (!persistentDataContainer.has(ADMINSHOP_NAMESPACED_KEY, PersistentDataType.BOOLEAN)) { - if (!isAdminShopNameString(sign.getLine(NAME_LINE))) { - return false; - } - persistentDataContainer.set(ADMINSHOP_NAMESPACED_KEY, PersistentDataType.BOOLEAN, Boolean.TRUE); + boolean isAdminshop = isAdminShopNameString(sign.getLine(NAME_LINE)); + persistentDataContainer.set(ADMINSHOP_NAMESPACED_KEY, PersistentDataType.BOOLEAN, Boolean.valueOf(isAdminshop)); + return isAdminshop; } return persistentDataContainer.get(ADMINSHOP_NAMESPACED_KEY, PersistentDataType.BOOLEAN).booleanValue(); @@ -104,13 +103,20 @@ public static boolean isOwner(OfflinePlayer player, Sign sign) { PersistentDataContainer persistentDataContainer = sign.getPersistentDataContainer(); String playerUUIDAsString = player.getUniqueId().toString(); + if (isAdminShop(sign)) { + return false; + } + if (!persistentDataContainer.has(OWNER_NAMESPACED_KEY, PersistentDataType.STRING)) { - if (!NameManager.canUseName(player, sign.getLine(NAME_LINE))) { + + // Update old Signs + String ownerName = sign.getLine(NAME_LINE); + UUID uuidByName = NameManager.getUUIDFor(ownerName); + persistentDataContainer.set(OWNER_NAMESPACED_KEY, PersistentDataType.STRING, uuidByName.toString()); + + if (!NameManager.canUseName(player, ownerName)) { return false; // Player isn't Owner } - - // Player is Owner, but it's only saved on the sign. Update to new way of saving the shop owner. - persistentDataContainer.set(OWNER_NAMESPACED_KEY, PersistentDataType.STRING, playerUUIDAsString); } String owner = getOwner(sign); diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index e85dd298e..a70898512 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -42,6 +42,17 @@ public static String getNameFor(Player player) { return currentShortName.get(player.getUniqueId()); } + public static UUID getUUIDFor(String shortName) { + if (Properties.ADMIN_SHOP_NAME.equalsIgnoreCase(shortName)) { + return adminShopUUID; + } + if (Properties.SERVER_ECONOMY_ACCOUNT != null && Properties.SERVER_ECONOMY_ACCOUNT.length() > 0 + && Properties.SERVER_ECONOMY_ACCOUNT.equals(shortName)) { + return serverAccountUUID; + } + return usedShortNames.get(shortName.toLowerCase()); + } + public static String getFullNameFor(UUID playerId) { if (isAdminShop(playerId)) { return Properties.ADMIN_SHOP_NAME;