Fixed mainhand abilities applying in offhand

This commit is contained in:
Jules 2024-04-18 16:02:02 -07:00
parent ed76008a4f
commit 56b92eebbf
2 changed files with 10 additions and 18 deletions

View File

@ -162,7 +162,6 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable {
if (!item.isPlacementLegal() || !getRPG().canUse(nbtItem, false, false))
continue;
item.cacheItem();
inventory.getEquipped().add(item);
}
@ -170,21 +169,19 @@ public class PlayerData extends SynchronizedDataHolder implements Closeable {
Bukkit.getPluginManager().callEvent(new RefreshInventoryEvent(inventory.getEquipped(), getPlayer(), this));
for (EquippedItem equipped : inventory.getEquipped()) {
final VolatileMMOItem item = equipped.getCached();
// Abilities
if (item.hasData(ItemStats.ABILITIES))
for (AbilityData abilityData : ((AbilityListData) item.getData(ItemStats.ABILITIES)).getAbilities()) {
ModifierSource modSource = equipped.getCached().getType().getModifierSource();
getMMOPlayerData().getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", abilityData, equipped.getSlot(), modSource));
}
// Modifier application rules
final VolatileMMOItem item = equipped.getCached();
final ModifierSource source = item.getType().getModifierSource();
final EquipmentSlot equipmentSlot = equipped.getSlot();
if (!EquipmentSlot.MAIN_HAND.isCompatible(source, equipmentSlot))
continue;
// Abilities
if (item.hasData(ItemStats.ABILITIES))
for (AbilityData abilityData : ((AbilityListData) item.getData(ItemStats.ABILITIES)).getAbilities())
getMMOPlayerData().getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", abilityData, equipmentSlot, source));
// Apply permanent potion effects
if (item.hasData(ItemStats.PERM_EFFECTS))
((PotionEffectListData) item.getData(ItemStats.PERM_EFFECTS)).getEffects().forEach(effect -> {

View File

@ -3,21 +3,20 @@ package net.Indyuce.mmoitems.api.player.inventory;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.player.modifier.ModifierSource;
import io.lumine.mythic.lib.util.Lazy;
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 org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import java.util.Objects;
public abstract class EquippedItem {
private final NBTItem item;
private final EquipmentSlot slot;
private VolatileMMOItem cached;
private final Lazy<VolatileMMOItem> cached;
/**
* An item equipped by a player in a specific slot
@ -38,15 +37,11 @@ public abstract class EquippedItem {
public EquippedItem(NBTItem item, EquipmentSlot slot) {
this.item = item;
this.slot = slot;
cached = Lazy.of(() -> new VolatileMMOItem(item));
}
public VolatileMMOItem getCached() {
return Objects.requireNonNull(cached, "Item not cached yet");
}
public void cacheItem() {
Validate.isTrue(cached == null, "MMOItem has already been cached");
cached = new VolatileMMOItem(item);
return cached.get();
}
public NBTItem getNBT() {