mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-17 10:04:53 +02:00
micro-efficiency, improvements
Don't call .getBlock which is both slow and doesn't work in all cases. Also don't compare worlds by name, compare by instance.
This commit is contained in:
parent
1c6a1cc719
commit
33ef7d2a55
@ -295,18 +295,19 @@ public class EventListen implements Listener {
|
|||||||
}, 60);
|
}, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Location roundLocation(Location input) {
|
||||||
|
return new Location(input.getWorld(), Math.floor(input.getX()),
|
||||||
|
Math.floor(input.getY()), Math.floor(input.getZ()));
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerWalks(final PlayerMoveEvent event) {
|
public void onPlayerWalks(final PlayerMoveEvent event) {
|
||||||
if (event.getFrom().getY() > 255 || event.getFrom().getY() < 0
|
Location from = roundLocation(event.getFrom());
|
||||||
|| event.getTo().getY() > 255 || event.getTo().getY() < 0) {
|
Location to = roundLocation(event.getTo());
|
||||||
return; // Don't fire if players go outside the world, as that would be more difficult to handle.
|
|
||||||
}
|
|
||||||
Location from = event.getFrom().getBlock().getLocation();
|
|
||||||
Location to = event.getTo().getBlock().getLocation();
|
|
||||||
if (from.equals(to)) {
|
if (from.equals(to)) {
|
||||||
return; // Don't fire on every movement, just full block+.
|
return; // Don't fire on every movement, just full block+.
|
||||||
}
|
}
|
||||||
if (!from.getWorld().getName().equalsIgnoreCase(to.getWorld().getName())) {
|
if (from.getWorld() != to.getWorld()) {
|
||||||
return; // Ignore cross-world movement for now.
|
return; // Ignore cross-world movement for now.
|
||||||
}
|
}
|
||||||
int maxRad = 50 * 50; // TODO: Adjust me to perfection
|
int maxRad = 50 * 50; // TODO: Adjust me to perfection
|
||||||
|
Loading…
Reference in New Issue
Block a user