extras/src/main/java/pw/kaboom/extras/modules/entity/EntityTeleport.java

44 lines
1.1 KiB
Java
Raw Normal View History

2019-12-17 12:37:59 +00:00
package pw.kaboom.extras.modules.entity;
2019-12-15 00:09:29 +00:00
2020-04-17 03:17:59 +00:00
import org.bukkit.Location;
2019-12-15 00:09:29 +00:00
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityTeleportEvent;
2019-12-21 14:12:26 +00:00
public final class EntityTeleport implements Listener {
2022-05-20 02:35:48 +00:00
public static Location limitLocation(final Location location) {
double x = location.getX();
double y = location.getY();
double z = location.getZ();
2020-04-17 03:17:59 +00:00
2022-05-20 02:35:48 +00:00
final int maxValue = 30000000;
final int minValue = -30000000;
2020-04-17 03:17:59 +00:00
2022-05-20 02:35:48 +00:00
if (x > maxValue) {
location.setX(maxValue);
}
if (x < minValue) {
location.setX(minValue);
}
if (y > maxValue) {
location.setY(maxValue);
}
if (y < minValue) {
location.setY(minValue);
}
if (z > maxValue) {
location.setZ(maxValue);
}
if (z < minValue) {
location.setZ(minValue);
}
2020-04-17 03:17:59 +00:00
2022-05-20 02:35:48 +00:00
return location;
}
2020-04-17 03:17:59 +00:00
2022-05-20 02:35:48 +00:00
@EventHandler
void onEntityTeleport(final EntityTeleportEvent event) {
event.setTo(limitLocation(event.getTo()));
}
2019-12-15 00:09:29 +00:00
}