From e2e64cefbf8abea05c9407d9c5ad8a6a1e0a93f8 Mon Sep 17 00:00:00 2001 From: Jules Date: Thu, 16 May 2024 17:52:49 -0700 Subject: [PATCH] For safety, a server restart is now required for changes to custom stats to apply --- .../java/net/Indyuce/mmoitems/MMOItems.java | 4 +- .../Indyuce/mmoitems/manager/StatManager.java | 38 +++++++++---------- .../mmoitems/stat/ActionLeftClick.java | 1 - .../stat/type/FictiveNumericStat.java | 6 +-- .../main/resources/default/custom-stats.yml | 11 ++++-- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java index 61f56148..eb21393c 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -118,7 +118,7 @@ public class MMOItems extends MMOPlugin { saveDefaultConfig(); configManager = new ConfigManager(); - statManager.load(); + statManager.loadInternalStats(); typeManager.reload(false); templateManager.preloadObjects(); @@ -166,7 +166,7 @@ public class MMOItems extends MMOPlugin { * After tiers, sets and upgrade templates are loaded, MI template data * can be fully loaded */ - statManager.loadElements(); + statManager.loadElements(); // Why is this call made there? loreManager.reload(); tierManager = new TierManager(); setManager = new SetManager(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java index 3cb55a47..9a79384e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/StatManager.java @@ -2,6 +2,7 @@ package net.Indyuce.mmoitems.manager; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.element.Element; +import io.lumine.mythic.lib.util.annotation.BackwardsCompatibility; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ConfigFile; @@ -24,9 +25,11 @@ public class StatManager { private final Map> stats = new LinkedHashMap<>(); /** - * TODO refactor with stat categories + * If, for whatever reason, a stat needs to change its internal + * string ID, this map keeps a reference for the deprecated old + * IDs while being separated from the main ItemStat map. */ - @Deprecated + @BackwardsCompatibility(version = "unknown") private final Map> legacyAliases = new HashMap<>(); /* @@ -39,14 +42,11 @@ public class StatManager { private final List consumableActions = new ArrayList<>(); private final List playerConsumables = new ArrayList<>(); - /** * Load default stats using java reflection, get all public static final * fields in the ItemStat and register them as stat instances - *

- * TODO refactor */ - public void load() { + public void loadInternalStats() { for (Field field : ItemStats.class.getFields()) try { if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && field.get(null) instanceof ItemStat) @@ -56,26 +56,20 @@ public class StatManager { } // Custom stats - loadCustom(); + loadCustomStats(); } - /** - * @see FictiveNumericStat - *

- * TODO refactor - */ + // TODO refactor with stat categories public void reload(boolean cleanFirst) { // Clean fictive numeric stats before - if (cleanFirst) { - numeric.removeIf(stat -> stat instanceof FictiveNumericStat); - loadCustom(); // Already loaded on plugin startup - } + if (cleanFirst) + numeric.removeIf(stat -> stat instanceof FictiveNumericStat); // temporary fix, this is for elements. // Register elemental stats loadElements(); - // Load stat translation objects + // Load stat translation objects (nothing to do with stats) final ConfigurationSection statOptions = new ConfigFile("/language", "stats").getConfig(); for (ItemStat stat : getAll()) try { @@ -89,10 +83,8 @@ public class StatManager { /** * Load custom stats - *

- * TODO refactor */ - public void loadCustom() { + private void loadCustomStats() { ConfigManager.DefaultFile.CUSTOM_STATS.checkFile(); ConfigFile config = new ConfigFile("custom-stats"); ConfigurationSection section = config.getConfig().getConfigurationSection("custom-stats"); @@ -103,7 +95,7 @@ public class StatManager { /** * Register all MythicLib elements as stats *

- * TODO refactor + * TODO refactor with stat categories */ public void loadElements() { for (ElementStatType type : ElementStatType.values()) @@ -195,6 +187,10 @@ public class StatManager { * @param stat The stat to register */ public void register(@NotNull ItemStat stat) { + register(stat, false); + } + + private void register(@NotNull ItemStat stat, boolean customStat) { // Skip disabled stats. if (!stat.isEnabled()) return; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ActionLeftClick.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ActionLeftClick.java index fa4d511f..7ec14c1a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ActionLeftClick.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ActionLeftClick.java @@ -41,7 +41,6 @@ public class ActionLeftClick extends StringStat { public static final String LEGACY_ID = "STAFF_SPIRIT"; public static final String LEGACY_PATH = "MMOITEMS_" + LEGACY_ID; - // TODO refactor with stat categories @Override @Deprecated public void whenLoaded(@NotNull ReadMMOItem mmoitem) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/FictiveNumericStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/FictiveNumericStat.java index 73f1ef68..373fd8cc 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/FictiveNumericStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/FictiveNumericStat.java @@ -19,10 +19,10 @@ import java.util.Optional; /** * Used for elements otherwise MMOItems doesn't - * register elemental stats inside of MythicLib + * register elemental stats inside MythicLib *

- * Workaround that will be removed when adding stat categories - * in order to give more clarity to the item editor. + * TODO Workaround that will be removed when adding stat categories + * TODO in order to give more clarity to the item editor. * * @deprecated Definitely not a perfect implementation */ diff --git a/MMOItems-Dist/src/main/resources/default/custom-stats.yml b/MMOItems-Dist/src/main/resources/default/custom-stats.yml index 9224b6f0..ca903112 100644 --- a/MMOItems-Dist/src/main/resources/default/custom-stats.yml +++ b/MMOItems-Dist/src/main/resources/default/custom-stats.yml @@ -1,7 +1,10 @@ -# Add as many custom stats as you want below -# - +# Add as many custom stats as you want below. +# # For each custom stat you add, you must also add a corresponding -# entry in the lore-format.yml and stats.yml files +# entry in the lore-format.yml and stats.yml files. +# +# Item stats are not reloaded when using /mi reload. Make sure +# you restart your server when applying any changes to them. custom-stats: # The key doesn't really matter, although it must be unique @@ -13,7 +16,7 @@ custom-stats: # Allowed stats type: # - double (numbers) - # - text (Will not work as placeholder. You have get this value from ntb tag of the item with your custom plugin) + # - text type: "double" # The lore must be a list of strings