2022-07-30 01:16:26 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
|
|
|
Date: Fri, 29 Jul 2022 12:35:19 -0400
|
|
|
|
Subject: [PATCH] Warn on plugins accessing faraway chunks
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
2024-08-09 22:05:50 +02:00
|
|
|
index b4111bcc6a676dc42b233761aa667708669c2ab8..cc92d2e8b77c75da1d8b850c3bc251e8ac221c24 100644
|
2022-07-30 01:16:26 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
2024-06-14 03:30:23 +02:00
|
|
|
@@ -339,7 +339,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
2022-07-30 01:16:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isInWorldBoundsHorizontal(BlockPos pos) {
|
|
|
|
- return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000;
|
2024-01-18 15:56:25 +01:00
|
|
|
+ return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000; // Diff on change warnUnsafeChunk()
|
2022-07-30 01:16:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isOutsideSpawnableHeight(int y) {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2024-08-31 19:59:17 +02:00
|
|
|
index a1912eb5fd26898d7e9848ffb2052fce2fa10868..cb28a7504e809a8b1e8ab6e34e14e414c542055f 100644
|
2022-07-30 01:16:26 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2024-08-31 19:59:17 +02:00
|
|
|
@@ -305,9 +305,24 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2022-07-30 01:16:26 +02:00
|
|
|
public boolean setSpawnLocation(int x, int y, int z) {
|
|
|
|
return this.setSpawnLocation(x, y, z, 0.0F);
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
|
|
+ private static void warnUnsafeChunk(String reason, int x, int z) {
|
|
|
|
+ // if any chunk coord is outside of 30 million blocks
|
|
|
|
+ if (x > 1875000 || z > 1875000 || x < -1875000 || z < -1875000) {
|
|
|
|
+ Plugin plugin = io.papermc.paper.util.StackWalkerUtil.getFirstPluginCaller();
|
|
|
|
+ if (plugin != null) {
|
|
|
|
+ plugin.getLogger().warning("Plugin is %s at (%s, %s), this might cause issues.".formatted(reason, x, z));
|
|
|
|
+ }
|
|
|
|
+ if (net.minecraft.server.MinecraftServer.getServer().isDebugging()) {
|
|
|
|
+ io.papermc.paper.util.TraceUtil.dumpTraceForThread("Dangerous chunk retrieval");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Chunk getChunkAt(int x, int z) {
|
|
|
|
+ warnUnsafeChunk("getting a faraway chunk", x, z); // Paper
|
|
|
|
// Paper start - add ticket to hold chunk for a little while longer if plugin accesses it
|
2023-04-07 20:39:13 +02:00
|
|
|
net.minecraft.world.level.chunk.LevelChunk chunk = this.world.getChunkSource().getChunkAtIfLoadedImmediately(x, z);
|
2022-07-30 01:16:26 +02:00
|
|
|
if (chunk == null) {
|
2024-08-31 19:59:17 +02:00
|
|
|
@@ -413,6 +428,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2024-06-14 14:11:52 +02:00
|
|
|
if (!unloadChunk0(x, z, false)) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-30 01:16:26 +02:00
|
|
|
+ warnUnsafeChunk("regenerating a faraway chunk", x, z); // Paper
|
2024-06-14 14:11:52 +02:00
|
|
|
|
|
|
|
final long chunkKey = ChunkCoordIntPair.pair(x, z);
|
|
|
|
world.getChunkProvider().unloadQueue.remove(chunkKey);
|
2024-08-31 19:59:17 +02:00
|
|
|
@@ -486,6 +502,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2022-07-30 01:16:26 +02:00
|
|
|
@Override
|
|
|
|
public boolean loadChunk(int x, int z, boolean generate) {
|
|
|
|
org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot
|
|
|
|
+ warnUnsafeChunk("loading a faraway chunk", x, z); // Paper
|
2024-01-23 15:43:48 +01:00
|
|
|
ChunkAccess chunk = this.world.getChunkSource().getChunk(x, z, generate || isChunkGenerated(x, z) ? ChunkStatus.FULL : ChunkStatus.EMPTY, true); // Paper
|
|
|
|
|
|
|
|
// If generate = false, but the chunk already exists, we will get this back.
|
2024-08-31 19:59:17 +02:00
|
|
|
@@ -518,6 +535,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2022-07-30 01:16:26 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addPluginChunkTicket(int x, int z, Plugin plugin) {
|
|
|
|
+ warnUnsafeChunk("adding a faraway chunk ticket", x, z); // Paper
|
|
|
|
Preconditions.checkArgument(plugin != null, "null plugin");
|
|
|
|
Preconditions.checkArgument(plugin.isEnabled(), "plugin is not enabled");
|
|
|
|
|
2024-08-31 19:59:17 +02:00
|
|
|
@@ -618,6 +636,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2022-07-30 01:16:26 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setChunkForceLoaded(int x, int z, boolean forced) {
|
|
|
|
+ warnUnsafeChunk("forceloading a faraway chunk", x, z); // Paper
|
|
|
|
this.getHandle().setChunkForced(x, z, forced);
|
|
|
|
}
|
|
|
|
|
2024-08-31 19:59:17 +02:00
|
|
|
@@ -946,6 +965,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2022-07-30 01:16:26 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getHighestBlockYAt(int x, int z, org.bukkit.HeightMap heightMap) {
|
|
|
|
+ warnUnsafeChunk("getting a faraway chunk", x >> 4, z >> 4); // Paper
|
|
|
|
// Transient load for this tick
|
|
|
|
return this.world.getChunk(x >> 4, z >> 4).getHeight(CraftHeightMap.toNMS(heightMap), x, z);
|
|
|
|
}
|
2024-08-31 19:59:17 +02:00
|
|
|
@@ -2343,6 +2363,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2022-09-01 18:51:59 +02:00
|
|
|
// Spigot end
|
2022-07-30 01:16:26 +02:00
|
|
|
// Paper start
|
|
|
|
public java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent) {
|
|
|
|
+ warnUnsafeChunk("getting a faraway chunk async", x, z); // Paper
|
|
|
|
if (Bukkit.isPrimaryThread()) {
|
|
|
|
net.minecraft.world.level.chunk.LevelChunk immediate = this.world.getChunkSource().getChunkAtIfLoadedImmediately(x, z);
|
|
|
|
if (immediate != null) {
|