Projectile Launch Event

Hey its me again,
i wrote a bit of code and i am not sure if i derped or there isnt a important method implemented.

Everything is being said in the code.

@Subscribe
public void onProjectileLaunch(ProjectileLaunchEvent e){
        Projectile p = e.getLaunchedProjectile();
        Location loc = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ());
        //here goes something like e.getShooter().setLocation(loc); However the setLocation is missing.
 }

I hope i am not very dumb and wrote shit code.

So… is it not running, or…?

If it’s not running at all, try adding debug text. Or check that you’re importing the correct @Subscribe.

No i mean the e.getShooter() after it i cant find anything about location or such.
Else it is running nice and erverything is also correct imported.

e,getShooter().getLocation().setLocation(loc); ?

there isnt a method like this
but it is what i mean

A ProjectileSource does not necessarily have to have a location.

You need to check whether the source is an instance of a certain interface, for example BlockProjectileSource. Using the javadocs, it can be seen what interfaces are sources. (see here).

It should be noted that the event is not being fired anywhere at the moment.

Yeah i know but also if i do something like that:

@Subscribe
public void onProjectileLaunch(ProjectileLaunchEvent e){
if(e.getLaunchedProjectile().getShooter() instanceof Player){
Projectile p = e.getLaunchedProjectile();
Location loc = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ());
p.getShooter().(here is going the setLocation method which isnt available);

    }
}

It still doesnt work.
Dont be afraid there will be more if clauses soon but first i need to make it to run.

The event isn’t implemented.

That’s because p.getShooter() will return ProjectileSource, you will need to cast it.

Player player = (Player) p.getShooter();

Also,

Location loc = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ());

is pointless because you can just do
Location loc = p.getLocation();

You too are talking about two different things is it not in the API (implemented) or not anywhere (fired)?

It’s not implemented and therefore is not fired from anywhere (yet).

So i need to wait until the develpoers implement it to the API ?
Thats sad.

@DarkIce Does this even make sense though, if it was implemented? If you get the location of a projectile on launch, it should be about the same location as the shooter. So, this will just make the shooter jump a half-block or so and that’s it?

I guess the question is, what is this for?

2 Likes

Just let me decide in which way it is useful or not i thought i havent asked for your opinion. Havent i?

I am more curious than anything. I am not saying that it is wrong in any way. If you don’t want to enlighten me, no problem man. It will be a surprise, I guess.

1 Like

What dou you think why i didnt posted the whole class. :wink:

@DarkIce don’t take offense to people asking what you’re attempting to do. :stuck_out_tongue: It’s a good way to determine whether or not the code is being done correctly.

Whenever I ask for help, I tend to release private information for the sake of getting my work audited.

1 Like