From cc612a30915a5cfaabdbb7603330b4e11b20a065 Mon Sep 17 00:00:00 2001 From: KillerOfPie Date: Sun, 10 Apr 2022 10:56:36 -0700 Subject: [PATCH] Bug Fixes - Fixes new messages not being saved properly when the message file is first created due to changes in config version 1.2 - Fixes Shop status not updating when hoppers push into a shop chest. --- .../tradeshop/listeners/ShopProtectionListener.java | 2 ++ .../org/shanerx/tradeshop/utils/config/Message.java | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java index af2c68c3..5ddad102 100644 --- a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java +++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java @@ -138,6 +138,8 @@ public void onInventoryMoveItem(InventoryMoveItemEvent event) { event.setCancelled(hopperEvent.isForbidden()); plugin.getListManager().addSkippableHopper(event.getInitiator().getLocation(), hopperEvent.isForbidden()); debugger.log("ShopProtectionListener: (TSAF) HopperEvent isForbidden: " + hopperEvent.isForbidden(), DebugLevels.PROTECTION); + shop.updateStatus(); + shop.saveShop(); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/src/main/java/org/shanerx/tradeshop/utils/config/Message.java b/src/main/java/org/shanerx/tradeshop/utils/config/Message.java index 238848bb..aaba7126 100644 --- a/src/main/java/org/shanerx/tradeshop/utils/config/Message.java +++ b/src/main/java/org/shanerx/tradeshop/utils/config/Message.java @@ -115,10 +115,9 @@ public enum Message { // Method to fix any values that have changed with updates static void upgrade() { double version = MESSAGE_VERSION.getDouble(); - ConfigManager configManager = PLUGIN.getMessageManager(); //Changes if CONFIG_VERSION is below 1.1, then update to 1.1 - if (version < 1.1) { + if (checkVersion(version, 1.1)) { if (TOO_MANY_ITEMS.getString().equals("&cThis trade can not take any more %side%!")) { TOO_MANY_ITEMS.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, TOO_MANY_ITEMS.getPath())); } @@ -126,7 +125,7 @@ static void upgrade() { } //Changes if CONFIG_VERSION is below 1.2, then update to 1.2 - if (version < 1.2) { + if (checkVersion(version, 1.2)) { Arrays.stream(values()).forEach((message) -> { String str = message.getString().replace("{", "%").replace("}", "%"); @@ -138,7 +137,7 @@ static void upgrade() { } //Changes if CONFIG_VERSION is below 1.3, then update to 1.3 - if (version < 1.3) { + if (checkVersion(version, 1.3)) { if (INSUFFICIENT_ITEMS.getString().equals("&cYou do not have &e%AMOUNT% %ITEM%&c!")) { INSUFFICIENT_ITEMS.setValue(PLUGIN.getLanguage().getDefault(Language.LangSection.MESSAGE, INSUFFICIENT_ITEMS.getPath())); } @@ -153,7 +152,11 @@ static void upgrade() { version = 1.3; } - MESSAGE_VERSION.setValue(version); + MESSAGE_VERSION.setValue(version != 0.0 ? version : 1.3); + } + + private static boolean checkVersion(double version, double maxVersion) { + return version > 0.0 && version < maxVersion; } private void setValue(Object obj) {