From a6002325e1799bcba728b3d7e069cba963914e2b Mon Sep 17 00:00:00 2001 From: Archy-X <63976867+Archy-X@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:06:56 -0700 Subject: [PATCH] Add trait modifier methods to ItemManager - Deprecate addModifier, getModifiers, and removeModifier to be replaced by addStatModifier, getStatModifiers, and removeStatModifier --- .../auraskills/api/item/ItemManager.java | 61 ++++++++++++++++++- .../bukkit/item/ApiItemManager.java | 47 +++++++++++++- 2 files changed, 102 insertions(+), 6 deletions(-) diff --git a/api-bukkit/src/main/java/dev/aurelium/auraskills/api/item/ItemManager.java b/api-bukkit/src/main/java/dev/aurelium/auraskills/api/item/ItemManager.java index 727825428..5a5d5e78d 100644 --- a/api-bukkit/src/main/java/dev/aurelium/auraskills/api/item/ItemManager.java +++ b/api-bukkit/src/main/java/dev/aurelium/auraskills/api/item/ItemManager.java @@ -6,6 +6,9 @@ import dev.aurelium.auraskills.api.stat.Stat; import dev.aurelium.auraskills.api.stat.StatModifier; import dev.aurelium.auraskills.api.stat.Stats; +import dev.aurelium.auraskills.api.trait.Trait; +import dev.aurelium.auraskills.api.trait.TraitModifier; +import dev.aurelium.auraskills.api.trait.Traits; import org.bukkit.inventory.ItemStack; import org.spongepowered.configurate.ConfigurationNode; @@ -18,7 +21,7 @@ public interface ItemManager { /** - * Adds a modifier to an item, with optional lore. This does not change the item passed in directly, + * Adds a stat modifier to an item, with optional lore. This does not change the item passed in directly, * you must use the returned ItemStack. This means the original ItemStack passed in is not changed at all, a new * one is created. * @@ -27,8 +30,27 @@ public interface ItemManager { * @param stat the stat to add (Use {@link Stats} enum for default stats) * @param value the value of the stat to add * @param lore whether to add lore - * @return a new ItemStack with the modifier + * @return a new ItemStack with the static modifier */ + ItemStack addStatModifier(ItemStack item, ModifierType type, Stat stat, double value, boolean lore); + + /** + * Adds a trait modifier to an item, with optional lore. This does not change the item passed in directly, + * you must use the returned ItemStack. + * + * @param item the original item + * @param type the {@link ModifierType} to add + * @param trait the trait to add (Use {@link Traits} enum for default stats) + * @param value the value of the trait to add + * @param lore whether to add lore + * @return a new ItemStack with the trait modifier + */ + ItemStack addTraitModifier(ItemStack item, ModifierType type, Trait trait, double value, boolean lore); + + /** + * @deprecated use {@link #addStatModifier(ItemStack, ModifierType, Stat, double, boolean)} + */ + @Deprecated ItemStack addModifier(ItemStack item, ModifierType type, Stat stat, double value, boolean lore); /** @@ -38,10 +60,25 @@ public interface ItemManager { * @param type the modifier type * @return a list of modifiers */ + List getStatModifiers(ItemStack item, ModifierType type); + + /** + * Gets a list of trait modifiers on an item for a given modifier type. + * + * @param item the item to get the trait modifiers of + * @param type the modifier type + * @return a list of modifiers + */ + List getTraitModifiers(ItemStack item, ModifierType type); + + /** + * @deprecated use {@link #getStatModifiers(ItemStack, ModifierType)} + */ + @Deprecated List getModifiers(ItemStack item, ModifierType type); /** - * Removes a modifier from an item for a given modifier type and stat. + * Removes a stat modifier from an item for a given modifier type and stat. * Does not modify the ItemStack passed in, instead returns a copy of the item with the * modifier removed. Will not remove any lore. * @@ -50,6 +87,24 @@ public interface ItemManager { * @param stat the stat of the modifier to remove * @return the item with the modifier removed */ + ItemStack removeStatModifier(ItemStack item, ModifierType type, Stat stat); + + /** + * Removes a trait modifier from an item for a given modifier type and stat. + * Does not modify the ItemStack passed in, instead returns a copy of the item with the + * modifier removed. Will not remove any lore. + * + * @param item The item to remove the modifier from. Does not get modified. + * @param type the modifier type + * @param trait the trait of the modifier to remove + * @return the item with the modifier removed + */ + ItemStack removeTraitModifier(ItemStack item, ModifierType type, Trait trait); + + /** + * @deprecated use {@link #removeStatModifier(ItemStack, ModifierType, Stat)} + */ + @Deprecated ItemStack removeModifier(ItemStack item, ModifierType type, Stat stat); /** diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/item/ApiItemManager.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/item/ApiItemManager.java index ebd8c95f8..a291dbe39 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/item/ApiItemManager.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/item/ApiItemManager.java @@ -7,6 +7,8 @@ import dev.aurelium.auraskills.api.skill.Skill; import dev.aurelium.auraskills.api.stat.Stat; import dev.aurelium.auraskills.api.stat.StatModifier; +import dev.aurelium.auraskills.api.trait.Trait; +import dev.aurelium.auraskills.api.trait.TraitModifier; import dev.aurelium.auraskills.bukkit.AuraSkills; import dev.aurelium.auraskills.bukkit.item.SkillsItem.MetaType; import dev.aurelium.auraskills.bukkit.util.ConfigurateItemParser; @@ -17,6 +19,7 @@ import java.util.List; import java.util.Map; +@SuppressWarnings("deprecation") public class ApiItemManager implements ItemManager { private final AuraSkills plugin; @@ -28,7 +31,7 @@ public ApiItemManager(AuraSkills plugin) { } @Override - public ItemStack addModifier(ItemStack item, ModifierType type, Stat stat, double value, boolean lore) { + public ItemStack addStatModifier(ItemStack item, ModifierType type, Stat stat, double value, boolean lore) { SkillsItem skillsItem = new SkillsItem(item, plugin); skillsItem.addModifier(MetaType.MODIFIER, type, stat, value); if (lore) { @@ -38,18 +41,56 @@ public ItemStack addModifier(ItemStack item, ModifierType type, Stat stat, doubl } @Override - public List getModifiers(ItemStack item, ModifierType type) { + public ItemStack addTraitModifier(ItemStack item, ModifierType type, Trait trait, double value, boolean lore) { + SkillsItem skillsItem = new SkillsItem(item, plugin); + skillsItem.addModifier(MetaType.TRAIT_MODIFIER, type, trait, value); + if (lore) { + skillsItem.addModifierLore(type, trait, value, plugin.getDefaultLanguage()); + } + return skillsItem.getItem(); + } + + @Override + public ItemStack addModifier(ItemStack item, ModifierType type, Stat stat, double value, boolean lore) { + return addStatModifier(item, type, stat, value, lore); + } + + @Override + public List getStatModifiers(ItemStack item, ModifierType type) { SkillsItem skillsItem = new SkillsItem(item, plugin); return skillsItem.getStatModifiers(type); } @Override - public ItemStack removeModifier(ItemStack item, ModifierType type, Stat stat) { + public List getTraitModifiers(ItemStack item, ModifierType type) { + SkillsItem skillsItem = new SkillsItem(item, plugin); + return skillsItem.getTraitModifiers(type); + } + + @Override + public List getModifiers(ItemStack item, ModifierType type) { + return getStatModifiers(item, type); + } + + @Override + public ItemStack removeStatModifier(ItemStack item, ModifierType type, Stat stat) { SkillsItem skillsItem = new SkillsItem(item, plugin); skillsItem.removeModifier(MetaType.MODIFIER, type, stat); return skillsItem.getItem(); } + @Override + public ItemStack removeTraitModifier(ItemStack item, ModifierType type, Trait trait) { + SkillsItem skillsItem = new SkillsItem(item, plugin); + skillsItem.removeModifier(MetaType.TRAIT_MODIFIER, type, trait); + return skillsItem.getItem(); + } + + @Override + public ItemStack removeModifier(ItemStack item, ModifierType type, Stat stat) { + return removeStatModifier(item, type, stat); + } + @Override public ItemStack addMultiplier(ItemStack item, ModifierType type, Skill skill, double value, boolean lore) { SkillsItem skillsItem = new SkillsItem(item, plugin);