From cdc7b32edb57a75087e34e47da644e95d374f1e3 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Tue, 18 Aug 2020 20:45:31 +0200 Subject: [PATCH] Fixed NPE's with unconventional weapons --- src/main/java/net/Indyuce/mmoitems/api/TypeSet.java | 4 ++++ .../net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java | 5 ++--- .../java/net/Indyuce/mmoitems/comp/RealDualWieldHook.java | 3 +-- src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java | 3 +-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java b/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java index daa8f41b..05469a99 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java +++ b/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java @@ -135,6 +135,10 @@ public enum TypeSet { this.attackHandler = attackHandler; } + public boolean hasAttackEffect() { + return attackHandler != null; + } + public void applyAttackEffect(CachedStats playerStats, LivingEntity target, Weapon weapon, ItemAttackResult result) { attackHandler.apply(playerStats, target, weapon, result); } diff --git a/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java b/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java index 9818a612..53878f2b 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java +++ b/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java @@ -4,7 +4,6 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -67,7 +66,7 @@ public class Weapon extends UseItem { return true; } - public ItemAttackResult targetedAttack(CachedStats stats, LivingEntity target, EquipmentSlot slot, ItemAttackResult result) { + public ItemAttackResult targetedAttack(CachedStats stats, LivingEntity target, ItemAttackResult result) { // cooldown double attackSpeed = getNBTItem().getStat(ItemStat.ATTACK_SPEED); @@ -75,7 +74,7 @@ public class Weapon extends UseItem { if (!hasEnoughResources(attackSpeed, CooldownType.ATTACK, true)) return result.setSuccessful(false); - if (!getNBTItem().getBoolean("MMOITEMS_DISABLE_ATTACK_PASSIVE")) + if (!getNBTItem().getBoolean("MMOITEMS_DISABLE_ATTACK_PASSIVE") && getMMOItem().getType().getItemSet().hasAttackEffect()) getMMOItem().getType().getItemSet().applyAttackEffect(stats, target, this, result); return result; diff --git a/src/main/java/net/Indyuce/mmoitems/comp/RealDualWieldHook.java b/src/main/java/net/Indyuce/mmoitems/comp/RealDualWieldHook.java index c5e9741a..5fc0d045 100644 --- a/src/main/java/net/Indyuce/mmoitems/comp/RealDualWieldHook.java +++ b/src/main/java/net/Indyuce/mmoitems/comp/RealDualWieldHook.java @@ -5,7 +5,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.inventory.EquipmentSlot; import com.evill4mer.RealDualWield.Api.PlayerDamageEntityWithOffhandEvent; @@ -59,7 +58,7 @@ public class RealDualWieldHook implements Listener { return; } - weapon.targetedAttack(stats = playerData.getStats().newTemporary(), target, EquipmentSlot.HAND, result.setSuccessful(true)); + weapon.targetedAttack(stats = playerData.getStats().newTemporary(), target, result); if (!result.isSuccessful()) { event.setCancelled(true); return; diff --git a/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java b/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java index 770f2161..b7d85fdd 100644 --- a/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java +++ b/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java @@ -145,7 +145,7 @@ public class ItemUse implements Listener { return; } - weapon.targetedAttack(stats = playerData.getStats().newTemporary(), target, EquipmentSlot.HAND, result.setSuccessful(true)); + weapon.targetedAttack(stats = playerData.getStats().newTemporary(), target, result); if (!result.isSuccessful()) { event.setCancelled(true); return; @@ -169,7 +169,6 @@ public class ItemUse implements Listener { * cast on-hit abilities and add the extra damage to the damage event */ result.applyEffects(stats == null ? stats = playerData.getStats().newTemporary() : stats, item, target); - event.setDamage(result.getDamage()); }