Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
KillerOfPie committed Apr 10, 2022
1 parent bd3c245 commit cc612a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/shanerx/tradeshop/utils/config/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,17 @@ 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()));
}
version = 1.1;
}

//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("}", "%");

Expand All @@ -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()));
}
Expand All @@ -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) {
Expand Down

0 comments on commit cc612a3

Please sign in to comment.