diff --git a/src/main/java/com/Acrobot/Breeze/Configuration/ValueParser.java b/src/main/java/com/Acrobot/Breeze/Configuration/ValueParser.java index d711986..7e16d0a 100644 --- a/src/main/java/com/Acrobot/Breeze/Configuration/ValueParser.java +++ b/src/main/java/com/Acrobot/Breeze/Configuration/ValueParser.java @@ -19,6 +19,12 @@ public class ValueParser { public static String parseToYAML(Object object) { if (object instanceof Number || object instanceof Boolean) { return String.valueOf(object); + } else if (object instanceof List) { + StringBuilder sb = new StringBuilder(); + for (Object o : (List) object) { + sb.append("\n- ").append(parseToYAML(o)); + } + return sb.toString(); } else { return '\"' + String.valueOf(object) + '\"'; } diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java index e8e102b..e81b32c 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -3,6 +3,9 @@ package com.Acrobot.ChestShop.Configuration; import com.Acrobot.Breeze.Configuration.Annotations.ConfigurationComment; import com.Acrobot.Breeze.Configuration.Annotations.PrecededBySpace; +import java.util.Arrays; +import java.util.List; + /** * @author Acrobot */ @@ -43,6 +46,9 @@ public class Properties { @ConfigurationComment("If true, if the REMOVE_EMPTY_SHOPS option is turned on, the chest is also destroyed.") public static boolean REMOVE_EMPTY_CHESTS = false; + @ConfigurationComment("A list of worlds in which to remove empty shops with the previous config. Case sensitive. An empty list means all worlds.") + public static List REMOVE_EMPTY_WORLDS = Arrays.asList("world1", "world2"); + @PrecededBySpace @ConfigurationComment("First line of your Admin Shop's sign should look like this:") public static String ADMIN_SHOP_NAME = "Admin Shop"; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EmptyShopDeleter.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EmptyShopDeleter.java index 606fb22..085c7d9 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EmptyShopDeleter.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EmptyShopDeleter.java @@ -30,10 +30,14 @@ public class EmptyShopDeleter implements Listener { Inventory ownerInventory = event.getOwnerInventory(); Sign sign = event.getSign(); Chest connectedChest = uBlock.findConnectedChest(sign); - + if (!shopShouldBeRemoved(ownerInventory, event.getStock())) { return; } + + if (!isInRemoveWorld(sign)) { + return; + } ShopDestroyedEvent destroyedEvent = new ShopDestroyedEvent(null, event.getSign(), connectedChest); ChestShop.callEvent(destroyedEvent); @@ -46,8 +50,12 @@ public class EmptyShopDeleter implements Listener { ownerInventory.addItem(new ItemStack(Material.SIGN, 1)); } } - + private static boolean shopShouldBeRemoved(Inventory inventory, ItemStack[] stock) { return Properties.REMOVE_EMPTY_SHOPS && !ChestShopSign.isAdminShop(inventory) && !InventoryUtil.hasItems(stock, inventory); } + + private static boolean isInRemoveWorld(Sign sign) { + return Properties.REMOVE_EMPTY_WORLDS.isEmpty() || Properties.REMOVE_EMPTY_WORLDS.contains(sign.getWorld().getName()); + } }