2019-01-17 03:02:56 +01:00
From f6e01d6360441f498d56175e148300b20c5f786f 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
2019-01-17 03:02:56 +01:00
index 575281991c..f47a648af3 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
2019-01-13 00:06:26 +01:00
@@ -574,4 +574,9 @@ public class PaperWorldConfig {
2018-10-24 03:13:58 +02:00
replacementBlocks = getList("anti-xray.replacement-blocks", Arrays.asList("stone", "planks"));
log("Anti-Xray: " + (antiXray ? "enabled" : "disabled") + " / Engine Mode: " + engineMode.getDescription() + " / Chunk Edge Mode: " + chunkEdgeMode.getDescription() + " / Up to " + ((maxChunkSectionIndex + 1) * 16) + " blocks / Update Radius: " + updateRadius);
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
2019-01-17 03:02:56 +01:00
index 0bcb9c1ab1..c1f47701cc 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
2019-01-01 04:15:55 +01:00
@@ -341,6 +341,13 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
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
2018-10-24 03:13:58 +02:00
+ if (player.world.paperConfig.preventMovingIntoUnloadedChunks && !worldserver.isChunkLoaded((int) Math.floor(packetplayinvehiclemove.getX()) >> 4, (int) Math.floor(packetplayinvehiclemove.getZ()) >> 4, false)) {
2018-10-22 21:25:16 +02:00
+ this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
+ return;
+ }
+ // Paper end
+
if (d10 - d9 > Math.max(100.0D, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && (!this.minecraftServer.H() || !this.minecraftServer.G().equals(entity.getDisplayName().getString()))) {
// 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);
2019-01-01 04:15:55 +01:00
@@ -848,9 +855,9 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
2018-10-24 03:13:58 +02: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
float f = packetplayinflying.a(this.player.yaw);
float f1 = packetplayinflying.b(this.player.pitch);
double d7 = d4 - this.l;
2019-01-01 04:15:55 +01:00
@@ -890,6 +897,13 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
2018-10-22 21:25:16 +02:00
speed = player.abilities.walkSpeed * 10f;
}
+ // Paper start - Prevent moving into unloaded chunks
2018-10-24 03:13:58 +02: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, false)) {
2018-10-22 21:25:16 +02:00
+ this.internalTeleport(this.player.locX, this.player.locY, this.player.locZ, this.player.yaw, this.player.pitch, Collections.emptySet());
+ return;
+ }
+ // Paper end
+
if (!this.player.H() && (!this.player.getWorldServer().getGameRules().getBoolean("disableElytraMovementCheck") || !this.player.dc())) {
float f2 = this.player.dc() ? 300.0F : 100.0F;
--
2019-01-17 03:02:56 +01:00
2.20.1
2018-10-22 21:25:16 +02:00