Skip to content

Commit

Permalink
Add trait modifier methods to ItemManager
Browse files Browse the repository at this point in the history
- Deprecate addModifier, getModifiers, and removeModifier to be replaced by addStatModifier, getStatModifiers, and removeStatModifier
  • Loading branch information
Archy-X committed Jul 8, 2024
1 parent dd473ea commit a600232
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
*
Expand All @@ -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);

/**
Expand All @@ -38,10 +60,25 @@ public interface ItemManager {
* @param type the modifier type
* @return a list of modifiers
*/
List<StatModifier> 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<TraitModifier> getTraitModifiers(ItemStack item, ModifierType type);

/**
* @deprecated use {@link #getStatModifiers(ItemStack, ModifierType)}
*/
@Deprecated
List<StatModifier> 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.
*
Expand All @@ -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);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +19,7 @@
import java.util.List;
import java.util.Map;

@SuppressWarnings("deprecation")
public class ApiItemManager implements ItemManager {

private final AuraSkills plugin;
Expand All @@ -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) {
Expand All @@ -38,18 +41,56 @@ public ItemStack addModifier(ItemStack item, ModifierType type, Stat stat, doubl
}

@Override
public List<StatModifier> 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<StatModifier> 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<TraitModifier> getTraitModifiers(ItemStack item, ModifierType type) {
SkillsItem skillsItem = new SkillsItem(item, plugin);
return skillsItem.getTraitModifiers(type);
}

@Override
public List<StatModifier> 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);
Expand Down

0 comments on commit a600232

Please sign in to comment.