Prevent loading faraway chunks (#4370)

* Prevent loading faraway chunks

* docs
This commit is contained in:
Hannes Greule 2024-03-07 21:34:33 +01:00 committed by GitHub
parent 25e98618b9
commit 2321831044
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.WorldUtil;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
@ -120,6 +121,9 @@ public class BukkitPlayer extends PlotPlayer<Player> {
@Override @Override
public boolean canTeleport(final @NonNull Location location) { public boolean canTeleport(final @NonNull Location location) {
if (!WorldUtil.isValidLocation(location)) {
return false;
}
final org.bukkit.Location to = BukkitUtil.adapt(location); final org.bukkit.Location to = BukkitUtil.adapt(location);
final org.bukkit.Location from = player.getLocation(); final org.bukkit.Location from = player.getLocation();
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to); PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
@ -221,7 +225,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
@Override @Override
public void teleport(final @NonNull Location location, final @NonNull TeleportCause cause) { public void teleport(final @NonNull Location location, final @NonNull TeleportCause cause) {
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) { if (!WorldUtil.isValidLocation(location)) {
return; return;
} }
final org.bukkit.Location bukkitLocation = final org.bukkit.Location bukkitLocation =

View File

@ -268,6 +268,7 @@ public class MainCommand extends Command {
tp = true; tp = true;
} else { } else {
player.sendMessage(TranslatableCaption.of("border.denied")); player.sendMessage(TranslatableCaption.of("border.denied"));
return CompletableFuture.completedFuture(false);
} }
// Trim command // Trim command
args = Arrays.copyOfRange(args, 1, args.length); args = Arrays.copyOfRange(args, 1, args.length);

View File

@ -2574,6 +2574,12 @@ public class Plot {
*/ */
public void teleportPlayer(final PlotPlayer<?> player, TeleportCause cause, Consumer<Boolean> resultConsumer) { public void teleportPlayer(final PlotPlayer<?> player, TeleportCause cause, Consumer<Boolean> resultConsumer) {
Plot plot = this.getBasePlot(false); Plot plot = this.getBasePlot(false);
if (!WorldUtil.isValidLocation(plot.getBottomAbs())) {
// prevent from teleporting into unsafe regions
player.sendMessage(TranslatableCaption.of("border.denied"));
resultConsumer.accept(false);
return;
}
PlayerTeleportToPlotEvent event = this.eventDispatcher.callTeleport(player, player.getLocation(), plot, cause); PlayerTeleportToPlotEvent event = this.eventDispatcher.callTeleport(player, player.getLocation(), plot, cause);
if (event.getEventResult() == Result.DENY) { if (event.getEventResult() == Result.DENY) {

View File

@ -62,6 +62,15 @@ import java.util.zip.ZipOutputStream;
public abstract class WorldUtil { public abstract class WorldUtil {
/**
* {@return whether the given location is valid in the world}
* @param location the location to check
* @since TODO
*/
public static boolean isValidLocation(Location location) {
return Math.abs(location.getX()) < 30000000 && Math.abs(location.getZ()) < 30000000;
}
/** /**
* Set the biome in a region * Set the biome in a region
* *