From e0a0154d1b10da59b03baa4a57613a3c9035eba1 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Tue, 28 Feb 2023 17:20:25 +0100 Subject: [PATCH] New type integration Integration of the new type into the plugin, there still are some lines to fix, basically every code using old hardcoded Type class or getSet() function --- .../java/net/Indyuce/mmoitems/MMOItems.java | 76 ++++---- .../java/net/Indyuce/mmoitems/api/Type.java | 14 +- .../mmoitems/api/crafting/ConfigMMOItem.java | 4 +- .../api/crafting/MMOItemUIFilter.java | 12 +- .../ingredient/MMOItemIngredient.java | 6 +- .../api/crafting/trigger/MMOItemTrigger.java | 15 +- .../mmoitems/api/droptable/DropTable.java | 4 +- .../api/droptable/item/MMOItemDropItem.java | 21 +- .../api/event/MMOItemReforgeEvent.java | 8 +- .../api/event/MMOItemReforgeFinishEvent.java | 4 +- .../mmoitems/api/interaction/Consumable.java | 4 +- .../mmoitems/api/interaction/GemStone.java | 5 +- .../mmoitems/api/item/ItemReference.java | 4 +- .../api/item/mmoitem/LiveMMOItem.java | 13 +- .../mmoitems/api/item/mmoitem/MMOItem.java | 8 +- .../api/item/mmoitem/ReadMMOItem.java | 4 +- .../api/item/template/MMOItemTemplate.java | 10 +- .../item/template/explorer/TypeFilter.java | 10 +- .../mmoitems/api/item/type/MMOItemType.java | 41 ++-- .../api/player/inventory/EquippedItem.java | 4 +- .../ingredients/MMOItemIngredient.java | 13 +- .../mmoitems/api/util/TemplateMap.java | 180 ++++++++---------- .../command/MMOItemsCommandTreeRoot.java | 6 +- .../completion/UpdateItemCompletion.java | 17 +- .../mmoitems/AllItemsCommandTreeNode.java | 11 +- .../mmoitems/BrowseCommandTreeNode.java | 13 +- .../command/mmoitems/CopyCommandTreeNode.java | 19 +- .../mmoitems/CreateCommandTreeNode.java | 6 +- .../mmoitems/DeleteCommandTreeNode.java | 13 +- .../command/mmoitems/DropCommandTreeNode.java | 23 +-- .../command/mmoitems/EditCommandTreeNode.java | 6 +- .../mmoitems/GenerateCommandTreeNode.java | 6 +- .../mmoitems/GiveAllCommandTreeNode.java | 19 +- .../command/mmoitems/GiveCommandTreeNode.java | 4 +- .../mmoitems/ItemListCommandTreeNode.java | 15 +- .../command/mmoitems/TakeCommandTreeNode.java | 4 +- .../mmoitems/list/TypeCommandTreeNode.java | 9 +- .../revid/RevIDActionCommandTreeNode.java | 8 +- .../mmoitems/comp/MMOItemsMetrics.java | 13 +- .../mmoitems/comp/MMOItemsRewardTypes.java | 11 +- .../mmoitems/comp/denizen/DenizenHook.java | 4 +- .../comp/denizen/MMOItemTemplateTag.java | 8 +- .../mmocore/load/GetMMOItemObjective.java | 19 +- .../mmocore/load/ItemTemplateDropItem.java | 15 +- .../comp/mmocore/load/MMOItemTrigger.java | 4 +- .../comp/mmocore/load/RandomItemDropItem.java | 4 +- .../placeholders/MMOItemsPlaceholders.java | 4 +- .../net/Indyuce/mmoitems/gui/ItemBrowser.java | 11 +- .../mmoitems/gui/edition/ItemEdition.java | 2 +- .../Indyuce/mmoitems/listener/ItemUse.java | 3 +- .../Indyuce/mmoitems/manager/ItemManager.java | 9 +- .../mmoitems/manager/PluginUpdateManager.java | 8 +- .../mmoitems/manager/RecipeManager.java | 8 +- .../Indyuce/mmoitems/manager/StatManager.java | 2 +- .../mmoitems/manager/TemplateManager.java | 51 +++-- .../Indyuce/mmoitems/manager/TypeManager.java | 3 +- .../mmoitems/stat/BrowserDisplayIDX.java | 2 +- .../Indyuce/mmoitems/stat/CanDeconstruct.java | 29 ++- .../net/Indyuce/mmoitems/stat/CanDeskin.java | 3 +- .../Indyuce/mmoitems/stat/CanIdentify.java | 23 ++- .../Indyuce/mmoitems/stat/CanUnsocket.java | 6 +- .../mmoitems/stat/ItemTypeRestriction.java | 36 ++-- .../Indyuce/mmoitems/stat/RandomUnsocket.java | 6 +- .../Indyuce/mmoitems/stat/RepairPower.java | 4 +- .../mmoitems/stat/RepairPowerPercent.java | 4 +- .../mmoitems/stat/SoulbindingBreakChance.java | 6 +- .../mmoitems/stat/SoulbindingChance.java | 6 +- .../Indyuce/mmoitems/stat/UpgradeStat.java | 6 +- .../stat/type/ConsumableItemInteraction.java | 11 +- .../Indyuce/mmoitems/stat/type/ItemStat.java | 13 +- .../net/Indyuce/mmoitems/util/MMOUtils.java | 6 +- .../resources/default/type-categories.yml | 12 -- 72 files changed, 471 insertions(+), 520 deletions(-) delete mode 100644 MMOItems-Dist/src/main/resources/default/type-categories.yml 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 69428310..57834bc2 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -6,10 +6,10 @@ import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import io.lumine.mythic.lib.version.SpigotPlugin; import net.Indyuce.mmoitems.api.ItemTier; import net.Indyuce.mmoitems.api.SoulboundInfo; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.crafting.MMOItemUIFilter; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.MMOItemReforger; import net.Indyuce.mmoitems.api.util.NumericStatFormula; @@ -49,6 +49,7 @@ import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; @@ -168,7 +169,7 @@ public class MMOItems extends JavaPlugin { dropTableManager = new DropTableManager(); worldGenManager = new WorldGenManager(); blockManager = new BlockManager(); - statManager.reload(false); + statManager.reload(false); PluginUtils.hookDependencyIfPresent("Vault", u -> vaultSupport = new VaultSupport()); @@ -507,11 +508,10 @@ public class MMOItems extends JavaPlugin { * template has the 'tiered' option */ @Nullable - public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, @Nullable PlayerData player) { - if (type == null || id == null) { + @Contract("_, _, null -> null") + public MMOItem getMMOItem(@Nullable MMOItemType type, @Nullable String id, @Nullable PlayerData player) { + if (type == null || id == null) return null; - } - // Valid template? MMOItemTemplate found = getTemplates().getTemplate(type, id); if (found == null) return null; @@ -527,8 +527,7 @@ public class MMOItems extends JavaPlugin { * template has the 'tiered' option */ @Nullable - public ItemStack getItem(@Nullable Type type, @Nullable String id, @NotNull PlayerData player) { - + public ItemStack getItem(@Nullable MMOItemType type, @Nullable String id, @NotNull PlayerData player) { // Valid MMOItem? MMOItem m = getMMOItem(type, id, player); if (m == null) return null; @@ -544,11 +543,10 @@ public class MMOItems extends JavaPlugin { * specific item level and item tier */ @Nullable - public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { - if (type == null || id == null) { + @Contract("null, null, _, _ -> null") + public MMOItem getMMOItem(@Nullable MMOItemType type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { + if (type == null || id == null) return null; - } - // Valid template? MMOItemTemplate found = getTemplates().getTemplate(type, id); if (found == null) return null; @@ -564,8 +562,7 @@ public class MMOItems extends JavaPlugin { * specific item level and item tier */ @Nullable - public ItemStack getItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { - + public ItemStack getItem(@Nullable MMOItemType type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { // Valid MMOItem? MMOItem m = getMMOItem(type, id, itemLevel, itemTier); if (m == null) return null; @@ -582,7 +579,8 @@ public class MMOItems extends JavaPlugin { * Will return null if such MMOItem does not exist. */ @Nullable - public MMOItem getMMOItem(@Nullable Type type, @Nullable String id) { + @Contract("null, _ -> null") + public MMOItem getMMOItem(@Nullable MMOItemType type, @Nullable String id) { return getMMOItem(type, id, 0, null); } @@ -595,10 +593,10 @@ public class MMOItems extends JavaPlugin { */ @Nullable + @Contract("null, _ -> null") public ItemStack getItem(@Nullable String type, @Nullable String id) { - if (type == null || id == null) { + if (type == null || id == null) return null; - } return getItem(getTypes().get(type), id); } @@ -610,16 +608,15 @@ public class MMOItems extends JavaPlugin { * Will return null if such MMOItem does not exist. */ @Nullable - public ItemStack getItem(@Nullable Type type, @Nullable String id) { - if (type == null || id == null) { + @Contract("null, _ -> null") + public ItemStack getItem(@Nullable MMOItemType type, @Nullable String id) { + if (type == null || id == null) return null; - } // Valid MMOItem? MMOItem m = getMMOItem(type, id); - if (m == null) { + if (m == null) return null; - } // Build if found return m.newBuilder().build(); @@ -633,7 +630,8 @@ public class MMOItems extends JavaPlugin { * @see #getType(NBTItem) */ @Nullable - public static Type getType(@Nullable ItemStack stack) { + @Contract("null -> null") + public static MMOItemType getType(@Nullable ItemStack stack) { // Get from nbt return getType(NBTItem.get(stack)); @@ -644,8 +642,7 @@ public class MMOItems extends JavaPlugin { * @return The MMOItems type of this nbt, if it has one */ @Nullable - public static Type getType(@Nullable NBTItem nbt) { - + public static MMOItemType getType(@Nullable NBTItem nbt) { // That's it return plugin.getTypes().get(getTypeName(nbt)); } @@ -657,7 +654,6 @@ public class MMOItems extends JavaPlugin { */ @Nullable public static String getTypeName(@Nullable ItemStack stack) { - // Get from nbt return getTypeName(NBTItem.get(stack)); } @@ -667,18 +663,11 @@ public class MMOItems extends JavaPlugin { * @return The MMOItems type of this nbt, if it has one */ @Nullable + @Contract("null -> null") public static String getTypeName(@Nullable NBTItem nbt) { - // Straight up no - if (nbt == null) { + if (nbt == null || !nbt.hasType()) return null; - } - - // Get from nbt - if (!nbt.hasType()) { - return null; - } - // That's it return nbt.getType(); } @@ -700,12 +689,11 @@ public class MMOItems extends JavaPlugin { * @return The MMOItems ID of this nbt, if it has one */ @Nullable + @Contract("null -> null") public static String getID(@Nullable NBTItem nbt) { - // Straight up no - if (nbt == null) { + if (nbt == null) return null; - } // That's it return nbt.getString("MMOITEMS_ITEM_ID"); @@ -720,16 +708,16 @@ public class MMOItems extends JavaPlugin { * @author Gunging */ public static void print(@Nullable Level level, @Nullable String message, @Nullable String prefix, @NotNull String... replaces) { - if (message == null) { + if (message == null) message = "< null >"; - } if (level != null) { plugin.getLogger().log(level, FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), message, replaces)); - } else { - FriendlyFeedbackMessage p = new FriendlyFeedbackMessage("", prefix); - FriendlyFeedbackMessage r = FriendlyFeedbackProvider.generateMessage(p, message, replaces); - getConsole().sendMessage(r.forConsole(FFPMMOItems.get())); + return; } + + FriendlyFeedbackMessage p = new FriendlyFeedbackMessage("", prefix); + FriendlyFeedbackMessage r = FriendlyFeedbackProvider.generateMessage(p, message, replaces); + getConsole().sendMessage(r.forConsole(FFPMMOItems.get())); } /** diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java index e09ade48..62c33cd8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java @@ -11,6 +11,7 @@ import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; @@ -18,7 +19,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +/** + * @deprecated Use {@link net.Indyuce.mmoitems.api.item.type.MMOItemType} instead. + */ @SuppressWarnings("unused") +@Deprecated +@ApiStatus.ScheduledForRemoval public class Type { @@ -106,7 +112,8 @@ public class Type { public Type(@NotNull TypeManager manager, @NotNull ConfigurationSection config) { id = config.getName().toUpperCase().replace("-", "_").replace(" ", "_"); - parent = manager.get(config.getString("parent", "").toUpperCase().replace("-", "_").replace(" ", "_")); + // parent = manager.get(config.getString("parent", "").toUpperCase().replace("-", "_").replace(" ", "_")); + parent = null; set = (parent != null ? parent.set : TypeSet.EXTRA); weapon = (parent != null && parent.weapon); @@ -120,7 +127,7 @@ public class Type { name = config.getString("name", name); item = read(config.getString("display", item == null ? Material.STONE.toString() : item.getType().toString())); - (unidentifiedTemplate = new UnidentifiedItem(this)).update(config.getConfigurationSection("unident-item")); + // (unidentifiedTemplate = new UnidentifiedItem(this)).update(config.getConfigurationSection("unident-item")); // Getting overridden? loreFormat = config.getString("LoreFormat", (parent != null ? parent.loreFormat : loreFormat)); @@ -303,7 +310,8 @@ public class Type { return null; } String format = id.toUpperCase().replace("-", "_").replace(" ", "_"); - return MMOItems.plugin.getTypes().has(format) ? MMOItems.plugin.getTypes().get(format) : null; + // return MMOItems.plugin.getTypes().has(format) ? MMOItems.plugin.getTypes().get(format) : null; + return null; } /** diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ConfigMMOItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ConfigMMOItem.java index 3c931c6c..6067ff0d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ConfigMMOItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ConfigMMOItem.java @@ -1,9 +1,9 @@ package net.Indyuce.mmoitems.api.crafting; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.RPGPlayer; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; @@ -23,7 +23,7 @@ public class ConfigMMOItem { Validate.notNull(config, "Could not read MMOItem config"); Validate.isTrue(config.contains("type") && config.contains("id"), "Config must contain type and ID"); - Type type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + MMOItemType type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); template = MMOItems.plugin.getTemplates().getTemplateOrThrow(type, config.getString("id")); this.amount = Math.max(1, config.getInt("amount")); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java index db94f713..2e4540ff 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java @@ -10,11 +10,11 @@ import io.lumine.mythic.lib.api.util.ui.QuickNumberRange; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.stat.data.UpgradeData; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -116,12 +116,12 @@ public class MMOItemUIFilter implements UIFilter { @Override public boolean isValid(@NotNull String argument, @NotNull String data, @Nullable FriendlyFeedbackProvider ffp) { - if (reg) { return true; } + if (reg) return true; argument = argument.replace(" ", "_").replace("-", "_").toUpperCase(); data = data.replace(" ", "_").replace("-", "_").toUpperCase(); // Type exists? - Type t = MMOItems.plugin.getTypes().get(argument); + MMOItemType t = MMOItems.plugin.getTypes().get(argument); // Nope if (t == null) { @@ -161,7 +161,7 @@ public class MMOItemUIFilter implements UIFilter { public ArrayList tabCompleteArgument(@NotNull String argument) { // Filter from the available types - return SilentNumbers.smartFilter(MMOItems.plugin.getTypes().getAllTypeNames(), argument, true); + return SilentNumbers.smartFilter(new ArrayList<>(MMOItems.plugin.getTypes().getAllTypeNames()), argument, true); } @NotNull @@ -169,7 +169,7 @@ public class MMOItemUIFilter implements UIFilter { public ArrayList tabCompleteData(@NotNull String argument, @NotNull String data) { //Find type? - Type t = MMOItems.plugin.getTypes().get(argument); + MMOItemType t = MMOItems.plugin.getTypes().get(argument); if (t != null) { @@ -189,7 +189,7 @@ public class MMOItemUIFilter implements UIFilter { } // Just filter among template names of this type - ArrayList suggestions = SilentNumbers.smartFilter(MMOItems.plugin.getTemplates().getTemplateNames(t), data, true); + ArrayList suggestions = SilentNumbers.smartFilter(new ArrayList<>(MMOItems.plugin.getTemplates().getTemplateNames(t)), data, true); ArrayList trueSuggestions = suggestions; // So, what things may be put in data? diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java index 777723e8..80d69716 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/MMOItemIngredient.java @@ -6,15 +6,15 @@ import io.lumine.mythic.lib.api.util.ui.QuickNumberRange; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.util.MMOUtils; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.crafting.ConfigMMOItem; import net.Indyuce.mmoitems.api.crafting.ingredient.inventory.MMOItemPlayerIngredient; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.stat.DisplayName; import net.Indyuce.mmoitems.stat.data.MaterialData; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; @@ -30,7 +30,7 @@ public class MMOItemIngredient extends Ingredient { // Which MMOItem? config.validate("type", "id"); - Type type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + MMOItemType type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); template = MMOItems.plugin.getTemplates().getTemplateOrThrow(type, config.getString("id")); // Read level, the default is that any level will work diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/trigger/MMOItemTrigger.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/trigger/MMOItemTrigger.java index 3a6d8c12..30ce9790 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/trigger/MMOItemTrigger.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/trigger/MMOItemTrigger.java @@ -1,16 +1,15 @@ package net.Indyuce.mmoitems.api.crafting.trigger; +import io.lumine.mythic.lib.api.MMOLineConfig; +import io.lumine.mythic.lib.api.util.SmartGive; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.api.player.PlayerData; import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; -import net.Indyuce.mmoitems.api.player.PlayerData; -import io.lumine.mythic.lib.api.MMOLineConfig; -import io.lumine.mythic.lib.api.util.SmartGive; - public class MMOItemTrigger extends Trigger { private final MMOItemTemplate template; private final int amount; @@ -20,7 +19,7 @@ public class MMOItemTrigger extends Trigger { config.validate("type", "id"); - Type type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + MMOItemType type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); String id = config.getString("id").replace("-", "_").toUpperCase(); Validate.isTrue(MMOItems.plugin.getTemplates().hasTemplate(type, id), "Could not find MMOItem with ID '" + id + "'"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/droptable/DropTable.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/droptable/DropTable.java index 66109cdd..f8766b7a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/droptable/DropTable.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/droptable/DropTable.java @@ -1,10 +1,10 @@ package net.Indyuce.mmoitems.api.droptable; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.droptable.item.BlockDropItem; import net.Indyuce.mmoitems.api.droptable.item.DropItem; import net.Indyuce.mmoitems.api.droptable.item.MMOItemDropItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; @@ -83,7 +83,7 @@ public class DropTable { if (subtable.contains("items")) for (String typeFormat : subtable.getConfigurationSection("items").getKeys(false)) { - Type type = MMOItems.plugin.getTypes().getOrThrow(typeFormat.toUpperCase().replace("-", "_")); + MMOItemType type = MMOItems.plugin.getTypes().getOrThrow(typeFormat.toUpperCase().replace("-", "_")); for (String id : subtable.getConfigurationSection("items." + typeFormat).getKeys(false)) items.add(new MMOItemDropItem(type, id, subtable.getString("items." + typeFormat + "." + id))); } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/droptable/item/MMOItemDropItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/droptable/item/MMOItemDropItem.java index 417258fe..3eb50feb 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/droptable/item/MMOItemDropItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/droptable/item/MMOItemDropItem.java @@ -1,24 +1,23 @@ package net.Indyuce.mmoitems.api.droptable.item; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.api.player.PlayerData; +import net.Indyuce.mmoitems.api.util.RandomAmount; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.player.PlayerData; -import net.Indyuce.mmoitems.api.util.RandomAmount; -import io.lumine.mythic.lib.api.item.NBTItem; - public class MMOItemDropItem extends DropItem { - private final Type type; + private final MMOItemType type; private final String id; private final double unidentification; - public MMOItemDropItem(Type type, String id, double drop, double unidentification, RandomAmount amount) { + public MMOItemDropItem(MMOItemType type, String id, double drop, double unidentification, RandomAmount amount) { this(type, id, drop, unidentification, amount.getMin(), amount.getMax()); } - public MMOItemDropItem(Type type, String id, double drop, double unidentification, int min, int max) { + public MMOItemDropItem(MMOItemType type, String id, double drop, double unidentification, int min, int max) { super(drop, min, max); this.type = type; @@ -26,7 +25,7 @@ public class MMOItemDropItem extends DropItem { this.unidentification = unidentification; } - public MMOItemDropItem(Type type, String id, String info) { + public MMOItemDropItem(MMOItemType type, String id, String info) { super(info); this.type = type; @@ -36,7 +35,7 @@ public class MMOItemDropItem extends DropItem { unidentification = Double.parseDouble(argSplit[2]) / 100; } - public Type getType() { + public MMOItemType getType() { return type; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/MMOItemReforgeEvent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/MMOItemReforgeEvent.java index e2e79119..c0831246 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/MMOItemReforgeEvent.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/MMOItemReforgeEvent.java @@ -1,14 +1,10 @@ package net.Indyuce.mmoitems.api.event; import net.Indyuce.mmoitems.api.ReforgeOptions; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.util.MMOItemReforger; -import net.Indyuce.mmoitems.stat.data.type.Mergeable; -import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.ItemStat; -import net.Indyuce.mmoitems.stat.type.StatHistory; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -68,7 +64,7 @@ public class MMOItemReforgeEvent extends Event implements Cancellable { /** * @return MMOItems Type we are working with */ - @NotNull public Type getType() { return getReforger().getTemplate().getType(); } + @NotNull public MMOItemType getType() { return getReforger().getTemplate().getType(); } /** * @return MMOItems Type we are working with diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/MMOItemReforgeFinishEvent.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/MMOItemReforgeFinishEvent.java index b1adac5d..3a72e764 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/MMOItemReforgeFinishEvent.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/event/MMOItemReforgeFinishEvent.java @@ -1,9 +1,9 @@ package net.Indyuce.mmoitems.api.event; import net.Indyuce.mmoitems.api.ReforgeOptions; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.util.MMOItemReforger; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; @@ -76,7 +76,7 @@ public class MMOItemReforgeFinishEvent extends Event implements Cancellable { /** * @return MMOItems Type we are working with */ - @NotNull public Type getType() { return getReforger().getTemplate().getType(); } + @NotNull public MMOItemType getType() { return getReforger().getTemplate().getType(); } /** * @return MMOItems Type we are working with diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/Consumable.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/Consumable.java index 3e46b5c0..571db582 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/Consumable.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/Consumable.java @@ -7,9 +7,9 @@ import io.lumine.mythic.lib.api.util.SmartGive; import io.lumine.mythic.lib.comp.flags.CustomFlag; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.ConsumableConsumedEvent; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.item.util.LoreUpdate; import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; import net.Indyuce.mmoitems.stat.type.PlayerConsumable; @@ -43,7 +43,7 @@ public class Consumable extends UseItem { return false; // Make sure it is an MMOItem - Type targetType = MMOItems.getType(target); + MMOItemType targetType = MMOItems.getType(target); for (ConsumableItemInteraction action : MMOItems.plugin.getStats().getConsumableActions()) if (action.handleConsumableEffect(event, playerData, this, target, targetType)) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java index 0a47fcd8..becd0913 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/GemStone.java @@ -6,6 +6,7 @@ import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.event.item.ApplyGemStoneEvent; import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.Enchants; import net.Indyuce.mmoitems.stat.GemUpgradeScaling; @@ -34,7 +35,7 @@ public class GemStone extends UseItem { } @NotNull - public ApplyResult applyOntoItem(@NotNull NBTItem target, @NotNull Type targetType) { + public ApplyResult applyOntoItem(@NotNull NBTItem target, @NotNull MMOItemType targetType) { /* * Entirely loads the MMOItem and checks if it has the required empty @@ -45,7 +46,7 @@ public class GemStone extends UseItem { } @NotNull - public ApplyResult applyOntoItem(@NotNull MMOItem targetMMO, @NotNull Type targetType, @NotNull String itemName, boolean buildStack, boolean silent) { + public ApplyResult applyOntoItem(@NotNull MMOItem targetMMO, @NotNull MMOItemType targetType, @NotNull String itemName, boolean buildStack, boolean silent) { if (!targetMMO.hasData(ItemStats.GEM_SOCKETS)) return new ApplyResult(ResultType.NONE); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/ItemReference.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/ItemReference.java index eea73f55..431da5a1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/ItemReference.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/ItemReference.java @@ -1,7 +1,7 @@ package net.Indyuce.mmoitems.api.item; import io.lumine.mythic.lib.player.cooldown.CooldownObject; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; /** * Referenced objects are either item templates or MMOItems. They contain the @@ -19,7 +19,7 @@ public interface ItemReference extends CooldownObject { *

* Example: GREATSWORD STEEL_CLAYMORE */ - Type getType(); + MMOItemType getType(); /** * MMOItem templates have to identifiers: TYPE and ID diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/LiveMMOItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/LiveMMOItem.java index dfb5d0a9..3fdf7eeb 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/LiveMMOItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/LiveMMOItem.java @@ -1,18 +1,17 @@ package net.Indyuce.mmoitems.api.item.mmoitem; -import java.util.logging.Level; - +import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.ItemTag; +import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; +import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; +import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.StatHistory; import org.bukkit.ChatColor; import org.bukkit.inventory.ItemStack; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.stat.type.ItemStat; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.item.NBTItem; +import java.util.logging.Level; public class LiveMMOItem extends ReadMMOItem { @@ -38,7 +37,7 @@ public class LiveMMOItem extends ReadMMOItem { super(item); // Reads all the stats that this type could possibly have. - for (ItemStat stat : getType().getAvailableStats()) + for (ItemStat stat : getType().getStats()) // Attempts to load it try { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/MMOItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/MMOItem.java index 604eee7e..57077ff1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/MMOItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/MMOItem.java @@ -5,10 +5,10 @@ import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ItemTier; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.UpgradeTemplate; import net.Indyuce.mmoitems.api.item.ItemReference; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.util.MMOItemReforger; import net.Indyuce.mmoitems.stat.Enchants; import net.Indyuce.mmoitems.stat.data.*; @@ -26,7 +26,7 @@ import java.util.*; @SuppressWarnings("unused") public class MMOItem implements ItemReference { - private final Type type; + private final MMOItemType type; private final String id; /** @@ -47,13 +47,13 @@ public class MMOItem implements ItemReference { * existing items not to interfere with MI features like the * dynamic item updater */ - public MMOItem(Type type, String id) { + public MMOItem(MMOItemType type, String id) { this.type = type; this.id = id; } @Override - public Type getType() { return type; } + public MMOItemType getType() { return type; } @Override public String getId() { return id; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/ReadMMOItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/ReadMMOItem.java index 41736fad..f0a563db 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/ReadMMOItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/mmoitem/ReadMMOItem.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.api.item.mmoitem; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; @@ -19,7 +19,7 @@ public abstract class ReadMMOItem extends MMOItem { * The NBTItem being read to generate an MMOItem */ public ReadMMOItem(@NotNull NBTItem item) { - super(Type.get(item.getType()), item.getString("MMOITEMS_ITEM_ID")); + super(MMOItemType.get(item.getType()), item.getString("MMOITEMS_ITEM_ID")); this.item = item; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/MMOItemTemplate.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/MMOItemTemplate.java index 2c6a8d1e..7a990ee4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/MMOItemTemplate.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/MMOItemTemplate.java @@ -5,9 +5,9 @@ import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ItemTier; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.ItemReference; import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; @@ -22,7 +22,7 @@ import javax.annotation.Nullable; import java.util.*; public class MMOItemTemplate extends PostLoadObject implements ItemReference { - private final Type type; + private final MMOItemType type; private final String id; private final int revId; @@ -40,7 +40,7 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference { * @param id The template identifier, it's ok if two templates with * different item types share the same ID */ - public MMOItemTemplate(Type type, String id) { + public MMOItemTemplate(MMOItemType type, String id) { super(null); this.type = type; @@ -54,7 +54,7 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference { * @param type The item type of your template * @param config The config file read to load the template */ - public MMOItemTemplate(Type type, ConfigurationSection config) { + public MMOItemTemplate(MMOItemType type, ConfigurationSection config) { super(config); Validate.notNull(config, "Could not load template config"); @@ -127,7 +127,7 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference { } @Override - public Type getType() { + public MMOItemType getType() { return type; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/explorer/TypeFilter.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/explorer/TypeFilter.java index c50e26e5..a0a9f114 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/explorer/TypeFilter.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/template/explorer/TypeFilter.java @@ -1,17 +1,17 @@ package net.Indyuce.mmoitems.api.item.template.explorer; -import java.util.function.Predicate; - -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; + +import java.util.function.Predicate; /** * Filters items with a specific type */ public class TypeFilter implements Predicate { - private final Type type; + private final MMOItemType type; - public TypeFilter(Type type) { + public TypeFilter(MMOItemType type) { this.type = type; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/MMOItemType.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/MMOItemType.java index 480644e4..6da7d46a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/MMOItemType.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/MMOItemType.java @@ -3,10 +3,10 @@ package net.Indyuce.mmoitems.api.item.type; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.player.modifier.ModifierSource; +import io.lumine.mythic.lib.script.Script; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.item.util.identify.UnidentifiedItem; -import net.Indyuce.mmoitems.manager.TypeManager; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.apache.commons.lang.Validate; import org.bukkit.Material; @@ -36,9 +36,10 @@ public class MMOItemType { private final ItemStack item; private final UnidentifiedItem unidentifiedTemplate; private final List> stats; + private final @org.jetbrains.annotations.Nullable Script script; - private MMOItemType(String id, String name, ModifierSource modifierSource, boolean weapon, String loreFormat, ItemStack item, List> stats) { + protected MMOItemType(String id, String name, ModifierSource modifierSource, boolean weapon, String loreFormat, ItemStack item, @org.jetbrains.annotations.Nullable Script script, List> stats) { this.id = id; this.name = name; this.modifierSource = modifierSource; @@ -46,6 +47,7 @@ public class MMOItemType { this.loreFormat = loreFormat; this.item = item; this.unidentifiedTemplate = new UnidentifiedItem(this); + this.script = script; this.stats = stats; } @@ -90,21 +92,8 @@ public class MMOItemType { return new ConfigFile("/item", getId().toLowerCase()); } - public static MMOItemType load(@NotNull TypeManager manager, @NotNull ConfigurationSection section) { - final String id = section.getName(); - final String name = section.getString("name"); - final ModifierSource modifierSource = ModifierSource.valueOf(section.getString("modifier-source")); - final boolean weapon = section.getBoolean("weapon"); - final String loreFormat = section.getString("lore-format"); - final ItemStack item = read(section.getString("display", Material.STONE.toString())); - - - // TODO: Load the stats - final List> stats = new ArrayList<>(); - - MMOItemType type = new MMOItemType(id, name, modifierSource, weapon, loreFormat, item, stats); - type.getUnidentifiedTemplate().update(section.getConfigurationSection("unident-item")); - return type; + public @org.jetbrains.annotations.Nullable Script getScript() { + return script; } public static ItemStack read(String str) { @@ -175,4 +164,22 @@ public class MMOItemType { public static boolean isValid(@Nullable String id) { return id != null && MMOItems.plugin.getTypes().has(id.toUpperCase().replace("-", "_").replace(" ", "_")); } + + public static MMOItemType load(@NotNull ConfigurationSection section) { + final String id = section.getName(); + final String name = section.getString("name"); + final ModifierSource modifierSource = ModifierSource.valueOf(section.getString("modifier-source")); + final boolean weapon = section.getBoolean("weapon"); + final String loreFormat = section.getString("lore-format"); + final ItemStack item = read(section.getString("display", Material.STONE.toString())); + final Script script = section.isString("script") ? MythicLib.plugin.getSkills().getScriptOrThrow(section.getString("script")) : null; + + + // TODO: Load the stats + final List> stats = new ArrayList<>(); + + MMOItemType type = new MMOItemType(id, name, modifierSource, weapon, loreFormat, item, script, stats); + type.getUnidentifiedTemplate().update(section.getConfigurationSection("unident-item")); + return type; + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java index 4e5f6a8d..54dee7dc 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java @@ -5,8 +5,8 @@ import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.player.modifier.ModifierSource; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.apache.commons.lang.Validate; import org.bukkit.inventory.ItemStack; @@ -70,7 +70,7 @@ public abstract class EquippedItem { if (typeFormat == null) return false; - final @Nullable Type type = MMOItems.plugin.getTypes().get(typeFormat); + final @Nullable MMOItemType type = MMOItems.plugin.getTypes().get(typeFormat); if (type == null) return false; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/recipe/workbench/ingredients/MMOItemIngredient.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/recipe/workbench/ingredients/MMOItemIngredient.java index 98483e17..1113e9e1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/recipe/workbench/ingredients/MMOItemIngredient.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/recipe/workbench/ingredients/MMOItemIngredient.java @@ -1,17 +1,16 @@ package net.Indyuce.mmoitems.api.recipe.workbench.ingredients; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import io.lumine.mythic.lib.api.item.NBTItem; - public class MMOItemIngredient extends WorkbenchIngredient { - private final Type type; + private final MMOItemType type; private final String id; - public MMOItemIngredient(Type type, String id, int amount) { + public MMOItemIngredient(MMOItemType type, String id, int amount) { super(amount); this.type = type; @@ -21,7 +20,7 @@ public class MMOItemIngredient extends WorkbenchIngredient { @Override public boolean corresponds(ItemStack stack) { NBTItem nbt = NBTItem.get(stack); - return type.equals(Type.get(nbt.getType())) && nbt.getString("MMOITEMS_ITEM_ID").equalsIgnoreCase(id); + return type.equals(MMOItemType.get(nbt.getType())) && nbt.getString("MMOITEMS_ITEM_ID").equalsIgnoreCase(id); } @Override diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/TemplateMap.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/TemplateMap.java index 05ceed6e..9d46c753 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/TemplateMap.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/TemplateMap.java @@ -1,7 +1,8 @@ package net.Indyuce.mmoitems.api.util; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.apache.commons.lang.Validate; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,116 +13,97 @@ import java.util.function.Consumer; * Allows the use of two nested maps to efficiently store data about mmoitem * templates. The first nested map is for the item type, the second is for the * item ID. - * - * @author cympe * - * @param - * The class of the value you want to assign to every mmoitem + * @param The class of the value you want to assign to every mmoitem * template + * @author cympe */ public class TemplateMap { - private final Map typeMap = new HashMap<>(); - /** - * @param type - * The item type - * @param id - * The template identifier - * @return If a template has some value stored in that map - */ - public boolean hasValue(@Nullable Type type, @Nullable String id) { - if(type == null || id == null) { return false; } - return typeMap.containsKey(type) && typeMap.get(type).idMap.containsKey(id); - } + private final Map> typeMap = new HashMap<>(); - /** - * @param type - * The item type - * @param id - * The template identifier - * @return Returns the value stored in the template map - */ - @Nullable public C getValue(@Nullable Type type, @Nullable String id) { - if(type == null || id == null) { return null; } - Submap m = typeMap.get(type); - if (m == null) { return null; } - return m.idMap.get(id); - } + /** + * @param type The item type + * @param id The template identifier + * @return If a template has some value stored in that map + */ + @Contract("null, _ -> false; _, null -> false") + public boolean hasValue(@Nullable MMOItemType type, @Nullable String id) { + if (type == null || id == null) + return false; + return typeMap.containsKey(type) && typeMap.getOrDefault(type, new HashMap<>()).containsKey(id); + } - /** - * Unregisters a value from the map - * - * @param type - * The item type - * @param id - * The template identifier - */ - public void removeValue(@Nullable Type type, @Nullable String id) { - if(type == null || id == null) { return; } - if (typeMap.containsKey(type)) - typeMap.get(type).idMap.remove(id); - } + /** + * @param type The item type + * @param id The template identifier + * @return Returns the value stored in the template map + */ + @Nullable + @Contract("null, _ -> null; _, null -> null") + public C getValue(@Nullable MMOItemType type, @Nullable String id) { + if (type == null || id == null) return null; + return typeMap.getOrDefault(type, new HashMap<>()).get(id); + } - /** - * Registers a value for a specific mmoitem template - * - * @param type - * The item type - * @param id - * The template identifier - * @param value - * The value to registered - */ - public void setValue(@NotNull Type type, @NotNull String id, @NotNull C value) { - Validate.notNull(value, "Value cannot be null"); + /** + * Unregisters a value from the map + * + * @param type The item type + * @param id The template identifier + */ + public void removeValue(@Nullable MMOItemType type, @Nullable String id) { + if (type == null || id == null) return; + typeMap.getOrDefault(type, new HashMap<>()).remove(id); + } - if (!typeMap.containsKey(type)) - typeMap.put(type, new Submap()); - typeMap.get(type).idMap.put(id, value); - } + /** + * Registers a value for a specific mmoitem template + * + * @param type The item type + * @param id The template identifier + * @param value The value to registered + */ + public void setValue(@NotNull MMOItemType type, @NotNull String id, @NotNull C value) { + Validate.notNull(value, "Value cannot be null"); - /** - * Applies a specific consumer for every template. This is used to postload - * all templates when MMOItems enables - * - * @param action - * Action performed for every registered template - */ - public void forEach(@NotNull Consumer action) { typeMap.values().forEach(submap -> submap.idMap.values().forEach(action)); } + this.typeMap.computeIfAbsent(type, k -> new HashMap<>()).put(id, value); + } - /** - * @return Collects all the values registered in this template map. - */ - @NotNull public Collection collectValues() { - Set collected = new HashSet<>(); - typeMap.values().forEach(submap -> collected.addAll(submap.idMap.values())); - return collected; - } + /** + * Applies a specific consumer for every template. This is used to postload + * all templates when MMOItems enables + * + * @param action Action performed for every registered template + */ + public void forEach(@NotNull Consumer action) { + typeMap.values().forEach(stringCMap -> stringCMap.values().forEach(action)); + } - /** - * @param type - * The item type - * @return Collects all the values registered in this template map with a - * specific item type - */ - @NotNull public Collection collectValues(@NotNull Type type) { - return typeMap.containsKey(type) ? typeMap.get(type).idMap.values() : new HashSet<>(); - } + /** + * @return Collects all the values registered in this template map. + */ + @NotNull + public Collection collectValues() { + Set collected = new HashSet<>(); + typeMap.values().forEach(submap -> collected.addAll(submap.values())); + return collected; + } - /** - * Clears the map - */ - public void clear() { typeMap.clear(); } + /** + * @param type The item type + * @return Collects all the values registered in this template map with a + * specific item type + */ + @NotNull + public Collection collectValues(@NotNull MMOItemType type) { + return typeMap.containsKey(type) ? typeMap.get(type).values() : new HashSet<>(); + } - /** - * For memory leak purposes we cannot directly use a nested map into another - * map (must resort to using an object). No methods are required however - * because this class is completely private. - * - * @author cympe - * - */ - private class Submap { - private final Map idMap = new LinkedHashMap<>(); - } + /** + * Clears the map + */ + public void clear() { + typeMap.clear(); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/MMOItemsCommandTreeRoot.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/MMOItemsCommandTreeRoot.java index b68aa2de..8ad956b1 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/MMOItemsCommandTreeRoot.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/MMOItemsCommandTreeRoot.java @@ -3,10 +3,10 @@ package net.Indyuce.mmoitems.command; import io.lumine.mythic.lib.command.api.CommandTreeRoot; import io.lumine.mythic.lib.command.api.Parameter; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.command.mmoitems.item.ItemCommandTreeNode; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.command.mmoitems.*; import net.Indyuce.mmoitems.command.mmoitems.debug.DebugCommandTreeNode; +import net.Indyuce.mmoitems.command.mmoitems.item.ItemCommandTreeNode; import net.Indyuce.mmoitems.command.mmoitems.list.ListCommandTreeNode; import net.Indyuce.mmoitems.command.mmoitems.revid.RevisionIDCommandTreeNode; import net.Indyuce.mmoitems.command.mmoitems.stations.StationsCommandTreeNode; @@ -17,7 +17,7 @@ public class MMOItemsCommandTreeRoot extends CommandTreeRoot { (explorer, list) -> MMOItems.plugin.getTypes().getAll().forEach(type -> list.add(type.getId()))); public static final Parameter ID_2 = new Parameter("", (explorer, list) -> { try { - Type type = Type.get(explorer.getArguments()[1]); + MMOItemType type = MMOItemType.get(explorer.getArguments()[1]); MMOItems.plugin.getTemplates().getTemplates(type).forEach(template -> list.add(template.getId())); } catch (Exception ignored) { } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/completion/UpdateItemCompletion.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/completion/UpdateItemCompletion.java index 2d0dfbf1..150d8ad7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/completion/UpdateItemCompletion.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/completion/UpdateItemCompletion.java @@ -1,15 +1,14 @@ package net.Indyuce.mmoitems.command.completion; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; public class UpdateItemCompletion implements TabCompleter { @Override @@ -20,11 +19,11 @@ public class UpdateItemCompletion implements TabCompleter { List list = new ArrayList<>(); if (args.length == 1) - for (Type type : MMOItems.plugin.getTypes().getAll()) + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) list.add(type.getId()); - if (args.length == 2 && Type.isValid(args[0])) - Type.get(args[0]).getConfigFile().getConfig().getKeys(false).forEach(id -> list.add(id.toUpperCase())); + if (args.length == 2 && MMOItemType.isValid(args[0])) + MMOItemType.get(args[0]).getConfigFile().getConfig().getKeys(false).forEach(id -> list.add(id.toUpperCase())); return args[args.length - 1].isEmpty() ? list : list.stream().filter(string -> string.toLowerCase().startsWith(args[args.length - 1].toLowerCase())).collect(Collectors.toList()); } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/AllItemsCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/AllItemsCommandTreeNode.java index 359fe73c..6defe6a7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/AllItemsCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/AllItemsCommandTreeNode.java @@ -1,14 +1,13 @@ package net.Indyuce.mmoitems.command.mmoitems; +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.command.api.CommandTreeNode; - public class AllItemsCommandTreeNode extends CommandTreeNode { public AllItemsCommandTreeNode(CommandTreeNode parent) { super(parent, "allitems"); @@ -18,7 +17,7 @@ public class AllItemsCommandTreeNode extends CommandTreeNode { public CommandResult execute(CommandSender sender, String[] args) { sender.sendMessage(ChatColor.YELLOW + "" + ChatColor.STRIKETHROUGH + "-----------------------------------------------------"); sender.sendMessage(ChatColor.GREEN + "List of all MMOItems:"); - for (Type type : MMOItems.plugin.getTypes().getAll()) { + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) { FileConfiguration config = type.getConfigFile().getConfig(); for (String s : config.getKeys(false)) sender.sendMessage("* " + ChatColor.GREEN + s diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/BrowseCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/BrowseCommandTreeNode.java index 027315b8..8700bd46 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/BrowseCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/BrowseCommandTreeNode.java @@ -1,15 +1,14 @@ package net.Indyuce.mmoitems.command.mmoitems; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; +import net.Indyuce.mmoitems.gui.ItemBrowser; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.gui.ItemBrowser; -import io.lumine.mythic.lib.command.api.CommandTreeNode; - public class BrowseCommandTreeNode extends CommandTreeNode { public BrowseCommandTreeNode(CommandTreeNode parent) { super(parent, "browse"); @@ -29,12 +28,12 @@ public class BrowseCommandTreeNode extends CommandTreeNode { return CommandResult.SUCCESS; } - if (!Type.isValid(args[1])) { + if (!MMOItemType.isValid(args[1])) { sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Please specify a valid item type."); return CommandResult.FAILURE; } - new ItemBrowser((Player) sender, Type.get(args[1])).open(); + new ItemBrowser((Player) sender, MMOItemType.get(args[1])).open(); return CommandResult.SUCCESS; } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/CopyCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/CopyCommandTreeNode.java index 42181aae..fd78c915 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/CopyCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/CopyCommandTreeNode.java @@ -1,17 +1,16 @@ package net.Indyuce.mmoitems.command.mmoitems; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import io.lumine.mythic.lib.command.api.Parameter; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.ConfigFile; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; +import net.Indyuce.mmoitems.gui.edition.ItemEdition; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.ConfigFile; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; -import net.Indyuce.mmoitems.gui.edition.ItemEdition; -import io.lumine.mythic.lib.command.api.CommandTreeNode; -import io.lumine.mythic.lib.command.api.Parameter; - public class CopyCommandTreeNode extends CommandTreeNode { public CopyCommandTreeNode(CommandTreeNode parent) { super(parent, "copy"); @@ -27,7 +26,7 @@ public class CopyCommandTreeNode extends CommandTreeNode { if (args.length < 4) return CommandResult.THROW_USAGE; - if (!Type.isValid(args[1])) { + if (!MMOItemType.isValid(args[1])) { sender.sendMessage( MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + "."); sender.sendMessage(MMOItems.plugin.getPrefix() + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.GRAY @@ -35,7 +34,7 @@ public class CopyCommandTreeNode extends CommandTreeNode { return CommandResult.FAILURE; } - Type type = Type.get(args[1]); + MMOItemType type = MMOItemType.get(args[1]); ConfigFile config = type.getConfigFile(); String id1 = args[2].toUpperCase().replace("-", "_"); if (!config.getConfig().contains(id1)) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/CreateCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/CreateCommandTreeNode.java index cba1dd95..60c501c5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/CreateCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/CreateCommandTreeNode.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.Parameter; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ConfigFile; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; import net.Indyuce.mmoitems.gui.edition.ItemEdition; import org.bukkit.ChatColor; @@ -24,7 +24,7 @@ public class CreateCommandTreeNode extends CommandTreeNode { if (args.length < 3) return CommandResult.THROW_USAGE; - if (!Type.isValid(args[1])) { + if (!MMOItemType.isValid(args[1])) { sender.sendMessage( MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + "."); sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED @@ -32,7 +32,7 @@ public class CreateCommandTreeNode extends CommandTreeNode { return CommandResult.FAILURE; } - Type type = Type.get(args[1]); + MMOItemType type = MMOItemType.get(args[1]); String name = args[2].toUpperCase().replace("-", "_"); ConfigFile config = type.getConfigFile(); if (config.getConfig().contains(name)) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/DeleteCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/DeleteCommandTreeNode.java index a13a29d3..a60f4781 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/DeleteCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/DeleteCommandTreeNode.java @@ -1,13 +1,12 @@ package net.Indyuce.mmoitems.command.mmoitems; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; -import io.lumine.mythic.lib.command.api.CommandTreeNode; - public class DeleteCommandTreeNode extends CommandTreeNode { public DeleteCommandTreeNode(CommandTreeNode parent) { super(parent, "delete"); @@ -21,7 +20,7 @@ public class DeleteCommandTreeNode extends CommandTreeNode { if (args.length < 3) return CommandResult.THROW_USAGE; - if (!Type.isValid(args[1])) { + if (!MMOItemType.isValid(args[1])) { sender.sendMessage( MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + "."); sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED @@ -29,7 +28,7 @@ public class DeleteCommandTreeNode extends CommandTreeNode { return CommandResult.FAILURE; } - Type type = Type.get(args[1]); + MMOItemType type = MMOItemType.get(args[1]); String id = args[2].toUpperCase().replace("-", "_"); if (!MMOItems.plugin.getTemplates().hasTemplate(type, id)) { sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item called " + id + "."); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/DropCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/DropCommandTreeNode.java index e5d297c1..abf095b5 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/DropCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/DropCommandTreeNode.java @@ -1,21 +1,16 @@ package net.Indyuce.mmoitems.command.mmoitems; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import io.lumine.mythic.lib.command.api.Parameter; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.droptable.item.MMOItemDropItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; +import org.bukkit.*; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.inventory.ItemStack; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.droptable.item.MMOItemDropItem; -import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; -import io.lumine.mythic.lib.command.api.CommandTreeNode; -import io.lumine.mythic.lib.command.api.Parameter; - public class DropCommandTreeNode extends CommandTreeNode { public DropCommandTreeNode(CommandTreeNode parent) { super(parent, "drop"); @@ -36,7 +31,7 @@ public class DropCommandTreeNode extends CommandTreeNode { if (args.length != 10) return CommandResult.THROW_USAGE; - if (!Type.isValid(args[1])) { + if (!MMOItemType.isValid(args[1])) { sender.sendMessage( MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + "."); sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.RED @@ -44,7 +39,7 @@ public class DropCommandTreeNode extends CommandTreeNode { return CommandResult.FAILURE; } - Type type = Type.get(args[1].toUpperCase()); + MMOItemType type = MMOItemType.get(args[1].toUpperCase()); String name = args[2].toUpperCase().replace("-", "_"); FileConfiguration config = type.getConfigFile().getConfig(); if (!config.contains(name)) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/EditCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/EditCommandTreeNode.java index 38b6b99b..17c390ad 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/EditCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/EditCommandTreeNode.java @@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.command.mmoitems; import io.lumine.mythic.lib.command.api.CommandTreeNode; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; import net.Indyuce.mmoitems.gui.edition.ItemEdition; import org.bukkit.ChatColor; @@ -27,7 +27,7 @@ public class EditCommandTreeNode extends CommandTreeNode { return CommandResult.FAILURE; } - if (!Type.isValid(args[1])) { + if (!MMOItemType.isValid(args[1])) { sender.sendMessage( MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + "."); sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED @@ -35,7 +35,7 @@ public class EditCommandTreeNode extends CommandTreeNode { return CommandResult.FAILURE; } - Type type = Type.get(args[1]); + MMOItemType type = MMOItemType.get(args[1]); String id = args[2].toUpperCase().replace("-", "_"); if (!MMOItems.plugin.getTemplates().hasTemplate(type, id)) { sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Could not find a template called '" + id + "'."); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GenerateCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GenerateCommandTreeNode.java index 88474255..4caf27f6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GenerateCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GenerateCommandTreeNode.java @@ -6,9 +6,9 @@ import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.Parameter; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ItemTier; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.item.template.explorer.*; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.RPGPlayer; import org.apache.commons.lang.Validate; @@ -68,8 +68,8 @@ public class GenerateCommandTreeNode extends CommandTreeNode { } if (handler.hasArgument("type")) { type = handler.getValue("type"); - Validate.isTrue(Type.isValid(type), "Could not find type with ID '" + type + "'"); - builder.applyFilter(new TypeFilter(Type.get(type))); + Validate.isTrue(MMOItemType.isValid(type), "Could not find type with ID '" + type + "'"); + builder.applyFilter(new TypeFilter(MMOItemType.get(type))); } if (handler.hasArgument("id")) { Validate.isTrue(type != null, "You have to specify a type if using the id option!"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveAllCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveAllCommandTreeNode.java index 25175fe4..49911fb0 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveAllCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveAllCommandTreeNode.java @@ -1,5 +1,13 @@ package net.Indyuce.mmoitems.command.mmoitems; +import io.lumine.mythic.lib.api.util.SmartGive; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import io.lumine.mythic.lib.command.api.Parameter; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.droptable.item.MMOItemDropItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.api.util.RandomAmount; +import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -8,15 +16,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.droptable.item.MMOItemDropItem; -import net.Indyuce.mmoitems.api.util.RandomAmount; -import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; -import io.lumine.mythic.lib.api.util.SmartGive; -import io.lumine.mythic.lib.command.api.CommandTreeNode; -import io.lumine.mythic.lib.command.api.Parameter; - public class GiveAllCommandTreeNode extends CommandTreeNode { public GiveAllCommandTreeNode(CommandTreeNode parent) { super(parent, "giveall"); @@ -33,7 +32,7 @@ public class GiveAllCommandTreeNode extends CommandTreeNode { Validate.isTrue(args.length > 4, "Usage: /mi giveall "); // item - Type type = MMOItems.plugin.getTypes().getOrThrow(args[1]); + MMOItemType type = MMOItems.plugin.getTypes().getOrThrow(args[1]); ItemStack item = new MMOItemDropItem(type, args[2], 1, Double.parseDouble(args[4]) / 100, new RandomAmount(args[3])).getItem(null); Validate.isTrue(item != null && item.getType() != Material.AIR, "Couldn't find/generate the item called '" + args[1].toUpperCase() + "'. Check your console for potential item generation issues."); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveCommandTreeNode.java index 1f769909..67c7caf2 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/GiveCommandTreeNode.java @@ -5,9 +5,9 @@ import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.Parameter; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.RandomAmount; import net.Indyuce.mmoitems.api.util.message.Message; @@ -54,7 +54,7 @@ public class GiveCommandTreeNode extends CommandTreeNode { Validate.notNull(target, "Could not find player called '" + args[args.length > 3 ? 3 : 2] + "'."); // item - Type type = MMOItems.plugin.getTypes().getOrThrow(args[1].toUpperCase().replace("-", "_")); + MMOItemType type = MMOItems.plugin.getTypes().getOrThrow(args[1].toUpperCase().replace("-", "_")); MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplateOrThrow(type, args[2].toUpperCase().replace("-", "_")); RandomAmount amount = args.length > 4 ? new RandomAmount(args[4]) : new RandomAmount(1, 1); double unidentify = args.length > 5 ? Double.parseDouble(args[5]) / 100 : 0; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ItemListCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ItemListCommandTreeNode.java index e4c9f3ef..7075850a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ItemListCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ItemListCommandTreeNode.java @@ -1,16 +1,15 @@ package net.Indyuce.mmoitems.command.mmoitems; +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.command.api.CommandTreeNode; - public class ItemListCommandTreeNode extends CommandTreeNode { public ItemListCommandTreeNode(CommandTreeNode parent) { super(parent, "itemlist"); @@ -23,7 +22,7 @@ public class ItemListCommandTreeNode extends CommandTreeNode { if (args.length < 2) return CommandResult.THROW_USAGE; - if (!Type.isValid(args[1])) { + if (!MMOItemType.isValid(args[1])) { sender.sendMessage( MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_")); sender.sendMessage(MMOItems.plugin.getPrefix() + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.GRAY @@ -31,7 +30,7 @@ public class ItemListCommandTreeNode extends CommandTreeNode { return CommandResult.FAILURE; } - Type type = Type.get(args[1]); + MMOItemType type = MMOItemType.get(args[1]); sender.sendMessage(ChatColor.YELLOW + "" + ChatColor.STRIKETHROUGH + "-----------------------------------------------------"); sender.sendMessage(ChatColor.GREEN + "List of all items in " + type.getId().toLowerCase() + ".yml:"); FileConfiguration config = type.getConfigFile().getConfig(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/TakeCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/TakeCommandTreeNode.java index 937abcbe..439af186 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/TakeCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/TakeCommandTreeNode.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.Parameter; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.command.MMOItemsCommandTreeRoot; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; @@ -36,7 +36,7 @@ public class TakeCommandTreeNode extends CommandTreeNode { try { // Target item & player - final Type type = MMOItems.plugin.getTypes().getOrThrow(args[1].toUpperCase().replace("-", "_")); + final MMOItemType type = MMOItems.plugin.getTypes().getOrThrow(args[1].toUpperCase().replace("-", "_")); final String id = args[2].toUpperCase().replace("-", "_"); final Player target = Bukkit.getPlayer(args[3]); Validate.notNull(target, "Could not find player called '" + args[3] + "'."); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/list/TypeCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/list/TypeCommandTreeNode.java index 12b798cc..a45556fe 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/list/TypeCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/list/TypeCommandTreeNode.java @@ -1,12 +1,11 @@ package net.Indyuce.mmoitems.command.mmoitems.list; +import io.lumine.mythic.lib.command.api.CommandTreeNode; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import io.lumine.mythic.lib.command.api.CommandTreeNode; - public class TypeCommandTreeNode extends CommandTreeNode { public TypeCommandTreeNode(CommandTreeNode parent) { super(parent, "type"); @@ -17,7 +16,7 @@ public class TypeCommandTreeNode extends CommandTreeNode { sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Item Types " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + ChatColor.LIGHT_PURPLE + " Item Types " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------"); - for (Type type : MMOItems.plugin.getTypes().getAll()) + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) sender.sendMessage("* " + ChatColor.LIGHT_PURPLE + type.getName() + " (" + type.getId() + ")"); return CommandResult.SUCCESS; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/revid/RevIDActionCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/revid/RevIDActionCommandTreeNode.java index e4677e18..ba769841 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/revid/RevIDActionCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/revid/RevIDActionCommandTreeNode.java @@ -1,10 +1,10 @@ package net.Indyuce.mmoitems.command.mmoitems.revid; +import io.lumine.mythic.lib.command.api.CommandTreeNode; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ConfigFile; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; -import io.lumine.mythic.lib.command.api.CommandTreeNode; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -28,13 +28,13 @@ public class RevIDActionCommandTreeNode extends CommandTreeNode { public CommandResult execute(CommandSender sender, String[] args) { if (args.length < 3) return CommandResult.THROW_USAGE; - if (!Type.isValid(args[2]) && !args[2].equalsIgnoreCase("all")) { + if (!MMOItemType.isValid(args[2]) && !args[2].equalsIgnoreCase("all")) { sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[2].toUpperCase().replace("-", "_") + "."); sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED + " to see all the available item types."); return CommandResult.FAILURE; } - Type type = args[2].equalsIgnoreCase("all") ? null : Type.get(args[2]); + MMOItemType type = args[2].equalsIgnoreCase("all") ? null : MMOItemType.get(args[2]); List templates = new ArrayList<>(type == null ? MMOItems.plugin.getTemplates().collectTemplates() : MMOItems.plugin.getTemplates().getTemplates(type)); int failed = 0; for(MMOItemTemplate template : templates) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/MMOItemsMetrics.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/MMOItemsMetrics.java index a3c13fe5..419aaa1a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/MMOItemsMetrics.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/MMOItemsMetrics.java @@ -2,17 +2,16 @@ package net.Indyuce.mmoitems.comp; import io.lumine.mythic.lib.metrics.bukkit.Metrics; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; public class MMOItemsMetrics extends Metrics { public MMOItemsMetrics() { super(MMOItems.plugin); - addCustomChart(new Metrics.SingleLineChart("items", () -> { - int total = 0; - for (Type type : MMOItems.plugin.getTypes().getAll()) - total += type.getConfigFile().getConfig().getKeys(false).size(); - return total; - })); + addCustomChart(new Metrics.SingleLineChart("items", () -> MMOItems.plugin.getTypes().getAll() + .stream() + .map(MMOItemType::getConfigFile) + .map(configFile -> configFile.getConfig().getKeys(false).size()) + .reduce(0, Integer::sum))); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/MMOItemsRewardTypes.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/MMOItemsRewardTypes.java index 4de1484a..e971b5ad 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/MMOItemsRewardTypes.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/MMOItemsRewardTypes.java @@ -1,7 +1,8 @@ package net.Indyuce.mmoitems.comp; -import java.util.List; - +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.api.player.PlayerData; import org.black_ixx.bossshop.core.BSBuy; import org.black_ixx.bossshop.core.rewards.BSRewardType; import org.black_ixx.bossshop.managers.ClassManager; @@ -10,9 +11,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.player.PlayerData; +import java.util.List; public class MMOItemsRewardTypes extends BSRewardType { @@ -49,7 +48,7 @@ public class MMOItemsRewardTypes extends BSRewardType { for (String item : (List) reward) try { String[] split = item.split("\\."); - Type type = MMOItems.plugin.getTypes().get(split[0].toUpperCase().replace("-", "_")); + MMOItemType type = MMOItems.plugin.getTypes().get(split[0].toUpperCase().replace("-", "_")); for (ItemStack drop : player.getInventory().addItem(MMOItems.plugin.getItem(type, split[1], PlayerData.get(player))) .values()) player.getWorld().dropItem(player.getLocation(), drop); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/denizen/DenizenHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/denizen/DenizenHook.java index b4cca618..41e927b0 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/denizen/DenizenHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/denizen/DenizenHook.java @@ -7,7 +7,7 @@ import com.denizenscript.denizencore.objects.core.MapTag; import com.denizenscript.denizencore.objects.properties.PropertyParser; import com.denizenscript.denizencore.tags.TagManager; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; public class DenizenHook { /** @@ -53,7 +53,7 @@ public class DenizenHook { } String typeName = type.toString().replace("-", "_").toUpperCase(); - Type parsedType = MMOItems.plugin.getTypes().get(typeName); + MMOItemType parsedType = MMOItems.plugin.getTypes().get(typeName); if (parsedType == null) { attribute.echoError("Invalid type - cannot find type with name '" + typeName + "'"); return null; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTemplateTag.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTemplateTag.java index ab27b309..81a3a6f8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTemplateTag.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/denizen/MMOItemTemplateTag.java @@ -10,19 +10,19 @@ import com.denizenscript.denizencore.tags.ObjectTagProcessor; import com.denizenscript.denizencore.tags.TagContext; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ItemTier; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import java.util.Random; public class MMOItemTemplateTag extends SimpleTag { - private final Type type; + private final MMOItemType type; private final String id; private static final Random random = new Random(); - public MMOItemTemplateTag(Type type, String id) { + public MMOItemTemplateTag(MMOItemType type, String id) { this.type = type; this.id = id; } @@ -134,7 +134,7 @@ public class MMOItemTemplateTag extends SimpleTag { String typeId = split[0]; String itemId = split[1]; - Type type = MMOItems.plugin.getTypes().getOrThrow(typeId); + MMOItemType type = MMOItems.plugin.getTypes().getOrThrow(typeId); MMOItems.plugin.getTemplates().getTemplateOrThrow(type, itemId); return new MMOItemTemplateTag(type, itemId); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/GetMMOItemObjective.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/GetMMOItemObjective.java index e2ad596d..ff2f59aa 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/GetMMOItemObjective.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/GetMMOItemObjective.java @@ -1,22 +1,21 @@ package net.Indyuce.mmoitems.comp.mmocore.load; +import io.lumine.mythic.lib.api.MMOLineConfig; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmocore.api.quest.ObjectiveProgress; +import net.Indyuce.mmocore.api.quest.QuestProgress; +import net.Indyuce.mmocore.api.quest.objective.Objective; +import net.Indyuce.mmocore.comp.citizens.CitizenInteractEvent; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import net.Indyuce.mmocore.api.quest.ObjectiveProgress; -import net.Indyuce.mmocore.api.quest.QuestProgress; -import net.Indyuce.mmocore.api.quest.objective.Objective; -import net.Indyuce.mmocore.comp.citizens.CitizenInteractEvent; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import io.lumine.mythic.lib.api.MMOLineConfig; -import io.lumine.mythic.lib.api.item.NBTItem; - public class GetMMOItemObjective extends Objective { - private final Type type; + private final MMOItemType type; private final String id; private final int required, npcId; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/ItemTemplateDropItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/ItemTemplateDropItem.java index 2c60770f..07bbb146 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/ItemTemplateDropItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/ItemTemplateDropItem.java @@ -1,18 +1,17 @@ package net.Indyuce.mmoitems.comp.mmocore.load; -import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.api.player.PlayerData; -import org.apache.commons.lang.Validate; -import org.bukkit.inventory.ItemStack; - +import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.loot.LootBuilder; +import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.stat.data.SoulboundData; -import io.lumine.mythic.lib.api.MMOLineConfig; +import org.apache.commons.lang.Validate; +import org.bukkit.inventory.ItemStack; public class ItemTemplateDropItem extends ItemGenerationDropItem { private final MMOItemTemplate template; @@ -24,7 +23,7 @@ public class ItemTemplateDropItem extends ItemGenerationDropItem { String format = config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"); Validate.isTrue(MMOItems.plugin.getTypes().has(format), "Could not find item type with ID '" + format + "'"); - Type type = MMOItems.plugin.getTypes().get(format); + MMOItemType type = MMOItems.plugin.getTypes().get(format); String id = config.getString("id").replace("-", "_").toUpperCase(); Validate.isTrue(MMOItems.plugin.getTemplates().hasTemplate(type, id), "Could not find MMOItem with ID '" + id + "'"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/MMOItemTrigger.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/MMOItemTrigger.java index 9911f072..e04aabe6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/MMOItemTrigger.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/MMOItemTrigger.java @@ -5,8 +5,8 @@ import io.lumine.mythic.lib.api.util.SmartGive; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.apache.commons.lang.Validate; import org.bukkit.inventory.ItemStack; @@ -21,7 +21,7 @@ public class MMOItemTrigger extends Trigger { String format = config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"); Validate.isTrue(MMOItems.plugin.getTypes().has(format), "Could not find item type with ID '" + format + "'"); - Type type = MMOItems.plugin.getTypes().get(format); + MMOItemType type = MMOItems.plugin.getTypes().get(format); String id = config.getString("id").replace("-", "_").toUpperCase(); Validate.isTrue(MMOItems.plugin.getTemplates().hasTemplate(type, id), "Could not find MMOItem with ID '" + id + "'"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/RandomItemDropItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/RandomItemDropItem.java index f1e80a3a..8709d1c8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/RandomItemDropItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/mmocore/load/RandomItemDropItem.java @@ -6,13 +6,13 @@ import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ItemTier; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.item.template.explorer.ClassFilter; import net.Indyuce.mmoitems.api.item.template.explorer.TemplateExplorer; import net.Indyuce.mmoitems.api.item.template.explorer.TierFilter; import net.Indyuce.mmoitems.api.item.template.explorer.TypeFilter; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.RPGPlayer; import net.Indyuce.mmoitems.stat.data.SoulboundData; @@ -26,7 +26,7 @@ public class RandomItemDropItem extends ItemGenerationDropItem { // generation options private final boolean matchClass; private final String profess; - private final Type type; + private final MMOItemType type; private final ItemTier tier; public RandomItemDropItem(MMOLineConfig config) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java index 1ae9dde4..2aa40466 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java @@ -8,7 +8,7 @@ import io.lumine.mythic.lib.manager.StatManager; import io.lumine.mythic.lib.util.DefenseFormula; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -69,7 +69,7 @@ public class MMOItemsPlaceholders extends PlaceholderExpansion { if(identifier.startsWith("type_")) { String t = identifier.substring(5, identifier.lastIndexOf("_")).toUpperCase(); if(!MMOItems.plugin.getTypes().has(t)) return "Invalid type"; - Type type = Type.get(t); + MMOItemType type = MMOItemType.get(t); String pholder = identifier.substring(6 + t.length()).toLowerCase(); if ("total".equals(pholder)) return "" + MMOItems.plugin.getTemplates().getTemplates(type).size(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java index 9208d4b5..de1c6a84 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java @@ -11,6 +11,7 @@ import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.edition.NewItemEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.gui.edition.ItemEdition; import net.Indyuce.mmoitems.stat.BrowserDisplayIDX; import net.Indyuce.mmoitems.util.MMOUtils; @@ -32,7 +33,7 @@ import java.util.*; public class ItemBrowser extends PluginInventory { private final Map cached = new LinkedHashMap<>(); - private final Type type; + private final MMOItemType type; private boolean deleteMode; // Slots used to display items based on the item type explored @@ -43,7 +44,7 @@ public class ItemBrowser extends PluginInventory { this(player, null); } - public ItemBrowser(Player player, Type type) { + public ItemBrowser(Player player, MMOItemType type) { super(player); this.type = type; @@ -72,11 +73,11 @@ public class ItemBrowser extends PluginInventory { Inventory inv = Bukkit.createInventory(this, 54, "Item Explorer"); // Fetch the list of types - List types = new ArrayList<>(MMOItems.plugin.getTypes().getAll()); + List types = new ArrayList<>(MMOItems.plugin.getTypes().getAll()); for (int j = min; j < Math.min(max, types.size()); j++) { // Current type to display into the GUI - Type currentType = types.get(j); + MMOItemType currentType = types.get(j); // Get number of items int items = MMOItems.plugin.getTemplates().getTemplates(currentType).size(); @@ -326,7 +327,7 @@ public class ItemBrowser extends PluginInventory { return inv; } - public Type getType() { + public MMOItemType getType() { return type; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java index b5a7a8b5..a8266202 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java @@ -40,7 +40,7 @@ public class ItemEdition extends EditionInventory { * it has to determine what stats can be applied first because otherwise * the for loop will just let some slots empty */ - List appliable = new ArrayList<>(getEdited().getType().getAvailableStats()).stream() + List> appliable = new ArrayList<>(getEdited().getType().getStats()).stream() .filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat)).toList(); Inventory inv = Bukkit.createInventory(this, 54, "Item Edition: " + getEdited().getId()); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java index 1ef9a575..57622d95 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java @@ -17,6 +17,7 @@ import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.Staff; import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.UntargetedWeapon; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.message.Message; import org.bukkit.Bukkit; @@ -242,7 +243,7 @@ public class ItemUse implements Listener { if (!picked.hasType()) return; - GemStone.ApplyResult result = ((GemStone) useItem).applyOntoItem(picked, Type.get(picked.getType())); + GemStone.ApplyResult result = ((GemStone) useItem).applyOntoItem(picked, MMOItemType.get(picked.getType())); if (result.getType() == GemStone.ResultType.NONE) return; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/ItemManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/ItemManager.java index bdf48866..1c8e3a37 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/ItemManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/ItemManager.java @@ -1,10 +1,9 @@ package net.Indyuce.mmoitems.manager; -import org.bukkit.inventory.ItemStack; - import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import org.bukkit.inventory.ItemStack; /** * ItemStack and MMOItem getters were moved over to MMOItems. There is no longer @@ -22,7 +21,7 @@ public class ItemManager { * @deprecated Use MMOItems.plugin.getMMOItem(Type, String) instead */ @Deprecated - public MMOItem getMMOItem(Type type, String id) { + public MMOItem getMMOItem(MMOItemType type, String id) { return MMOItems.plugin.getMMOItem(type, id); } @@ -33,7 +32,7 @@ public class ItemManager { * @deprecated Use MMOItems.plugin.getItem(Type, String) instead */ @Deprecated - public ItemStack getItem(Type type, String id) { + public ItemStack getItem(MMOItemType type, String id) { return MMOItems.plugin.getItem(type, id); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/PluginUpdateManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/PluginUpdateManager.java index b3aa7923..4f2eddb3 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/PluginUpdateManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/PluginUpdateManager.java @@ -5,7 +5,7 @@ import io.lumine.mythic.lib.skill.handler.SkillHandler; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.PluginUpdate; -import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.skill.RegisteredSkill; import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang.Validate; @@ -32,7 +32,7 @@ public class PluginUpdateManager { new String[]{"Applies a fix for skull textures values in 4.7.1.", "Texture values data storage changed in 4.7.1 due to the UUID change."}, sender -> { - for (Type type : MMOItems.plugin.getTypes().getAll()) { + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) { ConfigFile config = type.getConfigFile(); for (String key : config.getConfig().getKeys(false)) { ConfigurationSection section = config.getConfig().getConfigurationSection(key); @@ -130,7 +130,7 @@ public class PluginUpdateManager { register(new PluginUpdate(5, new String[]{"Transition to trigger types in 6.6.3", "Only scans through item configs"}, sender -> { - for (Type type : MMOItems.plugin.getTypes().getAll()) { + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) { ConfigFile config = type.getConfigFile(); for (String id : config.getConfig().getKeys(false)) { ConfigurationSection itemConfig = config.getConfig().getConfigurationSection(id); @@ -153,7 +153,7 @@ public class PluginUpdateManager { sender -> { // fixes stat formats - for (Type type : MMOItems.plugin.getTypes().getAll()) { + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) { ConfigFile config = type.getConfigFile(); for (String id : config.getConfig().getKeys(false)) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/RecipeManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/RecipeManager.java index 1a713bbc..3a692135 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/RecipeManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/RecipeManager.java @@ -10,10 +10,10 @@ import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackMessage; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.crafting.MMOItemUIFilter; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.AirIngredient; import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.MMOItemIngredient; import net.Indyuce.mmoitems.api.recipe.workbench.ingredients.VanillaIngredient; @@ -75,7 +75,7 @@ public class RecipeManager implements Reloadable { ffp.activatePrefix(true, "Custom Crafting"); // Every single type yes - for (Type type : MMOItems.plugin.getTypes().getAll()) { + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) { // Find their config FileConfiguration config = type.getConfigFile().getConfig(); @@ -198,7 +198,7 @@ public class RecipeManager implements Reloadable { } @NotNull - public NamespacedKey getRecipeKey(@NotNull Type type, @NotNull String id, @NotNull String recipeType, @NotNull String number) { + public NamespacedKey getRecipeKey(@NotNull MMOItemType type, @NotNull String id, @NotNull String recipeType, @NotNull String number) { return new NamespacedKey(MMOItems.plugin, recipeType + "_" + type.getId() + "_" + id + "_" + number); } @@ -364,7 +364,7 @@ public class RecipeManager implements Reloadable { if (poof.getParent() instanceof MMOItemUIFilter) { // Get those - Type miType = MMOItems.plugin.getTypes().getOrThrow(poof.getArgument()); + MMOItemType miType = MMOItems.plugin.getTypes().getOrThrow(poof.getArgument()); // Find template MMOItemTemplate mmo = MMOItems.plugin.getTemplates().getTemplateOrThrow(miType, poof.getData()); 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 0961ba27..9648a0f9 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 @@ -196,7 +196,7 @@ public class StatManager { .getAll() .stream() .filter(stat::isCompatible) - .forEach(type -> type.getAvailableStats().add(stat)); + .forEach(type -> type.getStats().add(stat)); } private void registerCustomStat(@NotNull ConfigurationSection section) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/TemplateManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/TemplateManager.java index d9f1b600..41d60f1b 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/TemplateManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/TemplateManager.java @@ -1,25 +1,27 @@ package net.Indyuce.mmoitems.manager; +import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.ItemTier; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.item.template.TemplateModifier; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.util.TemplateMap; -import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import org.apache.commons.lang.Validate; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; public class TemplateManager implements Reloadable { @@ -42,7 +44,7 @@ public class TemplateManager implements Reloadable { * * @return If these two Strings represent a loaded MMOItem Template */ - public boolean hasTemplate(@Nullable Type type, @Nullable String id) { + public boolean hasTemplate(@Nullable MMOItemType type, @Nullable String id) { if (type == null || id == null) { return false; } return templates.hasValue(type, id); } @@ -54,7 +56,7 @@ public class TemplateManager implements Reloadable { */ public boolean hasTemplate(@Nullable NBTItem nbt) { if (nbt == null) { return false; } - return hasTemplate(Type.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID")); + return hasTemplate(MMOItemType.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID")); } /** @@ -65,8 +67,10 @@ public class TemplateManager implements Reloadable { * * @return A template of these qualifications if it found them, */ - @Nullable public MMOItemTemplate getTemplate(@Nullable Type type, @Nullable String id) { - if (type == null || id == null) { return null; } + @Nullable + @Contract("_, null -> null") + public MMOItemTemplate getTemplate(@Nullable MMOItemType type, @Nullable String id) { + if (type == null || id == null) return null; return templates.getValue(type, id); } @@ -77,9 +81,11 @@ public class TemplateManager implements Reloadable { * * @return The MMOItem Template parent of it, if it has any. */ - @Nullable public MMOItemTemplate getTemplate(@Nullable NBTItem nbt) { - if (nbt == null) { return null; } - return getTemplate(Type.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID")); + @Nullable + @Contract("null -> null") + public MMOItemTemplate getTemplate(@Nullable NBTItem nbt) { + if (nbt == null) return null; + return getTemplate(MMOItemType.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID")); } /** @@ -89,18 +95,22 @@ public class TemplateManager implements Reloadable { * @param id The item ID * @return MMOItem template if it exists, or throws an IAE otherwise */ - @NotNull public MMOItemTemplate getTemplateOrThrow(@Nullable Type type, @Nullable String id) { + @NotNull + @Contract("_, null -> fail") + public MMOItemTemplate getTemplateOrThrow(@Nullable MMOItemType type, @Nullable String id) { Validate.isTrue(type != null && hasTemplate(type, id), "Could not find a template with ID '" + id + "'"); return templates.getValue(type, id); } - @NotNull public Collection getTemplates(@NotNull Type type) { + @NotNull public Collection getTemplates(@NotNull MMOItemType type) { return templates.collectValues(type); } - @NotNull public ArrayList getTemplateNames(@NotNull Type type) { - ArrayList names = new ArrayList<>(); - for (MMOItemTemplate t : templates.collectValues(type)) { names.add(t.getId()); } - return names; + + @NotNull public List getTemplateNames(@NotNull MMOItemType type) { + return this.templates.collectValues(type) + .stream() + .map(MMOItemTemplate::getId) + .collect(Collectors.toList()); } /** @@ -122,7 +132,7 @@ public class TemplateManager implements Reloadable { * @param type The item type * @param id The item ID */ - public void unregisterTemplate(@NotNull Type type, @NotNull String id) { + public void unregisterTemplate(@NotNull MMOItemType type, @NotNull String id) { templates.removeValue(type, id); } @@ -133,7 +143,7 @@ public class TemplateManager implements Reloadable { * @param type The item type * @param id The item ID */ - public void deleteTemplate(@NotNull Type type, @NotNull String id) { + public void deleteTemplate(@NotNull MMOItemType type, @NotNull String id) { unregisterTemplate(type, id); ConfigFile config = type.getConfigFile(); @@ -153,7 +163,7 @@ public class TemplateManager implements Reloadable { * @param id The item ID */ @SuppressWarnings("UnusedReturnValue") - public MMOItemTemplate requestTemplateUpdate(@NotNull Type type, @NotNull String id) { + public MMOItemTemplate requestTemplateUpdate(@NotNull MMOItemType type, @NotNull String id) { templates.removeValue(type, id); try { @@ -220,7 +230,7 @@ public class TemplateManager implements Reloadable { * are initialized */ public void preloadTemplates() { - for (Type type : MMOItems.plugin.getTypes().getAll()) { + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) { FileConfiguration config = type.getConfigFile().getConfig(); for (String key : config.getKeys(false)) try { @@ -235,7 +245,6 @@ public class TemplateManager implements Reloadable { * Loads item generator modifiers and post load item templates. */ public void postloadTemplates() { - FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get()); ffp.activatePrefix(true, "Item Templates"); ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading template modifiers, please wait.."); @@ -296,7 +305,7 @@ public class TemplateManager implements Reloadable { ffp.activatePrefix(true, "Item Templates"); ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading item templates, please wait..."); - for (Type type : MMOItems.plugin.getTypes().getAll()) { + for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) { FileConfiguration config = type.getConfigFile().getConfig(); ffp.activatePrefix(true, "Item Templates \u00a78($r" + type.getId() + "\u00a78)"); for (String key : config.getKeys(false)) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/TypeManager.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/TypeManager.java index 83f22e0d..cf3afcbb 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/TypeManager.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/manager/TypeManager.java @@ -40,13 +40,12 @@ public class TypeManager implements Reloadable { .filter(typesSection::isConfigurationSection) .map(typesSection::getConfigurationSection) .filter(Objects::nonNull) - .map(s -> MMOItemType.load(this, s)) + .map(MMOItemType::load) .peek(this.types::add) .peek(mmoItemType -> mmoItemType.getStats().clear()) .forEach(mmoItemType -> MMOItems.plugin.getStats() .getAll() .forEach(stat -> mmoItemType.getStats().add(stat))); - // TODO: Add stats from type category // DEBUG MMOItems.log("Loaded " + this.types.size() + " item types."); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/BrowserDisplayIDX.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/BrowserDisplayIDX.java index eafc2184..63a90b8d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/BrowserDisplayIDX.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/BrowserDisplayIDX.java @@ -41,7 +41,7 @@ public class BrowserDisplayIDX extends DoubleStat { if (template == null) { continue; } Double armorIDX = null; - if (template.getType().getAvailableStats().contains(ItemStats.BROWSER_DISPLAY_IDX)) { + if (template.getType().getStats().contains(ItemStats.BROWSER_DISPLAY_IDX)) { NumericStatFormula indexData = (NumericStatFormula) template.getBaseItemData().get(ItemStats.BROWSER_DISPLAY_IDX); // Get value if it existed diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java index 5f1a19d0..622f7d14 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeconstruct.java @@ -1,7 +1,16 @@ package net.Indyuce.mmoitems.stat; -import java.util.List; - +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.ItemTier; +import net.Indyuce.mmoitems.api.event.item.DeconstructItemEvent; +import net.Indyuce.mmoitems.api.interaction.Consumable; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.api.player.PlayerData; +import net.Indyuce.mmoitems.api.util.message.Message; +import net.Indyuce.mmoitems.stat.type.BooleanStat; +import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -9,20 +18,10 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; - -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.util.MMOUtils; -import net.Indyuce.mmoitems.api.ItemTier; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.event.item.DeconstructItemEvent; -import net.Indyuce.mmoitems.api.interaction.Consumable; -import net.Indyuce.mmoitems.api.player.PlayerData; -import net.Indyuce.mmoitems.api.util.message.Message; -import net.Indyuce.mmoitems.stat.type.BooleanStat; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; -import io.lumine.mythic.lib.api.item.NBTItem; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class CanDeconstruct extends BooleanStat implements ConsumableItemInteraction { public CanDeconstruct() { super("CAN_DECONSTRUCT", Material.PAPER, "Can Deconstruct?", @@ -31,7 +30,7 @@ public class CanDeconstruct extends BooleanStat implements ConsumableItemInterac } @Override - public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) { + public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, MMOItemType targetType) { String itemTierTag = target.getString("MMOITEMS_TIER"); if (itemTierTag.equals("") || !consumable.getNBTItem().getBoolean("MMOITEMS_CAN_DECONSTRUCT")) return false; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java index 173b7e86..2b64fe1a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanDeskin.java @@ -7,6 +7,7 @@ import io.lumine.mythic.lib.api.util.SmartGive; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.interaction.Consumable; @@ -37,7 +38,7 @@ public class CanDeskin extends BooleanStat implements ConsumableItemInteraction } @Override - public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) { + public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, MMOItemType targetType) { final String skinId = target.getString("MMOITEMS_SKIN_ID"); Player player = playerData.getPlayer(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java index 71eb5d8d..51a7cbbb 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanIdentify.java @@ -1,22 +1,21 @@ package net.Indyuce.mmoitems.stat; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.api.event.item.IdentifyItemEvent; +import net.Indyuce.mmoitems.api.interaction.Consumable; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.api.item.util.identify.IdentifiedItem; +import net.Indyuce.mmoitems.api.player.PlayerData; +import net.Indyuce.mmoitems.api.util.message.Message; +import net.Indyuce.mmoitems.stat.type.BooleanStat; +import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; - -import net.Indyuce.mmoitems.util.MMOUtils; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.event.item.IdentifyItemEvent; -import net.Indyuce.mmoitems.api.interaction.Consumable; -import net.Indyuce.mmoitems.api.item.util.identify.IdentifiedItem; -import net.Indyuce.mmoitems.api.player.PlayerData; -import net.Indyuce.mmoitems.api.util.message.Message; -import net.Indyuce.mmoitems.stat.type.BooleanStat; -import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; -import io.lumine.mythic.lib.api.item.NBTItem; import org.jetbrains.annotations.NotNull; public class CanIdentify extends BooleanStat implements ConsumableItemInteraction { @@ -26,7 +25,7 @@ public class CanIdentify extends BooleanStat implements ConsumableItemInteractio } @Override - public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) { + public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, MMOItemType targetType) { if (targetType != null) return false; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java index 2332de71..8f2cb709 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/CanUnsocket.java @@ -2,18 +2,18 @@ package net.Indyuce.mmoitems.stat; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.util.MMOUtils; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.interaction.Consumable; import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.stat.data.GemSocketsData; import net.Indyuce.mmoitems.stat.data.GemstoneData; import net.Indyuce.mmoitems.stat.type.BooleanStat; import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction; +import net.Indyuce.mmoitems.util.MMOUtils; import net.Indyuce.mmoitems.util.Pair; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -37,7 +37,7 @@ public class CanUnsocket extends BooleanStat implements ConsumableItemInteractio } @Override - public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) { + public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, MMOItemType targetType) { /* * Cancel if the target is just not an MMOItem diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemTypeRestriction.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemTypeRestriction.java index 053c565c..9aff420d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemTypeRestriction.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/ItemTypeRestriction.java @@ -1,36 +1,30 @@ package net.Indyuce.mmoitems.stat; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - +import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; -import io.lumine.mythic.lib.api.util.ui.SilentNumbers; +import io.lumine.mythic.lib.api.util.AltChar; +import net.Indyuce.mmoitems.ItemStats; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.TypeSet; +import net.Indyuce.mmoitems.api.edition.StatEdition; +import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; -import net.Indyuce.mmoitems.stat.data.StringData; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.gui.edition.EditionInventory; +import net.Indyuce.mmoitems.stat.data.StringListData; import net.Indyuce.mmoitems.stat.type.ItemStat; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; - -import net.Indyuce.mmoitems.ItemStats; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.TypeSet; -import net.Indyuce.mmoitems.api.edition.StatEdition; -import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; -import net.Indyuce.mmoitems.gui.edition.EditionInventory; -import net.Indyuce.mmoitems.stat.data.StringListData; -import net.Indyuce.mmoitems.stat.data.random.RandomStatData; -import net.Indyuce.mmoitems.stat.data.type.StatData; -import net.Indyuce.mmoitems.stat.type.StringStat; -import io.lumine.mythic.lib.api.item.ItemTag; -import io.lumine.mythic.lib.api.util.AltChar; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + public class ItemTypeRestriction extends ItemStat { public ItemTypeRestriction() { super("ITEM_TYPE_RESTRICTION", Material.EMERALD, "Item Type Restriction", @@ -191,7 +185,7 @@ public class ItemTypeRestriction extends ItemStat implements C public UpgradeData getClearStatData() { return new UpgradeData(null, null, false, false, 0, 0, 0D); } @Override - public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) { + public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, MMOItemType targetType) { VolatileMMOItem mmoitem = consumable.getMMOItem(); Player player = playerData.getPlayer(); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ConsumableItemInteraction.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ConsumableItemInteraction.java index 4b58e000..b9118416 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ConsumableItemInteraction.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ConsumableItemInteraction.java @@ -1,11 +1,10 @@ package net.Indyuce.mmoitems.stat.type; -import org.bukkit.event.inventory.InventoryClickEvent; - -import net.Indyuce.mmoitems.api.Type; -import net.Indyuce.mmoitems.api.interaction.Consumable; -import net.Indyuce.mmoitems.api.player.PlayerData; import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.api.interaction.Consumable; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; +import net.Indyuce.mmoitems.api.player.PlayerData; +import org.bukkit.event.inventory.InventoryClickEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,5 +30,5 @@ public interface ConsumableItemInteraction { * (basically return true if it should be the only * consumable effect applied). */ - boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, @Nullable Type targetType); + boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, @Nullable MMOItemType targetType); } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java index bbcefc55..79a4c9ed 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/type/ItemStat.java @@ -2,9 +2,9 @@ package net.Indyuce.mmoitems.stat.type; import io.lumine.mythic.lib.api.item.ItemTag; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder; import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.type.StatData; @@ -166,7 +166,7 @@ public abstract class ItemStat, S extends StatData> /** * @return The stat ID * @deprecated Use getId() instead. Type is no longer an util since they can - * now be registered from external plugins + * now be registered from external plugins */ @Deprecated @NotNull @@ -184,8 +184,8 @@ public abstract class ItemStat, S extends StatData> /** * @return The NBT path used by the stat to save data in an item's NBTTags. - * The format is 'MMOITEMS_' followed by the stat name in capital - * letters only using _ + * The format is 'MMOITEMS_' followed by the stat name in capital + * letters only using _ */ @NotNull public String getNBTPath() { @@ -212,10 +212,9 @@ public abstract class ItemStat, S extends StatData> * @param type The item type to check * @return If a certain item type is compatible with this item stat */ - public boolean isCompatible(Type type) { + public boolean isCompatible(MMOItemType type) { String lower = type.getId().toLowerCase(); - return type.isSubtype() ? isCompatible(type.getParent()) - : !compatibleTypes.contains("!" + lower) && (compatibleTypes.contains("all") || compatibleTypes.contains(lower) + return !compatibleTypes.contains("!" + lower) && (compatibleTypes.contains("all") || compatibleTypes.contains(lower) || compatibleTypes.contains(type.getItemSet().getName().toLowerCase())); } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java index d47eed22..c2fc0f9a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java @@ -10,6 +10,7 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues; import io.lumine.mythic.lib.skill.trigger.TriggerType; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; +import net.Indyuce.mmoitems.api.item.type.MMOItemType; import org.apache.commons.codec.binary.Base64; import org.bukkit.ChatColor; import org.bukkit.Color; @@ -25,6 +26,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; @@ -190,10 +192,10 @@ public class MMOUtils { * @return The MMOItem Type of this item, if it is a MMOItem */ @Nullable - public static Type getType(@Nullable NBTItem nbtItem) { + @Contract("null -> null") + public static MMOItemType getType(@Nullable NBTItem nbtItem) { if (nbtItem == null || !nbtItem.hasType()) return null; - // Try that one instead return MMOItems.plugin.getTypes().get(nbtItem.getType()); } diff --git a/MMOItems-Dist/src/main/resources/default/type-categories.yml b/MMOItems-Dist/src/main/resources/default/type-categories.yml deleted file mode 100644 index 58fdb4af..00000000 --- a/MMOItems-Dist/src/main/resources/default/type-categories.yml +++ /dev/null @@ -1,12 +0,0 @@ -SPLASHING: - - # The display parameter is used to display the item in both - # the item brower and the recipe list when shifting a - # workbench. You can use durability for custom textures. - # In 1.14, durability is replaced by CustomModelData. - display: IRON_SWORD:0 - - # Name displayed in the item lore. - name: 'Splashing' - - lore-format: ""