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 31a2bfa3..0f20a109 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -38,7 +38,6 @@ import net.Indyuce.mmoitems.comp.rpg.McMMOHook; import net.Indyuce.mmoitems.comp.rpg.RPGHandler; import net.Indyuce.mmoitems.gui.PluginInventory; import net.Indyuce.mmoitems.gui.edition.recipe.RecipeBrowserGUI; -import net.Indyuce.mmoitems.gui.listener.GuiListener; import net.Indyuce.mmoitems.listener.*; import net.Indyuce.mmoitems.manager.*; import org.apache.commons.lang.Validate; @@ -79,6 +78,7 @@ public class MMOItems extends JavaPlugin { private final PlayerInventoryHandler inventory = new PlayerInventoryHandler(); private final List stringInputParsers = new ArrayList<>(); private final List> enchantPlugins = new ArrayList<>(); + private final StatManager statManager = new StatManager(); private DropTableManager dropTableManager; private WorldGenManager worldGenManager; @@ -86,7 +86,6 @@ public class MMOItems extends JavaPlugin { private ConfigManager configManager; private BlockManager blockManager; private TierManager tierManager; - private StatManager statManager; private SetManager setManager; private PlaceholderParser placeholderParser = new DefaultPlaceholderParser(); @@ -119,11 +118,7 @@ public class MMOItems extends JavaPlugin { saveDefaultConfig(); configManager = new ConfigManager(); - /* - * Stat manager must be initialized before MMOCore compatibility - * initializes so that MMOCore can register its stats - */ - statManager = new StatManager(); + statManager.load(); typeManager.reload(); templateManager.preloadTemplates(); @@ -187,6 +182,7 @@ public class MMOItems extends JavaPlugin { dropTableManager = new DropTableManager(); worldGenManager = new WorldGenManager(); blockManager = new BlockManager(); + MMOItems.plugin.getStats().reload(false); if (Bukkit.getPluginManager().getPlugin("Vault") != null) vaultSupport = new VaultSupport(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ReloadCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ReloadCommandTreeNode.java index 6625e95b..a9302213 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ReloadCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ReloadCommandTreeNode.java @@ -64,6 +64,7 @@ public class ReloadCommandTreeNode extends CommandTreeNode { MMOItems.plugin.getLayouts().reload(); MMOItems.plugin.getFormats().reload(); MMOItems.plugin.getTemplates().reload(); + MMOItems.plugin.getStats().reload(true); sender.sendMessage(MMOItems.plugin.getPrefix() + MMOItems.plugin.getName() + " " + MMOItems.plugin.getDescription().getVersion() + " reloaded."); sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED 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 c878e3c6..95e69347 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 @@ -1,9 +1,12 @@ package net.Indyuce.mmoitems.manager; +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.element.Element; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.stat.type.*; +import net.Indyuce.mmoitems.util.ElementStatType; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -27,16 +30,37 @@ public class StatManager { * Load default stats using java reflection, get all public static final * fields in the ItemStat and register them as stat instances */ - public StatManager() { + public void load() { for (Field field : ItemStats.class.getFields()) try { if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && field.get(null) instanceof ItemStat) register((ItemStat) field.get(null)); } catch (IllegalArgumentException | IllegalAccessException exception) { - MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't register stat called " + field.getName()); + MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't register stat called '" + field.getName() + "': " + exception.getMessage()); } } + /** + * @see FictiveNumericStat + * @deprecated + */ + @Deprecated + public void reload(boolean cleanFirst) { + + // Clean fictive numeric stats before + if (cleanFirst) + for (Iterator ite = numeric.iterator(); ite.hasNext(); ) { + DoubleStat stat = ite.next(); + if (stat instanceof FictiveNumericStat) + ite.remove(); + } + + // Register elemental stats + for (ElementStatType type : ElementStatType.values()) + for (Element element : MythicLib.plugin.getElements().getAll()) + numeric.add(new FictiveNumericStat(element, type)); + } + public Collection getAll() { return stats.values(); } @@ -85,7 +109,7 @@ public class StatManager { /** * Registers a stat in MMOItems - * + * * @param id Useless. * @param stat The stat instance * @deprecated Stat IDs are now stored in the stat instance directly. @@ -101,7 +125,7 @@ public class StatManager { * Registers a stat in MMOItems. It must be done right after MMOItems loads * before any manager is initialized because stats are commonly used when * loading configs. - * + * * @param stat The stat to register */ public void register(ItemStat stat) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java index 664000ed..d04ed1b4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Elements.java @@ -132,7 +132,7 @@ public class Elements extends ItemStat i // Create Array ArrayList ret = new ArrayList<>(); for (Pair pair : data.getKeys()) - ret.add(new ItemTag("MMOITEMS_" + pair, data.getStat(pair.getKey(), pair.getValue()))); + ret.add(new ItemTag("MMOITEMS_" + pair.getValue().getConcatenatedTagPath(pair.getKey()), data.getStat(pair.getKey(), pair.getValue()))); // Thats it return ret; @@ -145,7 +145,7 @@ public class Elements extends ItemStat i ArrayList relevantTags = new ArrayList<>(); for (Element element : Element.values()) for (ElementStatType statType : ElementStatType.values()) { - final String path = "MMOITEMS_" + element.getName() + "_" + statType.name(); + final String path = "MMOITEMS_" + statType.getConcatenatedTagPath(element); if (mmoitem.getNBT().hasTag(path)) relevantTags.add(ItemTag.getTagAtPath(path, mmoitem.getNBT(), SupportedNBTTagValues.DOUBLE)); } @@ -165,7 +165,6 @@ public class Elements extends ItemStat i // Create new ElementListData elements = new ElementListData(); - boolean success = false; // Try to find every existing element for (Element element : Element.values()) @@ -176,10 +175,7 @@ public class Elements extends ItemStat i elements.setStat(element, statType, (double) tag.getValue()); } - if (success) { - return elements; - } - return null; + return elements.isEmpty() ? null : elements; } @Override diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java index 1fcdb02c..0c081eaa 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ShieldPatternStat.java @@ -69,9 +69,8 @@ public class ShieldPatternStat extends ItemStat + * Workaround that will be removed when adding stat categories + * in order to give more clarity to the item editor. + * + * @deprecated Definitely not a perfect implementation + */ +@Deprecated +public class FictiveNumericStat extends DoubleStat implements InternalStat { + public FictiveNumericStat(Element el, ElementStatType type) { + super(type.getConcatenatedTagPath(el), Material.BARRIER, "Fictive Stat", new String[0]); + } + + @Override + public NumericStatFormula whenInitialized(Object object) { + throw new RuntimeException("Fictive item stat"); + } + + @Override + public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) { + throw new RuntimeException("Fictive item stat"); + } + + @NotNull + @Override + public ArrayList getAppliedNBT(@NotNull DoubleData data) { + throw new RuntimeException("Fictive item stat"); + } + + @Override + public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) { + throw new RuntimeException("Fictive item stat"); + } + + @Override + public void whenLoaded(@NotNull ReadMMOItem mmoitem) { + throw new RuntimeException("Fictive item stat"); + } + + @Nullable + @Override + public DoubleData getLoadedNBT(@NotNull ArrayList storedTags) { + throw new RuntimeException("Fictive item stat"); + } + + @Override + public void whenDisplayed(List lore, Optional statData) { + throw new RuntimeException("Fictive item stat"); + } +}