aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0383-Add-option-to-prevent-players-from-moving-into-unloa.patch
blob: 9ac4c1b740eeb4cb29b8b6fcd1c69c3d7007803f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 92cb3409be8524f1e5684352cd18fc5737491707 Mon Sep 17 00:00:00 2001
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


diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 2a912286b2..61ad2cef7b 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -583,4 +583,9 @@ public class PaperWorldConfig {
         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);
     }
+
+    public boolean preventMovingIntoUnloadedChunks = false;
+    private void preventMovingIntoUnloadedChunks() {
+        preventMovingIntoUnloadedChunks = getBoolean("prevent-moving-into-unloaded-chunks", false);
+    }
 }
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 9a96078004..4705dd2c68 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -341,6 +341,13 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
                 }
                 speed *= 2f; // TODO: Get the speed of the vehicle instead of the player
 
+                // Paper start - Prevent moving into unloaded chunks
+                if (player.world.paperConfig.preventMovingIntoUnloadedChunks && !worldserver.isChunkLoaded((int) Math.floor(packetplayinvehiclemove.getX()) >> 4, (int) Math.floor(packetplayinvehiclemove.getZ()) >> 4, false)) {
+                    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
                     PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getDisplayName().getString(), this.player.getDisplayName().getString(), d6, d7, d8);
@@ -849,9 +856,9 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
                         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;
@@ -891,6 +898,13 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
                                 speed = player.abilities.walkSpeed * 10f;
                             }
 
+                            // Paper start - Prevent moving into unloaded chunks
+                            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)) {
+                                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;
 
-- 
2.21.0