From 8d37290cff9e49ed4e057032f5a49affc7f4115c Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Sat, 9 Mar 2024 08:06:14 +0800 Subject: [PATCH] custom placeholder register --- .../manager/PlaceholderManagerImpl.java | 15 +++++++++++++++ .../mechanic/item/ItemManagerImpl.java | 6 ++++++ plugin/src/main/resources/config.yml | 4 ++++ .../src/main/resources/contents/crops/default.yml | 1 + .../resources/contents/sprinklers/default.yml | 6 +++--- .../src/main/resources/contents/utils/default.yml | 0 6 files changed, 29 insertions(+), 3 deletions(-) delete mode 100644 plugin/src/main/resources/contents/utils/default.yml diff --git a/plugin/src/main/java/net/momirealms/customcrops/manager/PlaceholderManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/manager/PlaceholderManagerImpl.java index 6df2ed1..9a586c4 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/manager/PlaceholderManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/manager/PlaceholderManagerImpl.java @@ -4,7 +4,10 @@ import net.momirealms.customcrops.api.CustomCropsPlugin; import net.momirealms.customcrops.api.manager.PlaceholderManager; import net.momirealms.customcrops.compatibility.papi.CCPapi; import net.momirealms.customcrops.compatibility.papi.ParseUtils; +import net.momirealms.customcrops.utils.ConfigUtils; import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -36,6 +39,7 @@ public class PlaceholderManagerImpl extends PlaceholderManager { if (ccPapi != null) { ccPapi.register(); } + this.loadCustomPlaceholders(); } @Override @@ -43,6 +47,17 @@ public class PlaceholderManagerImpl extends PlaceholderManager { if (ccPapi != null) { ccPapi.unregister(); } + this.customPlaceholderMap.clear(); + } + + public void loadCustomPlaceholders() { + YamlConfiguration config = ConfigUtils.getConfig("config.yml"); + ConfigurationSection section = config.getConfigurationSection("other-settings.placeholder-register"); + if (section != null) { + for (Map.Entry entry : section.getValues(false).entrySet()) { + this.customPlaceholderMap.put(entry.getKey(), (String) entry.getValue()); + } + } } @Override diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java index b87036c..7a69086 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java @@ -311,6 +311,12 @@ public class ItemManagerImpl implements ItemManager { LogUtils.warn("Item " + sprinkler.get3DItemID() + " has more than one sprinkler config."); return false; } + if (sprinkler.get3DItemWithWater() != null) { + if (this.threeDItem2SprinklerMap.put(sprinkler.get3DItemWithWater(), sprinkler) != null) { + LogUtils.warn("Item " + sprinkler.get3DItemWithWater() + " has more than one sprinkler config."); + return false; + } + } return true; } diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index fc20fb6..650a68d 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -130,6 +130,10 @@ other-settings: # Disable this would improve performance legacy-color-code-support: true + # Requires PlaceholderAPI to work + placeholder-register: + '{skill-level}': '%levelplugin_farming%' + # Thread pool settings thread-pool-settings: corePoolSize: 10 diff --git a/plugin/src/main/resources/contents/crops/default.yml b/plugin/src/main/resources/contents/crops/default.yml index 6107aec..2e1fcb2 100644 --- a/plugin/src/main/resources/contents/crops/default.yml +++ b/plugin/src/main/resources/contents/crops/default.yml @@ -158,6 +158,7 @@ tomato: # But you can set some special crops' loots here 99: model: {0}tomato_stage_golden + # You can set interact/break requirements for each stage requirements: break: requirement_1: diff --git a/plugin/src/main/resources/contents/sprinklers/default.yml b/plugin/src/main/resources/contents/sprinklers/default.yml index 3fec79c..2a277fc 100644 --- a/plugin/src/main/resources/contents/sprinklers/default.yml +++ b/plugin/src/main/resources/contents/sprinklers/default.yml @@ -31,7 +31,7 @@ sprinkler_1: # The amount of water to add amount: 3 method_2: - item: WATER + item: POTION return: GLASS_BOTTLE amount: 1 # Water bar image settings @@ -119,7 +119,7 @@ sprinkler_2: return: BUCKET amount: 3 method_2: - item: WATER + item: POTION return: GLASS_BOTTLE amount: 1 water-bar: @@ -207,7 +207,7 @@ sprinkler_3: return: BUCKET amount: 3 method_2: - item: WATER + item: POTION return: GLASS_BOTTLE amount: 1 water-bar: diff --git a/plugin/src/main/resources/contents/utils/default.yml b/plugin/src/main/resources/contents/utils/default.yml deleted file mode 100644 index e69de29..0000000