I am trying to detect the crossbow in the players hand (it is a cutom item), but only the bow (also a custom item) seems to be working the way I have it set up right now. Only the bow will show "fire" (and run the code properly) when I test each item.
@EventHandler
public void playerBowShoot(EntityShootBowEvent e) {
Entity entity = e.getEntity();
Entity arrow = e.getProjectile();
if (entity.getType().equals(EntityType.PLAYER)) {
Player p = (Player) entity;
if (p.getInventory().getItemInMainHand().getItemMeta().equals(Weapons.crossbow.getItemMeta())) {
Bukkit.broadcastMessage("fire");
arrow.setVelocity(p.getLocation().getDirection().multiply(100.0D));
}
if (p.getInventory().getItemInMainHand().getItemMeta().equals(Weapons.bow.getItemMeta())) {
Bukkit.broadcastMessage("fire");
arrow.setVelocity(p.getLocation().getDirection().multiply(100.0D));
}
}
}