Shooting Arrows Issue

Discussion in 'Plugin Development' started by Philitup321, Jul 28, 2013.

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

    Philitup321

    Hello!!! I am trying to make a plugin where when you right-click the air, or a block with an item, in this case a stick, it will shoot arrows at what you are looking at. I have tried coding it multiple times, and it still won't work. If anyone could help me, it would be much appreciated.

    Here is a link to a Pastebin with all the coding that involves the right-click arrow shooting.
     
  2. Offline

    JPG2000

    Philitup321 Do a interact event, and check for event.right click. Then get the players hand, and check for the type stick. Then use the arrow.class. When I get on my computer I will give you a example.

    Philitup321 oops I'm sorry I'd dint see your paste in. You don't need the method gun, just have it in the interact event

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  3. Offline

    LanteanKnight

    Did you register your events?
     
  4. Offline

    Philitup321

    Ok, thank you. Even though I understand this, an example would be much appreciated.
     
  5. Offline

    JPG2000

    Philitup321 I'll be on my computer tomorrow. Just after the stick use the stuff in the gun method, like the arrow.class. Simple
     
  6. Offline

    Philitup321

    Ok, I made it this :
    @EventHandler
    public void onLeftClick(PlayerInteractEvent event){
    Player player = event.getPlayer();
    if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || player.getItemInHand().getType() == Material.STICK){
    player.launchProjectile(Arrow.class);

    But it still won't work. What am I doing wrong?
     
  7. Offline

    JPG2000

    Hm. Philitup321 I don't know. Does the interact event work at all?
     
  8. Offline

    Philitup321

    I don't think so. When I right click or change the code and Left click, it doesn't do anything.
     
  9. Offline

    xTrollxDudex

    Philitup321
    Any errors? Did you register the listener and does the listener class implement Listener?
     
  10. Offline

    Philitup321

    No errors. And yes I did:
    public class Fun extends JavaPlugin implements Listener{
     
  11. Offline

    xTrollxDudex

    Philitup321
    Only one class should extend JavaPlugin, can you post the full code? And by errors, I hope you mean there are no console errors.
     
  12. Offline

    Philitup321

    No console errors. Here is the full code.
     
  13. Offline

    cummo15

    Philitup321 You need to register the listener. Add this to your onEnable().
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
     
  14. Offline

    Philitup321

    Ok!! Thank you!! This worked. Do you know if there is a way to make the item shoot at a certain range? For example the stick shoots 10 blocks while the Iron Axe Shoot 15?
     
  15. Offline

    cummo15

    Philitup321 Sorry, Im not sure how you could change the distance of the arrow. I think you would need to spawn the arrow like this, but don't take my word for it. :p
    Code:java
    1. player.getLocation().getWorld().spawnArrow(Location, Velocity, Speed, Spread);

    You can find the javadocs for it here if you scroll down a bit.

    Also as for checking what it was that they right clicked with. Just use an if statement like this.
    Code:java
    1. } else if (player.getItemInHand().getType().equals(Material.IRON_AXE)) {
    2. //Do stuff.
    3. }
     
Thread Status:
Not open for further replies.

Share This Page