From b6dd16524ed2ff887a66296678f85a14fd0d22d1 Mon Sep 17 00:00:00 2001 From: XZot1K Date: Sat, 22 Jul 2023 13:11:56 -0400 Subject: [PATCH] **Build 6** * Fixed API dependency. * Fixed the visit menu not properly determining when to show a shop. * Fixed the "HIDE_DYE" attribute throwing errors for MC versions under 1.13. Signed-off-by: Jeremiah Osborne --- Core/dependency-reduced-pom.xml | 4 ++-- Core/pom.xml | 4 ++-- .../java/xzot1k/plugins/ds/DisplayShops.java | 2 -- .../java/xzot1k/plugins/ds/api/DManager.java | 18 +++++++++++------- .../plugins/ds/api/objects/CustomItem.java | 4 +--- .../java/xzot1k/plugins/ds/core/Commands.java | 6 ++++-- .../ds/core/tasks/ShopVisitItemTask.java | 11 ++++++++++- pom.xml | 4 ++-- 8 files changed, 32 insertions(+), 21 deletions(-) diff --git a/Core/dependency-reduced-pom.xml b/Core/dependency-reduced-pom.xml index f8de8a9..e089d96 100644 --- a/Core/dependency-reduced-pom.xml +++ b/Core/dependency-reduced-pom.xml @@ -86,13 +86,13 @@ net.md-5 bungeecord-api - 1.19-R0.1-SNAPSHOT + 1.20-R0.1-SNAPSHOT provided io.papermc.paper paper-api - 1.19.3-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT provided diff --git a/Core/pom.xml b/Core/pom.xml index 7f40862..f1ecf31 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -94,8 +94,8 @@ - com.github.XZot1K - DisplayShopsAPI + xzot1k.plugins.ds + API ${api.version} compile diff --git a/Core/src/main/java/xzot1k/plugins/ds/DisplayShops.java b/Core/src/main/java/xzot1k/plugins/ds/DisplayShops.java index 48adc62..f3b023d 100644 --- a/Core/src/main/java/xzot1k/plugins/ds/DisplayShops.java +++ b/Core/src/main/java/xzot1k/plugins/ds/DisplayShops.java @@ -677,8 +677,6 @@ private void setupVaultEconomy() { RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) return; - System.out.println(rsp.getPlugin().getName()); - setVaultEconomy(rsp.getProvider()); } diff --git a/Core/src/main/java/xzot1k/plugins/ds/api/DManager.java b/Core/src/main/java/xzot1k/plugins/ds/api/DManager.java index f8c65e1..b720f12 100644 --- a/Core/src/main/java/xzot1k/plugins/ds/api/DManager.java +++ b/Core/src/main/java/xzot1k/plugins/ds/api/DManager.java @@ -2426,17 +2426,21 @@ public Inventory getBaseBlockSelectionMenu(Player player, Shop shop) { private boolean checkShopAgainstFilters(@NotNull Shop shop, @Nullable OfflinePlayer offlinePlayer, @Nullable String currentFilterType, @Nullable String filter) { + final double buyPrice = shop.getBuyPrice(shop.canDynamicPriceChange()), + sellPrice = shop.getSellPrice(shop.canDynamicPriceChange()); + + final boolean failsBuyPriceCheck = (buyPrice >= 0 && (shop.getStock() == 0 || shop.getStock() < shop.getShopItemAmount())), + failsSellPriceCheck = (sellPrice >= 0 && (shop.getStoredBalance() <= 0 || shop.getStock() >= getMaxStock(shop))); + if (shop.getBaseLocation() == null || (!getPluginInstance().getMenusConfig().getBoolean("shop-visit-menu.show-admin-shops") && shop.isAdminShop()) - || shop.getShopItem() == null || ((shop.getStock() == 0 || shop.getStock() < shop.getShopItemAmount()) && shop.getSellPrice(shop.canDynamicPriceChange()) < 0)) - return false; + || shop.getShopItem() == null) return false; if (currentFilterType != null && !currentFilterType.isEmpty()) { - final String buyType = getPluginInstance().getMenusConfig().getString("shop-visit-menu.type-item.buy-type"), - sellType = getPluginInstance().getMenusConfig().getString("shop-visit-menu.type-item.sell-type"); - - if ((currentFilterType.equals(buyType) && shop.getBuyPrice(false) < 0) - || (currentFilterType.equals(sellType) && shop.getSellPrice(false) < 0)) return false; + sellType = getPluginInstance().getMenusConfig().getString("shop-visit-menu.type-item.sell-type"), + bothType = getPluginInstance().getMenusConfig().getString("shop-visit-menu.type-item.both-type"); + if ((currentFilterType.equals(buyType) && failsBuyPriceCheck) || (currentFilterType.equals(sellType) && failsSellPriceCheck) + || (currentFilterType.equals(bothType) && (failsBuyPriceCheck && failsSellPriceCheck))) return false; } if (filter != null) { diff --git a/Core/src/main/java/xzot1k/plugins/ds/api/objects/CustomItem.java b/Core/src/main/java/xzot1k/plugins/ds/api/objects/CustomItem.java index e1d4046..4cb92fe 100644 --- a/Core/src/main/java/xzot1k/plugins/ds/api/objects/CustomItem.java +++ b/Core/src/main/java/xzot1k/plugins/ds/api/objects/CustomItem.java @@ -233,9 +233,7 @@ public CustomItem setItemFlags(List itemFlags) { try { ItemFlag itemFlag = ItemFlag.valueOf(line); itemMeta.addItemFlags(itemFlag); - } catch (Exception e) { - e.printStackTrace(); - } + } catch (Exception ignored) {} } get().setItemMeta(itemMeta); } diff --git a/Core/src/main/java/xzot1k/plugins/ds/core/Commands.java b/Core/src/main/java/xzot1k/plugins/ds/core/Commands.java index fffa4b3..db135b9 100644 --- a/Core/src/main/java/xzot1k/plugins/ds/core/Commands.java +++ b/Core/src/main/java/xzot1k/plugins/ds/core/Commands.java @@ -796,10 +796,12 @@ private void runAdvertise(CommandSender commandSender) { final double buyPrice = shop.getBuyPrice(shop.canDynamicPriceChange()), sellPrice = shop.getSellPrice(shop.canDynamicPriceChange()); - TextComponent textComponent = new TextComponent(getPluginInstance().getManager().color(message.replace("{player}", player.getName()) + TextComponent textComponent = new TextComponent(getPluginInstance().getManager().color(message.replace("{player}", player.getName())) .replace("{item}", getPluginInstance().getManager().getItemName(shop.getShopItem())) + .replace("${buy}", ((buyPrice < 0 && naNotEmpty) ? notApplicable : getPluginInstance().getManager().formatNumber(buyPrice, true))) + .replace("${sell}", ((sellPrice < 0 && naNotEmpty) ? notApplicable : getPluginInstance().getManager().formatNumber(sellPrice, true))) .replace("{buy}", ((buyPrice < 0 && naNotEmpty) ? notApplicable : getPluginInstance().getManager().formatNumber(buyPrice, true))) - .replace("{sell}", ((sellPrice < 0 && naNotEmpty) ? notApplicable : getPluginInstance().getManager().formatNumber(sellPrice, true))))); + .replace("{sell}", ((sellPrice < 0 && naNotEmpty) ? notApplicable : getPluginInstance().getManager().formatNumber(sellPrice, true)))); if (shop.getShopItem() != null) { final ItemTag itemTag = ItemTag.ofNbt(shop.getShopItem().getItemMeta() == null ? null : (getPluginInstance().getServerVersion() > 1_17 ? shop.getShopItem().getItemMeta().getAsString() diff --git a/Core/src/main/java/xzot1k/plugins/ds/core/tasks/ShopVisitItemTask.java b/Core/src/main/java/xzot1k/plugins/ds/core/tasks/ShopVisitItemTask.java index 8feb3d5..672c9c7 100644 --- a/Core/src/main/java/xzot1k/plugins/ds/core/tasks/ShopVisitItemTask.java +++ b/Core/src/main/java/xzot1k/plugins/ds/core/tasks/ShopVisitItemTask.java @@ -71,7 +71,16 @@ private ItemStack buildItem(@NotNull Shop shop) { ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta != null) { - itemMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_DYE, ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE); + + String[] flagNames = {"HIDE_POTION_EFFECTS", "HIDE_DYE", "HIDE_ATTRIBUTES", "HIDE_UNBREAKABLE"}; + for (int i = -1; ++i < flagNames.length; ) { + final String flagName = flagNames[i]; + try { + final ItemFlag flag = ItemFlag.valueOf(flagName); + itemMeta.addItemFlags(flag); + } catch (Exception ignored) {} + } + final String itemName = (shop.getShopItem() != null ? INSTANCE.getManager().getItemName(shop.getShopItem()) : ""), tradeItemName = (!useVault ? ((!forceUse && shop.getTradeItem() != null) ? INSTANCE.getManager().getItemName(shop.getTradeItem()) : INSTANCE.getManager().getItemName(INSTANCE.getManager().buildShopCurrencyItem(1))) : ""); diff --git a/pom.xml b/pom.xml index ef9e09e..c8a9a0d 100644 --- a/pom.xml +++ b/pom.xml @@ -109,7 +109,7 @@ net.md-5 bungeecord-api - 1.19-R0.1-SNAPSHOT + 1.20-R0.1-SNAPSHOT jar provided @@ -117,7 +117,7 @@ io.papermc.paper paper-api - 1.19.3-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT provided