From 44b70a8394bac7d253277749fef370d9fb9ee1e3 Mon Sep 17 00:00:00 2001 From: hyperdefined Date: Wed, 22 Jan 2025 17:02:05 -0500 Subject: [PATCH] fix #90 --- .../lol/hyper/toolstats/events/ShootBow.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/lol/hyper/toolstats/events/ShootBow.java b/src/main/java/lol/hyper/toolstats/events/ShootBow.java index 7284067..4afb626 100644 --- a/src/main/java/lol/hyper/toolstats/events/ShootBow.java +++ b/src/main/java/lol/hyper/toolstats/events/ShootBow.java @@ -56,10 +56,8 @@ public class ShootBow implements Listener { return; } - PlayerInventory inventory = player.getInventory(); - ItemStack heldBow = getBow(inventory); - - // player swapped + ItemStack heldBow = getBow(player.getInventory()); + // player swapped or we can't get the bow if (heldBow == null) { return; } @@ -68,22 +66,23 @@ public class ShootBow implements Listener { } private static @Nullable ItemStack getBow(PlayerInventory inventory) { - boolean isMainHand = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW; - boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW; - ItemStack heldBow = null; - if (isMainHand) { - heldBow = inventory.getItemInMainHand(); + ItemStack main = inventory.getItemInMainHand(); + ItemStack offHand = inventory.getItemInOffHand(); + + boolean isMain = main.getType() == Material.BOW || main.getType() == Material.CROSSBOW; + boolean isOffHand = offHand.getType() == Material.BOW || offHand.getType() == Material.CROSSBOW; + + // if the player is holding a bow in their main hand, use that one + // if the bow is in their offhand instead, use that one after checking main hand + // Minecraft prioritizes main hand if the player holds in both hands + if (isMain) { + return main; } if (isOffHand) { - heldBow = inventory.getItemInOffHand(); + return offHand; } - // if the player is holding a bow in both hands - // default to main hand since that takes priority - if (isMainHand && isOffHand) { - heldBow = inventory.getItemInMainHand(); - } - return heldBow; + return null; } private void updateArrowsShot(ItemStack bow) {