From ef8f597796aa8fadda65b767689056706246b3a7 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 15 Jun 2017 14:03:48 +0200 Subject: [PATCH] Added CHEST_SPACE requirement and placeholder + Fixed %MAX-STACK% placeholder --- .../java/de/epiceric/shopchest/config/HologramFormat.java | 6 +++--- src/main/java/de/epiceric/shopchest/config/Placeholder.java | 1 + src/main/java/de/epiceric/shopchest/shop/Shop.java | 3 +++ src/main/resources/hologram-format.yml | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/config/HologramFormat.java b/src/main/java/de/epiceric/shopchest/config/HologramFormat.java index 3123244..4ceb100 100644 --- a/src/main/java/de/epiceric/shopchest/config/HologramFormat.java +++ b/src/main/java/de/epiceric/shopchest/config/HologramFormat.java @@ -18,7 +18,7 @@ public class HologramFormat { public enum Requirement { VENDOR, AMOUNT, ITEM_TYPE, ITEM_NAME, HAS_ENCHANTMENT, BUY_PRICE, SELL_PRICE, HAS_POTION_EFFECT, IS_MUSIC_DISC, IS_POTION_EXTENDED, IS_WRITTEN_BOOK, ADMIN_SHOP, - NORMAL_SHOP, IN_STOCK, MAX_STACK + NORMAL_SHOP, IN_STOCK, MAX_STACK, CHEST_SPACE } private ShopChest plugin; @@ -78,12 +78,12 @@ public class HologramFormat { ConfigurationSection option = options.getConfigurationSection(key); String format = option.getString("format"); - if (format.contains(Placeholder.STOCK.toString())) { + if (format.contains(Placeholder.STOCK.toString()) || format.contains(Placeholder.CHEST_SPACE.toString())) { return true; } for (String req : option.getStringList("requirements")) { - if (req.contains(Requirement.IN_STOCK.toString())) { + if (req.contains(Requirement.IN_STOCK.toString()) || req.contains(Requirement.CHEST_SPACE.toString())) { return true; } } diff --git a/src/main/java/de/epiceric/shopchest/config/Placeholder.java b/src/main/java/de/epiceric/shopchest/config/Placeholder.java index d2929b1..caa7f25 100644 --- a/src/main/java/de/epiceric/shopchest/config/Placeholder.java +++ b/src/main/java/de/epiceric/shopchest/config/Placeholder.java @@ -23,6 +23,7 @@ public enum Placeholder { REVENUE("%REVENUE%"), GENERATION("%GENERATION%"), STOCK("%STOCK%"), + CHEST_SPACE("%CHEST-SPACE%"), MAX_STACK("%MAX-STACK%"), COMMAND("%COMMAND%"); diff --git a/src/main/java/de/epiceric/shopchest/shop/Shop.java b/src/main/java/de/epiceric/shopchest/shop/Shop.java index 3f2a3cf..5fb41ab 100644 --- a/src/main/java/de/epiceric/shopchest/shop/Shop.java +++ b/src/main/java/de/epiceric/shopchest/shop/Shop.java @@ -197,6 +197,7 @@ public class Shop { requirements.put(HologramFormat.Requirement.NORMAL_SHOP, getShopType() == ShopType.NORMAL); requirements.put(HologramFormat.Requirement.IN_STOCK, Utils.getAmount(getInventoryHolder().getInventory(), getProduct())); requirements.put(HologramFormat.Requirement.MAX_STACK, getProduct().getMaxStackSize()); + requirements.put(HologramFormat.Requirement.CHEST_SPACE, Utils.getFreeSpaceForItem(getInventoryHolder().getInventory(), getProduct())); Map placeholders = new HashMap<>(); placeholders.put(Placeholder.VENDOR, getVendor().getName()); @@ -209,6 +210,8 @@ public class Shop { placeholders.put(Placeholder.MUSIC_TITLE, LanguageUtils.getMusicDiscName(getProduct().getType())); placeholders.put(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(ItemUtils.getBookGeneration(getProduct()))); placeholders.put(Placeholder.STOCK, Utils.getAmount(getInventoryHolder().getInventory(), getProduct())); + placeholders.put(Placeholder.MAX_STACK, getProduct().getMaxStackSize()); + placeholders.put(Placeholder.CHEST_SPACE, Utils.getFreeSpaceForItem(getInventoryHolder().getInventory(), getProduct())); int lineCount = plugin.getHologramFormat().getLineCount(); diff --git a/src/main/resources/hologram-format.yml b/src/main/resources/hologram-format.yml index 0a811f1..0fdf2a7 100644 --- a/src/main/resources/hologram-format.yml +++ b/src/main/resources/hologram-format.yml @@ -5,7 +5,7 @@ # Valid requirements are: # VENDOR, AMOUNT, ITEM_TYPE, ITEM_NAME, HAS_ENCHANTMENT, BUY_PRICE, # SELL_PRICE, HAS_POTION_EFFECT, IS_MUSIC_DISC, IS_POTION_EXTENDED, -# IS_WRITTEN_BOOK, ADMIN_SHOP, NORMAL_SHOP, IN_STOCK, MAX_STACK +# IS_WRITTEN_BOOK, ADMIN_SHOP, NORMAL_SHOP, IN_STOCK, MAX_STACK, CHEST_SPACE # # You can also use the requirements for conditions. # ITEM_TYPE will return the type of the item (-> item_names.txt), @@ -24,7 +24,7 @@ # Valid placeholders are: # %VENDOR%, %AMOUNT%, %ITEM-NAME%, %ENCHANTMENT%, %BUY-PRICE%, # %SELL-PRICE%, %POTION-EFFECT%, %MUSIC-TITLE%, %GENERATION%, -# %STOCK%, %MAX-STACK% +# %STOCK%, %MAX-STACK%, %CHEST-SPACE% # # In the format, placeholders can also be used for scripts. # Examples: