I'm trying to program a Minecraft plugin.
You shouldn't get snowball damage from self-thrown snowballs.
How do I write this in the EntityDamageByEntityEvent?
Respectively. How do I query this?
@EventHandler
public void onHit (EntityDamageByEntityEvent e) {
if (! (event.getDamager () instanceof Snowball))
return;
if Projectile) e.getDamager ()). GetShooter ()! = e.getEntity ())
return;
e.setCancelled (true);
}
It wasn't completely right, but it helped me get the right thing.
Correct:
@EventHandler
public void onHit (EntityDamageByEntityEvent event) {
if (! (event.getDamager () instanceof Snowball))
return;
if Projectile) event.getDamager ()). GetShooter () == event.getEntity ())
event.setCancelled (true);
Mine should work just as well, or why do you think mine doesn't work?
You wrote "if Projectile) e.getDamager ()). GetShooter ()! = E.getEntity ())! =. So you exclude that it is the same person.
According to your text, opponents don't get damage!
But it says below
return;
This means that exactly in this case he should no longer continue in the code, so that the e.setCancelled (true); is no longer executed.
Finally thanks first. Your code didn't work for me. This is due to the word "return". If it's up to you, use a different Minecraft.
Teach me better!
It is very strange. There's no reason why return shouldn't work. But I don't care now, the main thing is that it works.