mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-25 00:01:21 +01:00
Add option to set the worlds where shops should be removed (Fixes #129)
This also adds the ability to set string lists in the config.
This commit is contained in:
parent
34b6ab2cf2
commit
b3e62f199f
@ -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) + '\"';
|
||||
}
|
||||
|
@ -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<String> 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";
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user