Disable Sneaking when charging bow

Discussion in 'Spigot Plugin Development' started by Nopzakung, Apr 18, 2017.

  1. Question is above. What code can do that ?
     
  2. Listen to EntityShootBowEvent, check if it was a Player, check if the Player is sneaking, cancel the event.
     
    • Agree Agree x 2
    • Useful Useful x 1
  3. @EventHandler
    public void onShoot(EntityShootBowEvent e){
    if(e.getEntity() instanceof Player){
    Player player = (Player) e.getEntity();
    player.setSneaking(false);
    }
    }
     
    • Useful Useful x 2
  4. I mean when i'm charging bow, not shooting bow.

    I'm sorry, I'm not good in english.
     
    • Friendly Friendly x 1
  5. You can listen for interact event to do so
     
    • Like Like x 1
    • Agree Agree x 1
    • Useful Useful x 1
  6. Try this:
    @EventHandler
    public void onCharge(PlayerInteractEvent event){
    if(event.getPlayer().getItemInHand().getType() == Material.BOW){
    Player player = event.getPlayer();
    player.setSneaking(false);
    }
    }
     
    • Useful Useful x 2
  7. Thank you so much, I'll try to test it.
     
  8. You need to do more for example adding the player after the interact in a list then cancel any tentative of trying to sneak then remove him from the list after an arrow has been shoot
     
    • Useful Useful x 1
  9. You could also use a while loop for that.
     
    • Creative Creative x 1
  10. while-loops makes laggs
     
    • Useful Useful x 1
    • Optimistic Optimistic x 1
  11. That will not work. You will have to send a packet to everyone.

    Sent from my SM-G920P using Tapatalk
     
    • Useful Useful x 1