PaperMC/patches/server/0284-Add-option-to-prevent-players-from-moving-into-unloa.patch

65 lines
4.4 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 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 316978a376f57b420c946e87c16f2bc3b09425e1..2a7d31f533240e0b683c00d65f5632d7a8ff236d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -395,4 +395,9 @@ public class PaperWorldConfig {
2021-06-11 14:02:28 +02:00
waterOverLavaFlowSpeed = getInt("water-over-lava-flow-speed", 5);
log("Water over lava flow speed: " + waterOverLavaFlowSpeed);
}
+
+ public boolean preventMovingIntoUnloadedChunks = false;
+ private void preventMovingIntoUnloadedChunks() {
+ preventMovingIntoUnloadedChunks = getBoolean("prevent-moving-into-unloaded-chunks", false);
+ }
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2021-07-07 08:52:40 +02:00
index 912171f8b3280a6c45311104216e04d661daff8a..38a48add445e8dd6888bc5bb22e7bf5482682536 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2021-07-07 08:52:40 +02:00
@@ -531,6 +531,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
}
speed *= 2f; // TODO: Get the speed of the vehicle instead of the player
+ // Paper start - Prevent moving into unloaded chunks
+ if (player.level.paperConfig.preventMovingIntoUnloadedChunks && worldserver.getChunkIfLoadedImmediately((int) Math.floor(packet.getX()) >> 4, (int) Math.floor(packet.getZ()) >> 4) == null) {
+ this.connection.send(new ClientboundMoveVehiclePacket(entity));
+ return;
+ }
+ // Paper end
+
if (d10 - d9 > Math.max(100.0D, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && !this.isSingleplayerOwner()) {
// CraftBukkit end
ServerGamePacketListenerImpl.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getName().getString(), this.player.getName().getString(), d6, d7, d8);
2021-07-07 08:52:40 +02:00
@@ -1155,9 +1162,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-13 08:48:25 +02:00
float prevYaw = this.player.getYRot();
float prevPitch = this.player.getXRot();
// CraftBukkit end
- double d3 = this.player.getX();
+ double d3 = this.player.getX(); final double toX = d3; // Paper - OBFHELPER
double d4 = this.player.getY();
- double d5 = this.player.getZ();
+ double d5 = this.player.getZ(); final double toZ = d5; // Paper - OBFHELPER
double d6 = this.player.getY();
double d7 = d0 - this.firstGoodX;
double d8 = d1 - this.firstGoodY;
2021-07-07 08:52:40 +02:00
@@ -1195,6 +1202,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
} else {
2021-06-13 08:48:25 +02:00
speed = this.player.getAbilities().walkingSpeed * 10f;
2021-06-11 14:02:28 +02:00
}
+ // Paper start - Prevent moving into unloaded chunks
+ if (player.level.paperConfig.preventMovingIntoUnloadedChunks && (this.player.getX() != toX || this.player.getZ() != toZ) && !worldserver.hasChunk((int) Math.floor(toX) >> 4, (int) Math.floor(toZ) >> 4)) {
2021-06-13 08:48:25 +02:00
+ this.internalTeleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot(), Collections.emptySet(), true);
2021-06-11 14:02:28 +02:00
+ return;
+ }
+ // Paper end
if (!this.player.isChangingDimension() && (!this.player.getLevel().getGameRules().getBoolean(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK) || !this.player.isFallFlying())) {
float f2 = this.player.isFallFlying() ? 300.0F : 100.0F;