From dccb3947756b5caf1b52d606675678b6571187bd Mon Sep 17 00:00:00 2001 From: Aria Date: Wed, 2 Oct 2019 01:40:26 +0200 Subject: [PATCH] Offhand ranged check for melee hits. --- .../net/Indyuce/mmoitems/listener/ItemUse.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java b/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java index c9f1ffec..ebc4cdd2 100644 --- a/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java +++ b/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java @@ -118,7 +118,9 @@ public class ItemUse implements Listener { */ PlayerData playerData = PlayerData.get(player); NBTItem item = MMOItems.plugin.getNMS().getNBTItem(player.getInventory().getItemInMainHand()); + NBTItem offhandItem = MMOItems.plugin.getNMS().getNBTItem(player.getInventory().getItemInOffHand()); AttackResult result = new AttackResult(event.getDamage(), DamageType.WEAPON, DamageType.PHYSICAL); + if (item.hasType()) { Weapon weapon = new Weapon(playerData, item, item.getType()); @@ -138,6 +140,19 @@ public class ItemUse implements Listener { return; } } + if (offhandItem.hasType()) { + Weapon weapon = new Weapon(playerData, offhandItem, offhandItem.getType()); + + if(weapon.getMMOItem().getType().getItemSet() == TypeSet.RANGE) { + event.setCancelled(true); + return; + } + + if (!weapon.canBeUsed()) { + event.setCancelled(true); + return; + } + } /* * cast on-hit abilities and add the extra damage to the damage event