From 66ce7da7e24fcc9f084756ea14a4e3738efdf616 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Fri, 17 Jan 2025 23:50:11 +0800 Subject: [PATCH] 2.3.2 --- .../api/mechanic/context/ContextKeys.java | 1 - .../api/mechanic/totem/ActiveTotemList.java | 4 +++- .../customfishing/common/util/ListUtils.java | 2 +- .../bukkit/config/BukkitConfigManager.java | 9 ++++++-- .../bukkit/game/BukkitGameManager.java | 1 + .../bukkit/market/BukkitMarketManager.java | 21 ++++++++++++++++--- .../bukkit/market/MarketGUI.java | 6 ++++++ gradle.properties | 2 +- 8 files changed, 37 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java index 8b06d96c..8e9b2168 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java @@ -24,7 +24,6 @@ import org.bukkit.Location; import org.bukkit.inventory.EquipmentSlot; import java.util.Objects; -import java.util.Set; /** * Represents keys for accessing context values with specific types. diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/ActiveTotemList.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/ActiveTotemList.java index 914f9a12..aa3deca2 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/ActiveTotemList.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/totem/ActiveTotemList.java @@ -17,7 +17,9 @@ package net.momirealms.customfishing.api.mechanic.totem; -import java.util.*; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; public class ActiveTotemList { diff --git a/common/src/main/java/net/momirealms/customfishing/common/util/ListUtils.java b/common/src/main/java/net/momirealms/customfishing/common/util/ListUtils.java index 846f3f84..938f812f 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/util/ListUtils.java +++ b/common/src/main/java/net/momirealms/customfishing/common/util/ListUtils.java @@ -43,6 +43,6 @@ public class ListUtils { } else if (obj instanceof List list) { return (List) list; } - throw new IllegalArgumentException("Cannot convert " + obj + " to a list"); + throw new IllegalArgumentException("Invalid value found. Cannot convert " + obj.getClass().getSimpleName() + " to a list"); } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java index 96f4197c..a851999e 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java @@ -159,6 +159,7 @@ public class BukkitConfigManager extends ConfigManager { .addIgnoredRoute(configVersion, "mechanics.market.sell-all-icons", '.') .addIgnoredRoute(configVersion, "mechanics.market.sell-icons", '.') .addIgnoredRoute(configVersion, "mechanics.market.decorative-icons", '.') + .addIgnoredRoute(configVersion, "mechanics.market.titles", '.') .addIgnoredRoute(configVersion, "other-settings.placeholder-register", '.') .build() ); @@ -300,8 +301,12 @@ public class BukkitConfigManager extends ConfigManager { try { YamlDocument document = plugin.getConfigManager().loadData(subFile); for (Map.Entry entry : document.getStringRouteMappedValues(false).entrySet()) { - if (entry.getValue() instanceof Section section) { - type.parse(entry.getKey(), section, nodes); + try { + if (entry.getValue() instanceof Section section) { + type.parse(entry.getKey(), section, nodes); + } + } catch (Exception e) { + plugin.getPluginLogger().warn("Invalid config " + subFile.getPath() + " - Failed to parse section " + entry.getKey(), e); } } } catch (ConstructorException e) { diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java index 8af92e97..4e55ec12 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java @@ -86,6 +86,7 @@ public class BukkitGameManager implements GameManager { @Override public void unload() { this.gameMap.clear(); + this.gameConditions.clear(); } private ConditionalElement>, Player> parseGameConditions(Section section) { diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/market/BukkitMarketManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/market/BukkitMarketManager.java index 8b3e98ae..9369e3ee 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/market/BukkitMarketManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/market/BukkitMarketManager.java @@ -67,6 +67,9 @@ public class BukkitMarketManager implements MarketManager, Listener { protected boolean sellFishingBag; protected TextValue title; + protected TextValue denyTitle; + protected TextValue allowTitle; + protected TextValue limitTitle; protected String[] layout; protected final HashMap[]>> decorativeIcons; protected final ConcurrentHashMap marketGUICache; @@ -74,7 +77,6 @@ public class BukkitMarketManager implements MarketManager, Listener { protected char itemSlot; protected char sellSlot; protected char sellAllSlot; - protected char closeSlot; protected CustomFishingItem sellIconAllowItem; protected CustomFishingItem sellIconDenyItem; @@ -137,7 +139,8 @@ public class BukkitMarketManager implements MarketManager, Listener { this.formula = config.getString("price-formula", "{base} + {bonus} * {size}"); this.layout = config.getStringList("layout").toArray(new String[0]); - this.title = TextValue.auto(config.getString("title", "market.title")); + String defaultTitle = config.getString("title", "mechanics.market.title"); + this.title = TextValue.auto(defaultTitle); this.itemSlot = config.getString("item-slot.symbol", "I").charAt(0); this.allowItemWithNoPrice = config.getBoolean("item-slot.allow-items-with-no-price", true); this.allowBundle = config.getBoolean("allow-bundle", true); @@ -198,6 +201,17 @@ public class BukkitMarketManager implements MarketManager, Listener { } } } + + Section titleSection = config.getSection("titles"); + if (titleSection != null) { + this.denyTitle = TextValue.auto(titleSection.getString("deny", defaultTitle)); + this.limitTitle = TextValue.auto(titleSection.getString("limit", defaultTitle)); + this.allowTitle = TextValue.auto(titleSection.getString("allow", defaultTitle)); + } else { + this.denyTitle = null; + this.allowTitle = null; + this.limitTitle = null; + } } /** @@ -220,7 +234,8 @@ public class BukkitMarketManager implements MarketManager, Listener { for (Map.Entry[]>> entry : decorativeIcons.entrySet()) { gui.addElement(new MarketGUIElement(entry.getKey(), entry.getValue().left().build(context))); } - gui.build().refresh().show(); + gui.build().show(); + gui.refresh(); marketGUICache.put(player.getUniqueId(), gui); return true; } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUI.java b/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUI.java index 41d65a8c..4e3f2f3b 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUI.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUI.java @@ -123,10 +123,16 @@ public class MarketGUI { .arg(ContextKeys.SOLD_ITEM_AMOUNT, soldAmount); if (totalWorth <= 0) { sellElement.setItemStack(manager.sellIconDenyItem.build(context)); + if (manager.denyTitle != null) + SparrowHeart.getInstance().updateInventoryTitle(context.holder(), AdventureHelper.componentToJson(AdventureHelper.miniMessage(manager.denyTitle.render(context)))); } else if (earningLimit != -1 && (earningLimit - earningData.earnings < totalWorth)) { sellElement.setItemStack(manager.sellIconLimitItem.build(context)); + if (manager.limitTitle != null) + SparrowHeart.getInstance().updateInventoryTitle(context.holder(), AdventureHelper.componentToJson(AdventureHelper.miniMessage(manager.limitTitle.render(context)))); } else { sellElement.setItemStack(manager.sellIconAllowItem.build(context)); + if (manager.allowTitle != null) + SparrowHeart.getInstance().updateInventoryTitle(context.holder(), AdventureHelper.componentToJson(AdventureHelper.miniMessage(manager.allowTitle.render(context)))); } } diff --git a/gradle.properties b/gradle.properties index 972f315e..40c21c41 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=2.3.1 +project_version=2.3.2 config_version=38 project_group=net.momirealms