From b51eec279f708d98af5b0ff39688dacafe6eb7b6 Mon Sep 17 00:00:00 2001 From: SirYwell Date: Thu, 7 Mar 2024 18:34:52 +0100 Subject: [PATCH] Prevent loading faraway chunks --- .../java/com/plotsquared/bukkit/player/BukkitPlayer.java | 6 +++++- .../main/java/com/plotsquared/core/command/MainCommand.java | 1 + Core/src/main/java/com/plotsquared/core/plot/Plot.java | 6 ++++++ Core/src/main/java/com/plotsquared/core/util/WorldUtil.java | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index e69d3f5bf..2926d0bd1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -32,6 +32,7 @@ import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MathMan; +import com.plotsquared.core.util.WorldUtil; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.world.item.ItemType; @@ -120,6 +121,9 @@ public class BukkitPlayer extends PlotPlayer { @Override 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 from = player.getLocation(); PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to); @@ -221,7 +225,7 @@ public class BukkitPlayer extends PlotPlayer { @Override 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; } final org.bukkit.Location bukkitLocation = diff --git a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java index 721bec05f..322e04dbe 100644 --- a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java @@ -268,6 +268,7 @@ public class MainCommand extends Command { tp = true; } else { player.sendMessage(TranslatableCaption.of("border.denied")); + return CompletableFuture.completedFuture(false); } // Trim command args = Arrays.copyOfRange(args, 1, args.length); diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 67db8a698..27ef4b318 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -2574,6 +2574,12 @@ public class Plot { */ public void teleportPlayer(final PlotPlayer player, TeleportCause cause, Consumer resultConsumer) { 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); if (event.getEventResult() == Result.DENY) { diff --git a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java index d00ce0e21..ec1756d8e 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java @@ -62,6 +62,10 @@ import java.util.zip.ZipOutputStream; public abstract class WorldUtil { + public static boolean isValidLocation(Location location) { + return Math.abs(location.getX()) < 30000000 && Math.abs(location.getZ()) < 30000000; + } + /** * Set the biome in a region *