2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-10-22 21:25:16 +02:00
From: Gabriele C <sgdc3.mail@gmail.com>
Date: Mon, 22 Oct 2018 17:34:10 +0200
Subject: [PATCH] Add option to prevent players from moving into unloaded
chunks #1551
2018-10-24 03:13:58 +02:00
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2020-06-26 14:04:38 +02:00
index 487b0d5cd608e84a793eba5fdbd50a9f3d95c79b..b49a1a6f5017c9e183a7d08b16e89899c25a9717 100644
2018-10-24 03:13:58 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2020-06-26 14:04:38 +02:00
@@ -405,4 +405,9 @@ public class PaperWorldConfig {
2019-12-12 17:20:43 +01:00
waterOverLavaFlowSpeed = getInt("water-over-lava-flow-speed", 5);
log("Water over lava flow speed: " + waterOverLavaFlowSpeed);
2018-10-22 21:25:16 +02:00
}
+
2018-10-24 03:13:58 +02:00
+ public boolean preventMovingIntoUnloadedChunks = false;
+ private void preventMovingIntoUnloadedChunks() {
2018-10-24 14:38:34 +02:00
+ preventMovingIntoUnloadedChunks = getBoolean("prevent-moving-into-unloaded-chunks", false);
2018-10-22 21:25:16 +02:00
+ }
}
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2020-06-28 03:54:05 +02:00
index f0d8388d6ac0ed5546d34f628a6b2ba6c56b1c61..e815200d1b81bd0d8a62e28a43cc01f4da956fa0 100644
2018-10-22 21:25:16 +02:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2020-06-25 16:09:55 +02:00
@@ -350,6 +350,13 @@ public class PlayerConnection implements PacketListenerPlayIn {
2018-10-22 21:25:16 +02:00
}
speed *= 2f; // TODO: Get the speed of the vehicle instead of the player
+ // Paper start - Prevent moving into unloaded chunks
2019-07-28 01:38:49 +02:00
+ if (player.world.paperConfig.preventMovingIntoUnloadedChunks && worldserver.getChunkIfLoadedImmediately((int) Math.floor(packetplayinvehiclemove.getX()) >> 4, (int) Math.floor(packetplayinvehiclemove.getZ()) >> 4) == null) {
2018-10-22 21:25:16 +02:00
+ this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
+ return;
+ }
+ // Paper end
+
2019-05-05 13:12:32 +02:00
if (d10 - d9 > Math.max(100.0D, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && !this.isExemptPlayer()) {
2018-10-22 21:25:16 +02:00
// CraftBukkit end
2018-12-08 11:09:55 +01:00
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getDisplayName().getString(), this.player.getDisplayName().getString(), d6, d7, d8);
2020-06-25 16:09:55 +02:00
@@ -919,9 +926,9 @@ public class PlayerConnection implements PacketListenerPlayIn {
2019-12-12 17:20:43 +01:00
double d1 = this.player.locY();
double d2 = this.player.locZ();
double d3 = this.player.locY();
- double d4 = packetplayinflying.a(this.player.locX());
+ double d4 = packetplayinflying.a(this.player.locX());double toX = d4; // Paper - OBFHELPER
double d5 = packetplayinflying.b(this.player.locY());
- double d6 = packetplayinflying.c(this.player.locZ());
+ double d6 = packetplayinflying.c(this.player.locZ());double toZ = d6; // Paper - OBFHELPER
2018-10-24 03:13:58 +02:00
float f = packetplayinflying.a(this.player.yaw);
float f1 = packetplayinflying.b(this.player.pitch);
double d7 = d4 - this.l;
2020-06-25 16:09:55 +02:00
@@ -960,6 +967,12 @@ public class PlayerConnection implements PacketListenerPlayIn {
2019-06-25 03:47:58 +02:00
} else {
2018-10-22 21:25:16 +02:00
speed = player.abilities.walkSpeed * 10f;
}
+ // Paper start - Prevent moving into unloaded chunks
2019-12-12 17:20:43 +01:00
+ if (player.world.paperConfig.preventMovingIntoUnloadedChunks && (this.player.locX() != toX || this.player.locZ() != toZ) && !worldserver.isChunkLoaded((int) Math.floor(toX) >> 4, (int) Math.floor(toZ) >> 4)) {
+ this.internalTeleport(this.player.locX(), this.player.locY(), this.player.locZ(), this.player.yaw, this.player.pitch, Collections.emptySet());
2018-10-22 21:25:16 +02:00
+ return;
+ }
+ // Paper end
2019-06-25 03:47:58 +02:00
if (!this.player.H() && (!this.player.getWorldServer().getGameRules().getBoolean(GameRules.DISABLE_ELYTRA_MOVEMENT_CHECK) || !this.player.isGliding())) {
float f2 = this.player.isGliding() ? 300.0F : 100.0F;