Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent loading faraway chunks #4370

Merged
merged 2 commits into from Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -120,6 +121,9 @@ public long getLastPlayed() {

@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);
Expand Down Expand Up @@ -221,7 +225,7 @@ public int hasPermissionRange(

@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 =
Expand Down
Expand Up @@ -268,6 +268,7 @@ public CompletableFuture<Boolean> execute(
tp = true;
} else {
player.sendMessage(TranslatableCaption.of("border.denied"));
return CompletableFuture.completedFuture(false);
}
// Trim command
args = Arrays.copyOfRange(args, 1, args.length);
Expand Down
6 changes: 6 additions & 0 deletions Core/src/main/java/com/plotsquared/core/plot/Plot.java
Expand Up @@ -2574,6 +2574,12 @@ public void teleportPlayer(final PlotPlayer<?> player, Consumer<Boolean> result)
*/
public void teleportPlayer(final PlotPlayer<?> player, TeleportCause cause, Consumer<Boolean> 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) {
Expand Down
9 changes: 9 additions & 0 deletions Core/src/main/java/com/plotsquared/core/util/WorldUtil.java
Expand Up @@ -62,6 +62,15 @@

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
*
Expand Down