From 37f8891bfe8792aeb42721bd3df808802dcbf549 Mon Sep 17 00:00:00 2001 From: KillerOfPie Date: Sun, 12 Jun 2022 21:38:04 -0700 Subject: [PATCH] Feature Add and Bug Fixes - Added configurable colours for the middle lines on trade sides per material type #135 - Removed Message call in CommandRunner that should never be used and would never actually send if it was. - Added SET_MANAGER and SET_MEMBER commands to the autofill for player names - Added Config support for map values so individual setting enums are not required for settings that may change(like sign types), This should automatically add new items to existing maps as well - Changed SettingSection weights to start at 50 increments based on nest depth to make them more easily readable - Changed Member and Manager Lists into Sets to prevent Duplicates(hopefully) - Added Shop#saveShop with a boolean parameter so that conditional saves don't need a separate if statement - Removed Wall sign types since each sign type is handled the same whether it is on a wall or not - Adjusted sign code to properly handle above - Fixed error in ShoptradeListener where shops in the OOS state but without a product would try to check on stock. --- .../tradeshop/commands/CommandTabCaller.java | 2 + .../commandrunners/CommandRunner.java | 1 - .../tradeshop/data/config/ConfigManager.java | 18 ++++-- .../tradeshop/data/config/Setting.java | 31 +++++++-- .../tradeshop/data/config/SettingSection.java | 47 ++++++++------ .../java/org/shanerx/tradeshop/shop/Shop.java | 53 ++++++++------- .../org/shanerx/tradeshop/shop/ShopSign.java | 64 ++++++++++++------- .../shop/listeners/ShopTradeListener.java | 8 ++- src/main/resources/Lang/en-us.yml | 10 ++- 9 files changed, 157 insertions(+), 77 deletions(-) diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandTabCaller.java b/src/main/java/org/shanerx/tradeshop/commands/CommandTabCaller.java index 202ebbca..579c836e 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/CommandTabCaller.java +++ b/src/main/java/org/shanerx/tradeshop/commands/CommandTabCaller.java @@ -75,6 +75,8 @@ public List onTabComplete(CommandSender sender, Command cmd, String labe return tabCompleter.fillShopPlayer(); case ADD_MANAGER: case ADD_MEMBER: + case SET_MEMBER: + case SET_MANAGER: case PLAYER_LEVEL: return tabCompleter.fillServerPlayer(); default: diff --git a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/CommandRunner.java b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/CommandRunner.java index dc4d2926..030d5220 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/commandrunners/CommandRunner.java +++ b/src/main/java/org/shanerx/tradeshop/commands/commandrunners/CommandRunner.java @@ -64,7 +64,6 @@ public CommandRunner(TradeShop instance, CommandPass command) { */ protected Shop findShop() { if (pSender == null) { - Message.PLAYER_ONLY_COMMAND.sendMessage(pSender); return null; } diff --git a/src/main/java/org/shanerx/tradeshop/data/config/ConfigManager.java b/src/main/java/org/shanerx/tradeshop/data/config/ConfigManager.java index 6f110e4b..b8241e72 100644 --- a/src/main/java/org/shanerx/tradeshop/data/config/ConfigManager.java +++ b/src/main/java/org/shanerx/tradeshop/data/config/ConfigManager.java @@ -42,6 +42,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.LinkedHashMap; +import java.util.Map; import java.util.logging.Level; public class ConfigManager { @@ -154,13 +155,13 @@ public void save() { switch (configType) { case CONFIG: Arrays.stream(SettingSection.values()).sorted(new CompareSettingSections()).forEach((section) -> outputMap.put(section.getPath(), section.getFileString())); - Arrays.stream(Setting.values()).forEach((section) -> outputMap.put(section.getSection().getPath(), - outputMap.getOrDefault(section.getSection().getPath(), "") + section.getFileString())); + Arrays.stream(Setting.values()).forEach((setting) -> outputMap.put(setting.getSection().getPath(), + outputMap.getOrDefault(setting.getSection().getPath(), "") + setting.getFileString())); break; case MESSAGES: Arrays.stream(MessageSection.values()).sorted(new CompareMessageSections()).forEach((section) -> outputMap.put(section.getPath(), section.getFileString())); - Arrays.stream(Message.values()).forEach((section) -> outputMap.put(section.getSection().getPath(), - outputMap.getOrDefault(section.getSection().getPath(), "") + section.getFileString())); + Arrays.stream(Message.values()).forEach((message) -> outputMap.put(message.getSection().getPath(), + outputMap.getOrDefault(message.getSection().getPath(), "") + message.getFileString())); break; } @@ -181,7 +182,14 @@ public void save() { } private void addKeyValue(String node, Object value) { - if (config.get(node) == null || (config.get(node) != null && config.get(node).toString().isEmpty())) { + if (value instanceof Map) { + for (Map.Entry entry : ((Map) value).entrySet()) { + String newNode = node + "." + entry.getKey().toString(); + if (config.get(newNode) == null || (config.get(newNode) != null && config.get(newNode).toString().isEmpty())) { + config.set(newNode, entry.getValue().toString()); + } + } + } else if (config.get(node) == null || (config.get(node) != null && config.get(node).toString().isEmpty())) { config.set(node, value); } } diff --git a/src/main/java/org/shanerx/tradeshop/data/config/Setting.java b/src/main/java/org/shanerx/tradeshop/data/config/Setting.java index efc2ed42..79e24074 100644 --- a/src/main/java/org/shanerx/tradeshop/data/config/Setting.java +++ b/src/main/java/org/shanerx/tradeshop/data/config/Setting.java @@ -28,11 +28,12 @@ import org.bukkit.Bukkit; import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.item.IllegalItemList; +import org.shanerx.tradeshop.shop.ShopSign; import org.yaml.snakeyaml.Yaml; import java.util.Arrays; import java.util.List; -import java.util.Objects; +import java.util.Map; public enum Setting { @@ -81,7 +82,8 @@ public enum Setting { ALLOW_USER_PURCHASING(SettingSection.SHOP_OPTIONS, "allow-user-purchasing", false), MULTIPLE_ITEMS_ON_SIGN(SettingSection.SHOP_OPTIONS, "multiple-items-on-sign", "Use '/ts what'"), - //Shop Item Default Setting Options + //region Shop Item Settings + //------------------------------------------------------------------------------------------------------------------ COMPARE_DURABILITY_DEFAULT(SettingSection.COMPARE_DURABILITY, "default", 1), COMPARE_ENCHANTMENTS_DEFAULT(SettingSection.COMPARE_ENCHANTMENTS, "default", true), COMPARE_NAME_DEFAULT(SettingSection.COMPARE_NAME, "default", true), @@ -113,6 +115,16 @@ public enum Setting { COMPARE_FIREWORK_DURATION_USER_EDITABLE(SettingSection.COMPARE_FIREWORK_DURATION, "user-editable", true), COMPARE_FIREWORK_EFFECTS_USER_EDITABLE(SettingSection.COMPARE_FIREWORK_EFFECTS, "user-editable", true), + //------------------------------------------------------------------------------------------------------------------ + //endregion + + //region Shop Sign Settings + //------------------------------------------------------------------------------------------------------------------ + SHOP_SIGN_DEFAULT_COLOURS(SettingSection.SHOP_SIGN_OPTIONS, "sign-default-colours", ShopSign.getDefaultColourMap()), + + //------------------------------------------------------------------------------------------------------------------ + //endregion + // Trade Shop Options TRADESHOP_HEADER(SettingSection.TRADE_SHOP_OPTIONS, "header", "Trade"), TRADESHOP_EXPLODE(SettingSection.TRADE_SHOP_OPTIONS, "allow-explode", false), @@ -140,7 +152,7 @@ public enum Setting { PRODUCT_ILLEGAL_ITEMS_TYPE(SettingSection.PRODUCT_ILLEGAL_ITEMS, "type", IllegalItemList.ListType.DISABLED.toString()), PRODUCT_ILLEGAL_ITEMS_LIST(SettingSection.PRODUCT_ILLEGAL_ITEMS, "list", new String[]{}); - public static final TradeShop PLUGIN = Objects.requireNonNull((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop")); + public static final TradeShop PLUGIN = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop"); private final String key, path; private final Object defaultValue; @@ -239,6 +251,10 @@ public Object getDefaultValue() { return defaultValue; } + public String getMappedString(String subKey) { + return PLUGIN.getSettingManager().getConfig().getConfigurationSection(getPath()).getString(subKey.toLowerCase().replace("_", "-")); + } + public String getPostComment() { return PLUGIN.getLanguage().getPostComment(Language.LangSection.SETTING, path); } @@ -262,7 +278,14 @@ public String getFileString() { keyOutput.append(section.getSectionLead()).append("# ").append(PLUGIN.getSettingManager().fixCommentNewLines(section.getSectionLead(), getPreComment())).append("\n"); } - keyOutput.append(section.getSectionLead()).append(getKey()).append(": ").append(new Yaml().dump(getSetting())); + if (defaultValue instanceof Map) { + keyOutput.append(section.getSectionLead()).append(getKey()).append(":\n"); + for (Map.Entry entry : ((Map) defaultValue).entrySet()) { + keyOutput.append(section.getSectionLead() + " ").append(entry.getKey().toString()).append(": ").append(new Yaml().dump(entry.getValue())); + } + } else { + keyOutput.append(section.getSectionLead()).append(getKey()).append(": ").append(new Yaml().dump(getSetting())); + } if (!getPostComment().isEmpty()) { if (getPostComment().equals(" ") || getPostComment().equals("\n")) diff --git a/src/main/java/org/shanerx/tradeshop/data/config/SettingSection.java b/src/main/java/org/shanerx/tradeshop/data/config/SettingSection.java index 6bedaf7d..828b28c1 100644 --- a/src/main/java/org/shanerx/tradeshop/data/config/SettingSection.java +++ b/src/main/java/org/shanerx/tradeshop/data/config/SettingSection.java @@ -32,35 +32,44 @@ public enum SettingSection { + //Weight for primary Sections should start at 0 and each sub-section should start at increments of 50 + NONE(0, ""), SYSTEM_OPTIONS(1, "system-options"), LANGUAGE_OPTIONS(2, "language-options"), GLOBAL_OPTIONS(3, "global-options"), - GLOBAL_MULTI_TRADE(0, GLOBAL_OPTIONS, "multi-trade"), + GLOBAL_MULTI_TRADE(50, GLOBAL_OPTIONS, "multi-trade"), SHOP_OPTIONS(4, "shop-options"), - SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS(0, SHOP_OPTIONS, "shop-item-default-settings-options"), - COMPARE_DURABILITY(0, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-durability"), - COMPARE_ENCHANTMENTS(1, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-enchantments"), - COMPARE_NAME(2, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-name"), - COMPARE_LORE(3, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-lore"), - COMPARE_CUSTOM_MODEL_DATA(4, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-custom-data-model"), - COMPARE_ITEM_FLAGS(5, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-item-flags"), - COMPARE_UNBREAKABLE(6, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-unbreakable"), - COMPARE_ATTRIBUTE_MODIFIER(7, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-attribute-modifier"), - COMPARE_BOOK_AUTHOR(8, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-book-author"), - COMPARE_BOOK_PAGES(9, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-book-pages"), - COMPARE_SHULKER_INVENTORY(10, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-shulker-inventory"), - COMPARE_BUNDLE_INVENTORY(11, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-bundle-inventory"), - COMPARE_FIREWORK_DURATION(12, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-firework-duration"), - COMPARE_FIREWORK_EFFECTS(13, SHOP_ITEM_DEFAULT_SETTINGS_OPTIONS, "compare-firework-effects"), + + //region Shop Item Settings + //------------------------------------------------------------------------------------------------------------------ + SHOP_ITEM_SETTINGS(50, SHOP_OPTIONS, "shop-item-default-settings-options"), + COMPARE_DURABILITY(100, SHOP_ITEM_SETTINGS, "compare-durability"), + COMPARE_ENCHANTMENTS(101, SHOP_ITEM_SETTINGS, "compare-enchantments"), + COMPARE_NAME(102, SHOP_ITEM_SETTINGS, "compare-name"), + COMPARE_LORE(103, SHOP_ITEM_SETTINGS, "compare-lore"), + COMPARE_CUSTOM_MODEL_DATA(104, SHOP_ITEM_SETTINGS, "compare-custom-data-model"), + COMPARE_ITEM_FLAGS(105, SHOP_ITEM_SETTINGS, "compare-item-flags"), + COMPARE_UNBREAKABLE(106, SHOP_ITEM_SETTINGS, "compare-unbreakable"), + COMPARE_ATTRIBUTE_MODIFIER(107, SHOP_ITEM_SETTINGS, "compare-attribute-modifier"), + COMPARE_BOOK_AUTHOR(108, SHOP_ITEM_SETTINGS, "compare-book-author"), + COMPARE_BOOK_PAGES(109, SHOP_ITEM_SETTINGS, "compare-book-pages"), + COMPARE_SHULKER_INVENTORY(110, SHOP_ITEM_SETTINGS, "compare-shulker-inventory"), + COMPARE_BUNDLE_INVENTORY(111, SHOP_ITEM_SETTINGS, "compare-bundle-inventory"), + COMPARE_FIREWORK_DURATION(112, SHOP_ITEM_SETTINGS, "compare-firework-duration"), + COMPARE_FIREWORK_EFFECTS(113, SHOP_ITEM_SETTINGS, "compare-firework-effects"), + //------------------------------------------------------------------------------------------------------------------ + //endregion + + SHOP_SIGN_OPTIONS(5, "shop-sign-options"), TRADE_SHOP_OPTIONS(6, "trade-shop-options"), ITRADE_SHOP_OPTIONS(7, "itrade-shop-options"), BITRADE_SHOP_OPTIONS(8, "bitrade-shop-options"), ILLEGAL_ITEM_OPTIONS(9, "illegal-item-options"), - GLOBAL_ILLEGAL_ITEMS(0, ILLEGAL_ITEM_OPTIONS, "global-illegal-items"), - COST_ILLEGAL_ITEMS(1, ILLEGAL_ITEM_OPTIONS, "cost-illegal-items"), - PRODUCT_ILLEGAL_ITEMS(2, ILLEGAL_ITEM_OPTIONS, "product-illegal-items"); + GLOBAL_ILLEGAL_ITEMS(50, ILLEGAL_ITEM_OPTIONS, "global-illegal-items"), + COST_ILLEGAL_ITEMS(51, ILLEGAL_ITEM_OPTIONS, "cost-illegal-items"), + PRODUCT_ILLEGAL_ITEMS(52, ILLEGAL_ITEM_OPTIONS, "product-illegal-items"); public static final TradeShop PLUGIN = Objects.requireNonNull((TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop")); diff --git a/src/main/java/org/shanerx/tradeshop/shop/Shop.java b/src/main/java/org/shanerx/tradeshop/shop/Shop.java index 1d21b25b..3c7cf51a 100644 --- a/src/main/java/org/shanerx/tradeshop/shop/Shop.java +++ b/src/main/java/org/shanerx/tradeshop/shop/Shop.java @@ -59,7 +59,7 @@ public class Shop implements Serializable { private ShopUser owner; - private List managers, members; + private Set managers, members; private ShopType shopType; private final ShopLocation shopLoc; private List product, cost; @@ -79,7 +79,7 @@ public class Shop implements Serializable { * @param items Items to go into the shop as Tuple, left = Product, right = Cost * @param players Users to be added to the shop as Tuple, left = Managers, right = Members */ - public Shop(Tuple locations, ShopType shopType, ShopUser owner, Tuple, List> players, Tuple items) { + public Shop(Tuple locations, ShopType shopType, ShopUser owner, Tuple, Set> players, Tuple items) { shopLoc = new ShopLocation(locations.getLeft()); this.owner = owner; @@ -90,8 +90,8 @@ public Shop(Tuple locations, ShopType shopType, ShopUser own this.shopType = shopType; - managers = players.getLeft() == null ? Collections.emptyList() : players.getLeft(); - members = players.getRight() == null ? Collections.emptyList() : players.getRight(); + managers = players.getLeft() == null ? Collections.emptySet() : players.getLeft(); + members = players.getRight() == null ? Collections.emptySet() : players.getRight(); product = new ArrayList<>(); cost = new ArrayList<>(); @@ -320,6 +320,15 @@ public void saveShop() { updateUserFiles(); } + /** + * Saves the shop to file if passed boolean is true + * + * @param shouldSave true if save should proceed + */ + public void saveShop(boolean shouldSave) { + if (shouldSave) saveShop(); + } + /** * Returns the shops sign as a Sign * @@ -344,7 +353,7 @@ public void updateSign() { if (s == null) return; - String[] signLines = updateSignLines(); + String[] signLines = updateSignLines(Setting.SHOP_SIGN_DEFAULT_COLOURS.getMappedString(Signs.match(s.getType()).name())); for (int i = 0; i < 4; i++) { s.setLine(i, signLines[i]); @@ -360,7 +369,7 @@ public void updateSign(SignChangeEvent event) { if (event == null || !event.getBlock().getLocation().equals(getShopLocation())) return; - String[] signLines = updateSignLines(); + String[] signLines = updateSignLines(Setting.SHOP_SIGN_DEFAULT_COLOURS.getMappedString(Signs.match(event.getBlock().getType()).name())); for (int i = 0; i < 4; i++) { event.setLine(i, signLines[i]); @@ -374,7 +383,7 @@ public void updateSign(Sign sign) { if (sign == null || !sign.getLocation().equals(getShopLocation())) return; - String[] signLines = updateSignLines(); + String[] signLines = updateSignLines(Setting.SHOP_SIGN_DEFAULT_COLOURS.getMappedString(Signs.match(sign.getType()).name())); for (int i = 0; i < 4; i++) { sign.setLine(i, signLines[i]); @@ -383,12 +392,12 @@ public void updateSign(Sign sign) { sign.update(); } - /** - * Updates the text for the shop signs - * - * @return String array containing updated sign lines to be set - */ - private String[] updateSignLines() { + /** + * Updates the text for the shop signs + * + * @return String array containing updated sign lines to be set + */ + private String[] updateSignLines(String defaultColour) { String[] signLines = new String[4]; signLines[0] = utils.colorize((isMissingItems() ? Setting.SHOP_INCOMPLETE_COLOUR : Setting.SHOP_GOOD_COLOUR).getString() + shopType.toHeader()); @@ -405,10 +414,10 @@ private String[] updateSignLines() { sb.append(item.getCleanItemName()); - signLines[1] = sb.substring(0, Math.min(sb.length(), 15)); + signLines[1] = utils.colorize(defaultColour + sb.substring(0, Math.min(sb.length(), 15))); - } else { - signLines[1] = Setting.MULTIPLE_ITEMS_ON_SIGN.getString().replace("%amount%", ""); + } else { + signLines[1] = utils.colorize(defaultColour + Setting.MULTIPLE_ITEMS_ON_SIGN.getString().replace("%amount%", "")); } if (cost.isEmpty()) { @@ -428,8 +437,8 @@ private String[] updateSignLines() { signLines[2] = Setting.MULTIPLE_ITEMS_ON_SIGN.getString(); } - signLines[1] = ChatColor.stripColor(signLines[1]); - signLines[2] = ChatColor.stripColor(signLines[2]); + signLines[1] = utils.colorize(defaultColour + ChatColor.stripColor(signLines[1])); + signLines[2] = utils.colorize(defaultColour + ChatColor.stripColor(signLines[2])); updateStatus(); @@ -742,7 +751,7 @@ public boolean addUser(UUID newUser, ShopRole role) { } } - if (ret) saveShop(); + saveShop(ret); return ret; } @@ -794,7 +803,7 @@ public boolean removeUser(UUID oldUser) { ret = true; } - saveShop(); + saveShop(ret); return ret; } @@ -804,7 +813,7 @@ public boolean removeUser(UUID oldUser) { * * @param users the managers to be set to the shop */ - public boolean setUsers(List users, ShopRole role) { + public boolean setUsers(Set users, ShopRole role) { boolean ret = false; switch (role) { case MANAGER: @@ -817,7 +826,7 @@ public boolean setUsers(List users, ShopRole role) { ret = true; } - if (ret) saveShop(); + saveShop(ret); return ret; } diff --git a/src/main/java/org/shanerx/tradeshop/shop/ShopSign.java b/src/main/java/org/shanerx/tradeshop/shop/ShopSign.java index 10ae2863..fdbdfab8 100644 --- a/src/main/java/org/shanerx/tradeshop/shop/ShopSign.java +++ b/src/main/java/org/shanerx/tradeshop/shop/ShopSign.java @@ -32,33 +32,30 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; enum Signs { - SIGN("", "1.13.2"), - OAK_SIGN("1.14.0", ""), - SPRUCE_SIGN("1.14.0", ""), - BIRCH_SIGN("1.14.0", ""), - JUNGLE_SIGN("1.14.0", ""), - ACACIA_SIGN("1.14.0", ""), - DARK_OAK_SIGN("1.14.0", ""), - CRIMSON_SIGN("1.16.0", ""), - WARPED_SIGN("1.16.0", ""), - WALL_SIGN("", "1.13.2"), - OAK_WALL_SIGN("1.14.0", ""), - SPRUCE_WALL_SIGN("1.14.0", ""), - BIRCH_WALL_SIGN("1.14.0", ""), - JUNGLE_WALL_SIGN("1.14.0", ""), - ACACIA_WALL_SIGN("1.14.0", ""), - DARK_OAK_WALL_SIGN("1.14.0", ""), - CRIMSON_WALL_SIGN("1.16.0", ""), - WARPED_WALL_SIGN("1.16.0", ""); + SIGN("", "1.13.2", "&0"), + OAK_SIGN("1.14.0", "", "&0"), + SPRUCE_SIGN("1.14.0", "", "&0"), + BIRCH_SIGN("1.14.0", "", "&0"), + JUNGLE_SIGN("1.14.0", "", "&0"), + ACACIA_SIGN("1.14.0", "", "&0"), + DARK_OAK_SIGN("1.14.0", "", "&f"), + CRIMSON_SIGN("1.16.0", "", "&0"), + WARPED_SIGN("1.16.0", "", "&0"), + MANGROVE_SIGN("1.19.0", "", "&0"); private final List minVer = Arrays.asList(new Integer[3]); private final List maxVer = Arrays.asList(new Integer[3]); private boolean hasMin = true, hasMax = true; + private final String defaultColour; + + Signs(String minVersion, String maxVersion, String defaultColour) { + this.defaultColour = defaultColour; - Signs(String minVersion, String maxVersion) { if (minVersion.equalsIgnoreCase("")) hasMin = false; @@ -104,6 +101,13 @@ public String getMaxVersionAsString() { return hasMaxVersion() ? getMaxVer().get(0) + "." + getMaxVer().get(1) + "." + getMaxVer().get(2) : "None"; } + public static Signs match(Material mat) { + return valueOf(mat.toString().replace("WALL_", "")); + } + + public String getDefaultColour() { + return defaultColour; + } } public class ShopSign extends Utils { @@ -124,16 +128,32 @@ public ShopSign() { pass = false; } - if (pass) + if (pass) { signTypes.add(Material.matchMaterial(type.toString())); + signTypes.add(Material.matchMaterial(type.toString().toUpperCase().replace("_SIGN", "_WALL_SIGN"))); + } } - - } public List getSignTypes() { return signTypes; } + public static Map getDefaultColourMap() { + final BukkitVersion version = new BukkitVersion(); + Map colourMap = new HashMap<>(); + + for (Signs value : Signs.values()) { + String key = value.name().toLowerCase().replace("_", "-"); + + colourMap.put(key, value.getDefaultColour()); + if (value.hasMinVersion() && version.isBelow(value.getMinVer().get(0), value.getMinVer().get(1), value.getMinVer().get(2))) + colourMap.remove(key); + if (value.hasMaxVersion() && version.isAbove(value.getMaxVer().get(0), value.getMaxVer().get(1), value.getMaxVer().get(2))) + colourMap.remove(key); + } + + return colourMap; + } } \ No newline at end of file diff --git a/src/main/java/org/shanerx/tradeshop/shop/listeners/ShopTradeListener.java b/src/main/java/org/shanerx/tradeshop/shop/listeners/ShopTradeListener.java index d22acbf2..43d547f7 100644 --- a/src/main/java/org/shanerx/tradeshop/shop/listeners/ShopTradeListener.java +++ b/src/main/java/org/shanerx/tradeshop/shop/listeners/ShopTradeListener.java @@ -139,8 +139,12 @@ public void onBlockInteract(PlayerInteractEvent e) { break; } - List searchResult = getItems(shop.getChestAsSC().getInventory().getStorageContents(), shop.getSideList(ShopItemSide.PRODUCT, doBiTradeAlternate), multiplier); - Message.SHOP_INSUFFICIENT_ITEMS.sendItemMultiLineMessage(buyer, Collections.singletonMap(Variable.MISSING_ITEMS, searchResult)); + if (shop.hasSide(ShopItemSide.PRODUCT)) { + List searchResult = getItems(shop.getChestAsSC().getInventory().getStorageContents(), shop.getSideList(ShopItemSide.PRODUCT, doBiTradeAlternate), multiplier); + Message.SHOP_INSUFFICIENT_ITEMS.sendItemMultiLineMessage(buyer, Collections.singletonMap(Variable.MISSING_ITEMS, searchResult)); + } else { + Message.SHOP_EMPTY.sendMessage(buyer); + } return; case OPEN: break; diff --git a/src/main/resources/Lang/en-us.yml b/src/main/resources/Lang/en-us.yml index 69ed1666..eea3bb34 100644 --- a/src/main/resources/Lang/en-us.yml +++ b/src/main/resources/Lang/en-us.yml @@ -60,6 +60,8 @@ setting-section: compare-firework-effects: header: "" pre-comment: "Compare Firework Effects" + shop-sign-options: + header: "Shop Sign Options" trade-shop-options: header: "Trade Shop Options" itrade-shop-options: @@ -240,7 +242,11 @@ setting: default: pre-comment: "" user-editable: - pre-comment: "" + post-comment: "\n" + shop-sign-options: + sign-default-colours: + pre-comment: "What colour should be used for line 2/3 on shop signs per each material type." + post-comment: "\n" trade-shop-options: header: pre-comment: "The header that appears at the top of the shop signs, this is also what the player types to create the sign" @@ -391,7 +397,7 @@ message: too-many-items: default: "&cThis shop cannot take any more %SIDE% items!" updated-shop-users: - default: "&aShop users have tried to update for the below shops! \n{%UPDATED_SHOPS%= %SHOP% -|- %STATUS%}" + default: "&aShop users have tried to update for the below shops! \n{%UPDATEDSHOPS%= %SHOP% -|- %STATUS%}" pre-comment: "Text to display when shop users have been updated." updated-shop-users-successful: default: "&aSuccessful"