From 56b92eebbf405fd6f006b06a1d118db2094dfba7 Mon Sep 17 00:00:00 2001 From: Jules Date: Thu, 18 Apr 2024 16:02:02 -0700 Subject: [PATCH] Fixed mainhand abilities applying in offhand --- .../Indyuce/mmoitems/api/player/PlayerData.java | 15 ++++++--------- .../api/player/inventory/EquippedItem.java | 13 ++++--------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java index 99066fb8..8eb0cefd 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java @@ -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 -> { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java index 4e5f6a8d..4d2c3412 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java @@ -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 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() {