Solved How to cancel bow event?

Discussion in 'Plugin Development' started by Tim_M, Aug 18, 2021.

Thread Status:
Not open for further replies.
  1. Offline


    I'm trying to make a bow that shoots wither skulls. The player needs to have atleast one wither skull in their inventory to use the bow. How can I make it impossible for the player to charge the bow if they don't have the required items?
  2. Offline


    Having trouble understanding the issue. By default, doesn't a bow not charge when the player has no items it is able to shoot?
  3. Offline


    Well yes but that's only for arrows. Even if I have wither skulls in my inventory I won't be able to shoot. And, in turn, if I don't have any wither skulls I shouldn't be able to shoot (even if I have arrows).
  4. Offline


    you could get the player's inventory and check for the material wither skull in their inventory in an if statement. so that if they don't have skulls you can cancel the event but if they do continue the event.

    Psuedo code
    public void onShoot(EntityShootBowEvent event) {
    if (event.getShooter instanceof Player) {
    Player player = event.getShooter();
    if (player.getInventory.getItemInOffHand() != null && player.getInventory().getItemInOffHand().equals(Material.WITHER_SKELETON_SKULL)) {
    Last edited: Aug 22, 2021
  5. Offline


    I get what you're saying. What you can do is have a PlayerInteractEvent and check if they right-clicked and they are holding your bow, if so then just cancel the event.
  6. Offline


    I wasn't sure if that triggers when the player uses a bow. Thanks for your response! Marking solved.
Thread Status:
Not open for further replies.

Share This Page