How to fire arrow with Right Click Event

Discussion in 'Plugin Development' started by thatdubstepgamer, Sep 12, 2013.

Thread Status:
Not open for further replies.
  1. Hello and today I was wondering how can I fire an arrow with a Right Click Event Ive tried for the past 2 hours but I cant get It if you could share some code that would be great :D also the material needed in hand is a wooden_hoe
     
  2. Offline

    Quantix

    This method seems to work well:
    Code:java
    1. @EventHandler (priority = EventPriority.NORMAL)
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. Action action = event.getAction();
    5.  
    6. if ((action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) && event.hasItem() && player.getItemInHand().getTypeId() == Material.WOOD_HOE.getId()) {
    7. player.launchProjectile(Arrow.class); //This makes the player shoot the arrow
    8. //If you want to change the arrow's velocity etc. type
    9. //Arrow arrow = player.launchProjectile(Arrow.class);
    10. //do stuff with arrow
    11. }
    12. }
     
Thread Status:
Not open for further replies.

Share This Page