Added CHEST_SPACE requirement and placeholder

+ Fixed %MAX-STACK% placeholder
This commit is contained in:
Eric 2017-06-15 14:03:48 +02:00
parent 0e1fc781f5
commit ef8f597796
4 changed files with 9 additions and 5 deletions

View File

@ -18,7 +18,7 @@ public class HologramFormat {
public enum Requirement { public enum Requirement {
VENDOR, AMOUNT, ITEM_TYPE, ITEM_NAME, HAS_ENCHANTMENT, BUY_PRICE, 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, 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; private ShopChest plugin;
@ -78,12 +78,12 @@ public class HologramFormat {
ConfigurationSection option = options.getConfigurationSection(key); ConfigurationSection option = options.getConfigurationSection(key);
String format = option.getString("format"); 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; return true;
} }
for (String req : option.getStringList("requirements")) { 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; return true;
} }
} }

View File

@ -23,6 +23,7 @@ public enum Placeholder {
REVENUE("%REVENUE%"), REVENUE("%REVENUE%"),
GENERATION("%GENERATION%"), GENERATION("%GENERATION%"),
STOCK("%STOCK%"), STOCK("%STOCK%"),
CHEST_SPACE("%CHEST-SPACE%"),
MAX_STACK("%MAX-STACK%"), MAX_STACK("%MAX-STACK%"),
COMMAND("%COMMAND%"); COMMAND("%COMMAND%");

View File

@ -197,6 +197,7 @@ public class Shop {
requirements.put(HologramFormat.Requirement.NORMAL_SHOP, getShopType() == ShopType.NORMAL); requirements.put(HologramFormat.Requirement.NORMAL_SHOP, getShopType() == ShopType.NORMAL);
requirements.put(HologramFormat.Requirement.IN_STOCK, Utils.getAmount(getInventoryHolder().getInventory(), getProduct())); requirements.put(HologramFormat.Requirement.IN_STOCK, Utils.getAmount(getInventoryHolder().getInventory(), getProduct()));
requirements.put(HologramFormat.Requirement.MAX_STACK, getProduct().getMaxStackSize()); requirements.put(HologramFormat.Requirement.MAX_STACK, getProduct().getMaxStackSize());
requirements.put(HologramFormat.Requirement.CHEST_SPACE, Utils.getFreeSpaceForItem(getInventoryHolder().getInventory(), getProduct()));
Map<Placeholder, Object> placeholders = new HashMap<>(); Map<Placeholder, Object> placeholders = new HashMap<>();
placeholders.put(Placeholder.VENDOR, getVendor().getName()); 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.MUSIC_TITLE, LanguageUtils.getMusicDiscName(getProduct().getType()));
placeholders.put(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(ItemUtils.getBookGeneration(getProduct()))); placeholders.put(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(ItemUtils.getBookGeneration(getProduct())));
placeholders.put(Placeholder.STOCK, Utils.getAmount(getInventoryHolder().getInventory(), 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(); int lineCount = plugin.getHologramFormat().getLineCount();

View File

@ -5,7 +5,7 @@
# Valid requirements are: # Valid requirements are:
# VENDOR, AMOUNT, ITEM_TYPE, ITEM_NAME, HAS_ENCHANTMENT, BUY_PRICE, # VENDOR, AMOUNT, ITEM_TYPE, ITEM_NAME, HAS_ENCHANTMENT, BUY_PRICE,
# SELL_PRICE, HAS_POTION_EFFECT, IS_MUSIC_DISC, IS_POTION_EXTENDED, # 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. # You can also use the requirements for conditions.
# ITEM_TYPE will return the type of the item (-> item_names.txt), # ITEM_TYPE will return the type of the item (-> item_names.txt),
@ -24,7 +24,7 @@
# Valid placeholders are: # Valid placeholders are:
# %VENDOR%, %AMOUNT%, %ITEM-NAME%, %ENCHANTMENT%, %BUY-PRICE%, # %VENDOR%, %AMOUNT%, %ITEM-NAME%, %ENCHANTMENT%, %BUY-PRICE%,
# %SELL-PRICE%, %POTION-EFFECT%, %MUSIC-TITLE%, %GENERATION%, # %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. # In the format, placeholders can also be used for scripts.
# Examples: # Examples: