mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-21 09:21:21 +01:00
For safety, a server restart is now required for changes to custom stats to apply
This commit is contained in:
parent
a6b159ad7e
commit
e2e64cefbf
@ -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();
|
||||
|
@ -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<String, ItemStat<?, ?>> 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<String, ItemStat<?, ?>> legacyAliases = new HashMap<>();
|
||||
|
||||
/*
|
||||
@ -39,14 +42,11 @@ public class StatManager {
|
||||
private final List<ConsumableItemInteraction> consumableActions = new ArrayList<>();
|
||||
private final List<PlayerConsumable> playerConsumables = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* Load default stats using java reflection, get all public static final
|
||||
* fields in the ItemStat and register them as stat instances
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* 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;
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
* <p>
|
||||
* 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
|
||||
*/
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user