How can Minecraft show PvP from a certain height?
I tried this like this:
double y = 201;
@EventHandler
public void onEntityDamage (EntityDamageByEntityEvent e) {
Entity en = e.getEntity ();
if (en.getLocation (). GetY ()> y) {
e.setCancelled (true);
}
}
but unfortunately it doesn't work that way…
I thank you in advance.
Looks right - the question arises why it doesn't work.
Have you debugged a bit? If only with System.out.println (). Just see what exactly is not working by having something displayed at each point. Then you know where the mistake is.
double y = 201;
System.out.println ("Loading");
@EventHandler
public void onEntityDamage (EntityDamageByEntityEvent e) {
System.out.println ("Event is being called");
Entity en = e.getEntity ();
if (en.getLocation (). GetY ()> y) {
System.out.println ("Condition works too");
e.setCancelled (true);
}
Thank you