How to get the Player who shot an arrow?

Discussion in 'Plugin Development' started by TheJesterRace, Jan 27, 2016.

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


    I'm trying to get the item the player holds when he fires an arrow (as they're able to fire arrows with multiple items in my plugin), therefore I need the player first. So this is basically what I'm doing:

    public void onProjectileLaunch(ProjectileLaunchEvent e)
        Plugin.getLogger().info("ProjectileLaunch event fired");
        ProjectileSource source = e.getEntity().getShooter();
        if (source instanceof Player)
                Plugin.getLogger().info("Shooter is a player");
    The Problem is that when I'm firing an arrow, my method does not print "Shooter is a player" to my console althoug it tells me that the EventHandler is called. :(
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline


    Omg i know - it's because I'm not telling the player to fire an arrow but the world to spawn one on the players location.. argh i totally forgot about that - could have tried that on my own earlier :rolleyes:
    Thanks for your fast answer!
    timtower likes this.
  4. Offline


  5. Offline


    No, not really :/
    I tried a little around and came out with this:

    // Spawn the arrow
    Arrow arrow = player.getWorld().spawnArrow(location, direction, 2, 0);
    // And set the shooter manually
    The Problem is that I need the shooter in my ProjectileLaunchEvent which fires immediately after the first line (before the shooter is set). Is there any way to set the shooter before I spawn this arrow?
    Last edited: Jan 30, 2016
Thread Status:
Not open for further replies.

Share This Page