I am using Java with Maven and Spigot-API(1.19.4) to create a plugin which enhances item modifiers for weapons and armor if the enchantment is succesful(+5% per level, for total of 20 levels). The issue is, for some reason it does not apply the changes to the item. What could be an issue here? Do i have to maybe return some value in this method?(new to this) Here is the apply method:
private void applyEffects(ItemStack item, int whetLevel) {
double multiplier = 1 + (whetLevel * 0.05);
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null) return;
if(isWeapon(item)){
AttributeModifier currentAttackDamageModifier = null;
AttributeModifier currentAttackSpeedModifier = null;
if(itemMeta.getAttributeModifiers(Attribute.GENERIC_ATTACK_DAMAGE) != null){
for(AttributeModifier modifier : itemMeta.getAttributeModifiers(Attribute.GENERIC_ATTACK_DAMAGE)){
currentAttackDamageModifier = modifier;
break;
}
}
if(itemMeta.getAttributeModifiers(Attribute.GENERIC_ATTACK_SPEED) != null){
for(AttributeModifier modifier : itemMeta.getAttributeModifiers(Attribute.GENERIC_ATTACK_SPEED)){
currentAttackSpeedModifier = modifier;
break;
}
}
// Remove existing attribute modifiers to avoid stacking modifiers
for (Attribute attribute : Attribute.values()) {
itemMeta.removeAttributeModifier(attribute);
}
if(currentAttackDamageModifier != null){
AttributeModifier updatedAttackDamageModifier = new AttributeModifier(
currentAttackDamageModifier.getUniqueId(),
currentAttackDamageModifier.getName(),
currentAttackDamageModifier.getAmount()*multiplier,
currentAttackDamageModifier.getOperation(),
currentAttackDamageModifier.getSlot()
);
itemMeta.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, updatedAttackDamageModifier);
}
if(currentAttackSpeedModifier != null){
AttributeModifier updatedAttackSpeedModifier = new AttributeModifier(
currentAttackSpeedModifier.getUniqueId(),
currentAttackSpeedModifier.getName(),
currentAttackSpeedModifier.getAmount()*multiplier,
currentAttackSpeedModifier.getOperation(),
currentAttackSpeedModifier.getSlot()
);
itemMeta.addAttributeModifier(Attribute.GENERIC_ATTACK_SPEED, updatedAttackSpeedModifier);
}
}
if(isArmor(item)){
AttributeModifier currentArmorModifier = null;
AttributeModifier currentArmorToughnessModifier = null;
if(itemMeta.getAttributeModifiers(Attribute.GENERIC_ARMOR) != null){
for(AttributeModifier modifier : itemMeta.getAttributeModifiers(Attribute.GENERIC_ARMOR)){
currentArmorModifier = modifier;
break;
}
}
if(itemMeta.getAttributeModifiers(Attribute.GENERIC_ARMOR_TOUGHNESS) != null){
for(AttributeModifier modifier : itemMeta.getAttributeModifiers(Attribute.GENERIC_ARMOR_TOUGHNESS)){
currentArmorToughnessModifier = modifier;
break;
}
}
// Remove existing attribute modifiers to avoid stacking modifiers
for (Attribute attribute : Attribute.values()) {
itemMeta.removeAttributeModifier(attribute);
}
if(currentArmorModifier != null){
AttributeModifier updatedArmorModifier = new AttributeModifier(
currentArmorModifier.getUniqueId(),
currentArmorModifier.getName(),
currentArmorModifier.getAmount()*multiplier,
currentArmorModifier.getOperation(),
currentArmorModifier.getSlot()
);
itemMeta.addAttributeModifier(Attribute.GENERIC_ARMOR, updatedArmorModifier);
}
if(currentArmorToughnessModifier != null){
AttributeModifier updatedArmorToughnessModifier = new AttributeModifier(
currentArmorToughnessModifier.getUniqueId(),
currentArmorToughnessModifier.getName(),
currentArmorToughnessModifier.getAmount()*multiplier,
currentArmorToughnessModifier.getOperation(),
currentArmorToughnessModifier.getSlot()
);
itemMeta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, updatedArmorToughnessModifier);
}
}
item.setItemMeta(itemMeta);
}