From 5d59a10b0599a1d8c10b9c49ed0632b68f850f5a Mon Sep 17 00:00:00 2001 From: Gunging <48371009+Gunging@users.noreply.github.com> Date: Sun, 21 Nov 2021 14:16:54 -0600 Subject: [PATCH] Added backwards compatibility with `ON_HIT` and `WHEN_HIT` triggers. Max Upgrades may now show up in lore if included in lore-format.yml --- .../java/net/Indyuce/mmoitems/MMOItems.java | 39 +++++------------ .../api/crafting/MMOItemUIFilter.java | 5 +-- .../net/Indyuce/mmoitems/stat/Enchants.java | 43 +++++++++++-------- .../Indyuce/mmoitems/stat/UpgradeStat.java | 13 +++++- .../mmoitems/stat/data/AbilityData.java | 21 ++++++++- 5 files changed, 67 insertions(+), 54 deletions(-) diff --git a/src/main/java/net/Indyuce/mmoitems/MMOItems.java b/src/main/java/net/Indyuce/mmoitems/MMOItems.java index e73ac335..41298178 100644 --- a/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -617,6 +617,7 @@ public class MMOItems extends LuminePlugin { */ @Nullable public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, @Nullable PlayerData player) { + if (type == null || id == null) { return null; } // Valid template? MMOItemTemplate found = getTemplates().getTemplate(type, id); @@ -633,9 +634,7 @@ public class MMOItems extends LuminePlugin { * template has the 'tiered' option */ @Nullable - public ItemStack getItem(@NotNull Type type, @NotNull String id, @NotNull PlayerData player) { - Validate.notNull(type, "Type cannot be null"); - Validate.notNull(id, "ID cannot be null"); + public ItemStack getItem(@Nullable Type type, @Nullable String id, @NotNull PlayerData player) { // Valid MMOItem? MMOItem m = getMMOItem(type, id, player); @@ -652,9 +651,8 @@ public class MMOItems extends LuminePlugin { * specific item level and item tier */ @Nullable - public MMOItem getMMOItem(@NotNull Type type, @NotNull String id, int itemLevel, @Nullable ItemTier itemTier) { - Validate.notNull(type, "Type cannot be null"); - Validate.notNull(id, "ID cannot be null"); + public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { + if (type == null || id == null) { return null; } // Valid template? MMOItemTemplate found = getTemplates().getTemplate(type, id); @@ -667,13 +665,12 @@ public class MMOItems extends LuminePlugin { /** * @param itemLevel The desired item level * @param itemTier The desired item tier, can be null + * * @return Generates an item given an item template with a * specific item level and item tier */ @Nullable - public ItemStack getItem(@NotNull Type type, @NotNull String id, int itemLevel, @Nullable ItemTier itemTier) { - Validate.notNull(type, "Type cannot be null"); - Validate.notNull(id, "ID cannot be null"); + public ItemStack getItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) { // Valid MMOItem? MMOItem m = getMMOItem(type, id, itemLevel, itemTier); @@ -691,17 +688,7 @@ public class MMOItems extends LuminePlugin { * Will return null if such MMOItem does not exist. */ @Nullable - public MMOItem getMMOItem(@NotNull Type type, @NotNull String id) { - Validate.notNull(type, "Type cannot be null"); - Validate.notNull(id, "ID cannot be null"); - - // Valid template? - MMOItemTemplate found = getTemplates().getTemplate(type, id); - if (found == null) return null; - - // Build if found - return found.newBuilder(0, null).build(); - } + public MMOItem getMMOItem(@Nullable Type type, @Nullable String id) { return getMMOItem(type, id, 0, null); } /** * @return Generates an item given an item template. The item level will be @@ -713,9 +700,7 @@ public class MMOItems extends LuminePlugin { @Nullable public ItemStack getItem(@Nullable String type, @Nullable String id) { - if (type == null || id == null) { - return null; - } + if (type == null || id == null) { return null; } return getItem(getTypes().get(type), id); } @@ -728,15 +713,11 @@ public class MMOItems extends LuminePlugin { */ @Nullable public ItemStack getItem(@Nullable Type type, @Nullable String id) { - if (type == null || id == null) { - return null; - } + if (type == null || id == null) { return null; } // Valid MMOItem? MMOItem m = getMMOItem(type, id); - if (m == null) { - return null; - } + if (m == null) { return null; } // Build if found return m.newBuilder().build(); diff --git a/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java b/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java index 76a33168..88d001bb 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java +++ b/src/main/java/net/Indyuce/mmoitems/api/crafting/MMOItemUIFilter.java @@ -87,12 +87,11 @@ public class MMOItemUIFilter implements UIFilter { VolatileMMOItem vmmo = new VolatileMMOItem(asNBT); // Get - QuickNumberRange upgradeReq = SilentNumbers.rangeFromBracketsTab(dataments, "level"); + QuickNumberRange upgradeReq = SilentNumbers.rangeFromBracketsTab(dataments, "LEVEL"); if (upgradeReq != null) { // Upgrade data? - int identifiedLvl = 0; - if (vmmo.hasData(ItemStats.UPGRADE)) { identifiedLvl = vmmo.getUpgradeLevel(); } + int identifiedLvl = vmmo.getUpgradeLevel(); // Not matched? if (!upgradeReq.inRange(identifiedLvl)) { diff --git a/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java b/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java index caee898d..d0b48247 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/Enchants.java @@ -381,7 +381,7 @@ public class Enchants extends ItemStat implements Upgradable { return; } boolean additiveMerge = MMOItems.plugin.getConfig().getBoolean("stat-merging.additive-enchantments", false); - //SENCH//MMOItems.Log(" \u00a79>\u00a73>\u00a77 Separating Enchantments"); + //SENCH//MMOItems.log(" \u00a79>\u00a73>\u00a77 Separating Enchantments"); // Does it have enchantment data? if (mmoitem.hasData(ItemStats.ENCHANTS)) { @@ -390,14 +390,17 @@ public class Enchants extends ItemStat implements Upgradable { EnchantListData data = (EnchantListData) mmoitem.getData(ItemStats.ENCHANTS); StatHistory hist = StatHistory.from(mmoitem, ItemStats.ENCHANTS); - //SENCH//MMOItems.Log(" \u00a7b:\u00a73:\u00a79: \u00a77Early Analysis: \u00a73o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o"); - //SENCH//MMOItems.Log(" \u00a73> \u00a77History:"); - //SENCH//MMOItems.Log(" \u00a73=\u00a7b> \u00a77Original:"); - //SENCH//for (Enchantment e : ((EnchantListData) hist.getOriginalData()).getEnchants()) { MMOItems.Log(" \u00a7b * \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) hist.getOriginalData()).getLevel(e)); } - //SENCH//MMOItems.Log(" \u00a73=\u00a7b> \u00a77Stones:"); - //SENCH//for (UUID date : hist.getAllGemstones()) { MMOItems.Log(" \u00a7b==\u00a73> \u00a77" + date.toString()); for (Enchantment e : ((EnchantListData) hist.getGemstoneData(date)).getEnchants()) { MMOItems.Log(" \u00a7b *\u00a73* \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) hist.getGemstoneData(date)).getLevel(e)); } } - //SENCH//MMOItems.Log(" \u00a73=\u00a7b> \u00a77Externals:"); - //SENCH//for (StatData date : hist.getExternalData()) { MMOItems.Log(" \u00a7b==\u00a73> \u00a77 --------- "); for (Enchantment e : ((EnchantListData) date).getEnchants()) { MMOItems.Log(" \u00a7b *\u00a73* \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) date).getLevel(e)); } } + //SENCH//MMOItems.log(" \u00a7b:\u00a73:\u00a79: \u00a77Early Analysis: \u00a73o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o"); + //SENCH//MMOItems.log(" \u00a73=\u00a7b> \u00a77Active:"); + //SENCH//for (Enchantment e : data.getEnchants()) { MMOItems.log(" \u00a7b * \u00a77" + e.getName() + " \u00a7f" + data.getLevel(e)); } + + //SENCH//MMOItems.log(" \u00a73> \u00a77History:"); + //SENCH//MMOItems.log(" \u00a73=\u00a7b> \u00a77Original:"); + //SENCH//for (Enchantment e : ((EnchantListData) hist.getOriginalData()).getEnchants()) { MMOItems.log(" \u00a7b * \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) hist.getOriginalData()).getLevel(e)); } + //SENCH//MMOItems.log(" \u00a73=\u00a7b> \u00a77Stones:"); + //SENCH//for (UUID date : hist.getAllGemstones()) { MMOItems.log(" \u00a7b==\u00a73> \u00a77" + date.toString()); for (Enchantment e : ((EnchantListData) hist.getGemstoneData(date)).getEnchants()) { MMOItems.log(" \u00a7b *\u00a73* \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) hist.getGemstoneData(date)).getLevel(e)); } } + //SENCH//MMOItems.log(" \u00a73=\u00a7b> \u00a77Externals:"); + //SENCH//for (StatData date : hist.getExternalData()) { MMOItems.log(" \u00a7b==\u00a73> \u00a77 --------- "); for (Enchantment e : ((EnchantListData) date).getEnchants()) { MMOItems.log(" \u00a7b *\u00a73* \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) date).getLevel(e)); } } // All right, whats the expected enchantment levels? //HSY//MMOItems.log(" \u00a73-\u00a7a- \u00a77Enchantment Separation Recalculation \u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-\u00a73-\u00a7a-"); @@ -420,7 +423,7 @@ public class Enchants extends ItemStat implements Upgradable { int offset = actual - ideal; if (offset != 0) { discrepancies.put(e, offset); - //SENCH//MMOItems.Log("\u00a77 Act \u00a7f" + actual + "\u00a77 Ide \u00a73" + ideal + "\u00a77 Off \u00a79" + offset + " \u00a77 -- of \u00a7b" + e.getName() ); + //SENCH//MMOItems.log("\u00a77 Act \u00a7f" + actual + "\u00a77 Ide \u00a73" + ideal + "\u00a77 Off \u00a79" + offset + " \u00a77 -- of \u00a7b" + e.getName() ); } // Weird maximum enchantment @@ -429,7 +432,7 @@ public class Enchants extends ItemStat implements Upgradable { // We can only know that, if the actual is greater than the ideal, there is a greater external. if (actual > ideal) { discrepancies.put(e, actual); - //SENCH//MMOItems.Log("\u00a77 Act \u00a7f" + actual + "\u00a77 Ide \u00a73" + ideal + " \u00a77 -- of \u00a7b" + e.getName() ); + //SENCH//MMOItems.log("\u00a77 Act \u00a7f" + actual + "\u00a77 Ide \u00a73" + ideal + " \u00a77 -- of \u00a7b" + e.getName() ); } } } @@ -439,6 +442,8 @@ public class Enchants extends ItemStat implements Upgradable { // Generate enchantment list with offsets EnchantListData extraneous = new EnchantListData(); for (Enchantment e : discrepancies.keySet()) { + //SENCH//MMOItems.log("\u00a77 Discrepancy of \u00a7f" + discrepancies.get(e) + " \u00a77 -- in \u00a7b" + e.getName() ); + extraneous.addEnchant(e, discrepancies.get(e)); } @@ -446,14 +451,14 @@ public class Enchants extends ItemStat implements Upgradable { hist.registerExternalData(extraneous); } - //SENCH//MMOItems.Log(" \u00a7b:\u00a73:\u00a79: \u00a77Results \u00a79o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o"); - //SENCH//MMOItems.Log(" \u00a73> \u00a77History:"); - //SENCH//MMOItems.Log(" \u00a73=\u00a7b> \u00a77Original:"); - //SENCH//for (Enchantment e : ((EnchantListData) hist.getOriginalData()).getEnchants()) { MMOItems.Log(" \u00a7b * \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) hist.getOriginalData()).getLevel(e)); } - //SENCH//MMOItems.Log(" \u00a73=\u00a7b> \u00a77Stones:"); - //SENCH//for (UUID date : hist.getAllGemstones()) { MMOItems.Log(" \u00a7b==\u00a73> \u00a77" + date.toString()); for (Enchantment e : ((EnchantListData) hist.getGemstoneData(date)).getEnchants()) { MMOItems.Log(" \u00a7b *\u00a73* \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) hist.getGemstoneData(date)).getLevel(e)); } } - //SENCH//MMOItems.Log(" \u00a73=\u00a7b> \u00a77Externals:"); - //SENCH//for (StatData date : hist.getExternalData()) { MMOItems.Log(" \u00a7b==\u00a73> \u00a77 --------- "); for (Enchantment e : ((EnchantListData) date).getEnchants()) { MMOItems.Log(" \u00a7b *\u00a73* \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) date).getLevel(e)); } } + //SENCH//MMOItems.log(" \u00a7b:\u00a73:\u00a79: \u00a77Results \u00a79o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o"); + //SENCH//MMOItems.log(" \u00a73> \u00a77History:"); + //SENCH//MMOItems.log(" \u00a73=\u00a7b> \u00a77Original:"); + //SENCH//for (Enchantment e : ((EnchantListData) hist.getOriginalData()).getEnchants()) { MMOItems.log(" \u00a7b * \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) hist.getOriginalData()).getLevel(e)); } + //SENCH//MMOItems.log(" \u00a73=\u00a7b> \u00a77Stones:"); + //SENCH//for (UUID date : hist.getAllGemstones()) { MMOItems.log(" \u00a7b==\u00a73> \u00a77" + date.toString()); for (Enchantment e : ((EnchantListData) hist.getGemstoneData(date)).getEnchants()) { MMOItems.log(" \u00a7b *\u00a73* \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) hist.getGemstoneData(date)).getLevel(e)); } } + //SENCH//MMOItems.log(" \u00a73=\u00a7b> \u00a77Externals:"); + //SENCH//for (StatData date : hist.getExternalData()) { MMOItems.log(" \u00a7b==\u00a73> \u00a77 --------- "); for (Enchantment e : ((EnchantListData) date).getEnchants()) { MMOItems.log(" \u00a7b *\u00a73* \u00a77" + e.getName() + " \u00a7f" + ((EnchantListData) date).getLevel(e)); } } } } diff --git a/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java b/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java index 7231a285..7320f333 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/UpgradeStat.java @@ -60,7 +60,18 @@ public class UpgradeStat extends ItemStat implements ConsumableItemInteraction { } @Override - public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StatData data) { item.addItemTag(getAppliedNBT(data)); } + public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StatData data) { + if (!(data instanceof UpgradeData)) { return; } + + // Show in lore + item.addItemTag(getAppliedNBT(data)); + + // Show in lore + if (((UpgradeData) data).getMaxUpgrades() > 0) { + item.getLore().insert(getPath(), + MMOItems.plugin.getLanguage().getStatFormat(getPath()).replace("#", String.valueOf(((UpgradeData) data).getMaxUpgrades()))); + } + } @NotNull @Override diff --git a/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java b/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java index bdddf1ad..55f7ffc7 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/data/AbilityData.java @@ -7,10 +7,12 @@ import io.lumine.mythic.lib.skill.trigger.TriggerType; import io.lumine.mythic.lib.skill.trigger.TriggeredSkill; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.ability.Ability; +import net.Indyuce.mmoitems.api.crafting.trigger.Trigger; import net.Indyuce.mmoitems.api.player.PlayerData; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashMap; @@ -52,7 +54,7 @@ public class AbilityData implements MythicSkillInfo, TriggeredSkill { public AbilityData(JsonObject object) { ability = MMOItems.plugin.getAbilities().getAbility(object.get("Id").getAsString()); - triggerType = TriggerType.valueOf(object.get("CastMode").getAsString()); + triggerType = backwardsCompatibleTriggerType(object.get("CastMode").getAsString()); JsonObject modifiers = object.getAsJsonObject("Modifiers"); modifiers.entrySet().forEach(entry -> setModifier(entry.getKey(), entry.getValue().getAsDouble())); @@ -66,13 +68,28 @@ public class AbilityData implements MythicSkillInfo, TriggeredSkill { ability = MMOItems.plugin.getAbilities().getAbility(abilityFormat); String modeFormat = config.getString("mode").toUpperCase().replace("-", "_").replace(" ", "_"); - triggerType = TriggerType.valueOf(modeFormat); + triggerType = backwardsCompatibleTriggerType(modeFormat); for (String key : config.getKeys(false)) if (!key.equalsIgnoreCase("mode") && !key.equalsIgnoreCase("type") && ability.getModifiers().contains(key)) modifiers.put(key, config.getDouble(key)); } + /** + * @param name The trigger name that may be in old format + * @return The trigger type this represents + * @throws IllegalArgumentException If this does not match any trigger type + */ + @NotNull TriggerType backwardsCompatibleTriggerType(@Nullable String name) throws IllegalArgumentException { + if (name == null) { throw new IllegalArgumentException("Trigger cannot be null"); } + + switch (name) { + case "ON_HIT": return TriggerType.ATTACK; + case "WHEN_HIT": return TriggerType.DAMAGED_BY_ENTITY; + default: return TriggerType.valueOf(name); + } + } + public AbilityData(Ability ability, TriggerType triggerType) { this.ability = ability; this.triggerType = triggerType;