Skip to content

Commit

Permalink
Refactor sign display and logger update in ChestShop
Browse files Browse the repository at this point in the history
Reorganized the flow of data in ChestShopSign class by separating sign display update and logging process. The method `updateSignDisplay` has been introduced to handle sign data updates, improving the modularity of the code and increasing readability. The logger now only logs when necessary, reducing the frequency of logger calls.
  • Loading branch information
Feli499 committed Jan 5, 2024
1 parent 97a71bc commit 4073ecf
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java
Expand Up @@ -108,16 +108,7 @@ private static void updateLegacyChestShop(Sign sign) {

ChestShopMetaData chestShopMetaData = new ChestShopMetaData(ownerUUID, quantity, sellPrice, buyPrice, itemStack);

UUID owner = chestShopMetaData.getOwner();
String fullOwnerName = NameManager.getFullNameFor(owner);

sign.setLine(0, fullOwnerName);
sign.setLine(3, ItemChecker.getSignItemName(itemStack));

saveChestShopMetaData(sign, chestShopMetaData);

ChestShop.getPlugin().getLogger().log(Level.INFO,
"Converted legacy Chestshop of %s (%s) at %d %d %d".formatted(owner, fullOwnerName, sign.getX(), sign.getY(), sign.getZ()));
}

private static boolean isLegacyChestShop(Sign sign) {
Expand All @@ -143,9 +134,22 @@ public static boolean isChestShop(Sign sign) {
return true;
}

updateSignDisplay(sign);

return sign.getPersistentDataContainer().has(METADATA_NAMESPACED_KEY, PersistentDataType.STRING);
}

private static void updateSignDisplay(Sign sign) {
ChestShopMetaData chestShopMetaData = getChestShopMetaData(sign);

UUID owner = chestShopMetaData.getOwner();
String fullOwnerName = NameManager.getFullNameFor(owner);

sign.setLine(0, fullOwnerName);
sign.setLine(3, ItemChecker.getSignItemName(chestShopMetaData.getItemStack()));
sign.update();
}

public static ChestShopMetaData getChestShopMetaData(Sign sign) {

try {
Expand Down

0 comments on commit 4073ecf

Please sign in to comment.