mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-18 12:48:53 +01:00
da7138233f
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: ed0ec489 SPIGOT-7965: Unknown TransformReason for Hoglins 9db03457 SPIGOT-7964: Fix typo in Deprecation annotation d14119af PR-1082: Add "since" to Deprecation annotations e8a318d4 PR-1067: Add method to get Advancement requirements CraftBukkit Changes: 40dd796db SPIGOT-7971: NotSerializableException on serialize CraftUseCooldownComponent fa85c5e0a SPIGOT-7968: ProjectileHitEvent not trigerred when arrow hits entity b75b792ec SPIGOT-7970: World#getMaxHeight() returning incorrect value 2b9a094bb SPIGOT-7965: Unknown TransformReason for Hoglins fd3f5a380 SPIGOT-7966: Some trees do not generate with #generateTree f2822317c PR-1515: Add a Class reader and Class node argument provider 07abf6852 PR-1514: Add a test case for ClassTraverser a7577cb24 Fix Inventory#addItem not respecting max stack size 066a74e74 PR-1490: Add method to get Advancement requirements 4a1df30e4 PR-1512: Test Art class based on specific values instead of the implementation, to better catch implementation changes 53254c56f PR-1503: Simplify CAS loop to getAndSet e9447dc5e Make BlockDataMeta#setBlockData hide unspecified states dd08a7120 SPIGOT-7960: Fix inconsistency between natural item drop coordinates e9e8ed753 SPIGOT-7960: Improve natural item drop methods Spigot Changes: 60c9969b Rebuild patches
105 lines
5.8 KiB
Diff
105 lines
5.8 KiB
Diff
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
|
|
index 9afc0eaaca5ab7b6445d90ce53e31a6ae76f8848..f0c2187a92de633a1d4cc7e71ff62cbe30ce8774 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -337,7 +337,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
}
|
|
|
|
private static boolean isInWorldBoundsHorizontal(BlockPos pos) {
|
|
- return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000;
|
|
+ return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000; // Diff on change warnUnsafeChunk()
|
|
}
|
|
|
|
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
|
|
index 33735897ec3800754ba690ca215d3d11d746f728..b0e57ca463a3c7cb1be8920a899c9afc7c871f4b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -302,9 +302,24 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
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
|
|
net.minecraft.world.level.chunk.LevelChunk chunk = (net.minecraft.world.level.chunk.LevelChunk) this.world.getChunk(x, z, ChunkStatus.FULL, true);
|
|
return new CraftChunk(chunk);
|
|
}
|
|
@@ -400,6 +415,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
if (!unloadChunk0(x, z, false)) {
|
|
return false;
|
|
}
|
|
+ warnUnsafeChunk("regenerating a faraway chunk", x, z); // Paper
|
|
|
|
final long chunkKey = ChunkCoordIntPair.pair(x, z);
|
|
world.getChunkProvider().unloadQueue.remove(chunkKey);
|
|
@@ -473,6 +489,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
@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
|
|
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.
|
|
@@ -505,6 +522,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@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");
|
|
|
|
@@ -605,6 +623,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public void setChunkForceLoaded(int x, int z, boolean forced) {
|
|
+ warnUnsafeChunk("forceloading a faraway chunk", x, z); // Paper
|
|
this.getHandle().setChunkForced(x, z, forced);
|
|
}
|
|
|
|
@@ -939,6 +958,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@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);
|
|
}
|
|
@@ -2344,6 +2364,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
// Paper start
|
|
@Override
|
|
public void getChunkAtAsync(int x, int z, boolean gen, boolean urgent, @NotNull Consumer<? super Chunk> cb) {
|
|
+ warnUnsafeChunk("getting a faraway chunk async", x, z); // Paper
|
|
ca.spottedleaf.moonrise.common.util.ChunkSystem.scheduleChunkLoad(
|
|
this.getHandle(), x, z, gen, ChunkStatus.FULL, true,
|
|
urgent ? ca.spottedleaf.concurrentutil.util.Priority.HIGHER : ca.spottedleaf.concurrentutil.util.Priority.NORMAL,
|
|
@@ -2356,6 +2377,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public void getChunksAtAsync(int minX, int minZ, int maxX, int maxZ, boolean urgent, Runnable cb) {
|
|
+ warnUnsafeChunk("getting a faraway chunk async", minX, minZ); // Paper
|
|
+ warnUnsafeChunk("getting a faraway chunk async", maxX, maxZ); // Paper
|
|
this.getHandle().loadChunks(
|
|
minX, minZ, maxX, maxZ,
|
|
urgent ? ca.spottedleaf.concurrentutil.util.Priority.HIGHER : ca.spottedleaf.concurrentutil.util.Priority.NORMAL,
|