Getting Thrower Of Potion

Discussion in 'Spigot Plugin Development' started by Technerder, May 3, 2017.

  1. Using projrctilelaunchevent how would I get the thrower of the projectile? I have tried event.getThrower(); and it hasn't been working.
  2. I'm not near my computer right now but since it's an event it should be e.getPlayer() or e.getThrower()
  3. Choco


    That's because ProjectileLaunchEvent#getThrower() doesn't exist... I suggest taking a look at the Javadocs for what you're working with. #getEntity() will return a Projectile, in which you may then invoke Projectile#getShooter() to return a ProjectileSource. Keep in mind that ProjectileSource can be a variety of different objects, not just Player. Assure that you're checking instanceof before casting
    #3 Choco, May 3, 2017
    Last edited: May 3, 2017
    • Agree Agree x 1
  4. Code (Text):
        public void onPotionThrow(ProjectileLaunchEvent event) {
            if (event.getEntity().getType() == EntityType.THROWN_EXP_BOTTLE) {
                if (thrower.getEntity instanceof Player) {
                Entity potion = event.getEntity();
                Player thrower = event.getShooter();
                potion.setVelocity(new Vector(thrower.getLocation().getDirection().multiply(10).getX(), 5.0D,
    currently not working, am i missing something?
  5. Compile error detected, please don't write code in reverse... Fix that first.
    And as the person above you said, shooter is fetched from projectile, not event.
    • Agree Agree x 1