spigot/CraftBukkit-Patches/0007-Async-Operation-Catching.patch

253 lines
13 KiB
Diff
Raw Normal View History

2020-01-13 10:27:31 +11:00
From b562e1cb36b153e71acc71e9abc06621ae8abf27 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Tue, 25 Mar 2014 16:10:01 +1100
Subject: [PATCH] Async Operation Catching
Catch and throw an exception when a potentially unsafe operation occurs on a thread other than the main server thread.
2013-08-03 19:09:09 +10:00
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
2019-12-22 10:00:03 +11:00
index 3446ee292..cd72a9c84 100644
2013-08-03 19:09:09 +10:00
--- a/src/main/java/net/minecraft/server/Block.java
+++ b/src/main/java/net/minecraft/server/Block.java
2019-12-11 09:00:00 +11:00
@@ -387,10 +387,13 @@ public class Block implements IMaterial {
2013-08-03 19:09:09 +10:00
}
2018-07-15 10:00:00 +10:00
@Deprecated
2019-04-23 12:00:00 +10:00
- public void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {}
+ public void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
+ org.spigotmc.AsyncCatcher.catchOp("block onPlace"); // Spigot
2013-08-03 19:09:09 +10:00
+ }
2018-07-15 10:00:00 +10:00
@Deprecated
2019-04-23 12:00:00 +10:00
public void remove(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
+ org.spigotmc.AsyncCatcher.catchOp("block remove"); // Spigot
2019-04-23 12:00:00 +10:00
if (this.isTileEntity() && iblockdata.getBlock() != iblockdata1.getBlock()) {
world.removeTileEntity(blockposition);
}
2019-01-07 10:30:38 +11:00
diff --git a/src/main/java/net/minecraft/server/CraftingManager.java b/src/main/java/net/minecraft/server/CraftingManager.java
2019-12-22 10:00:03 +11:00
index c892ec74e..2dd27edc8 100644
2019-01-07 10:30:38 +11:00
--- a/src/main/java/net/minecraft/server/CraftingManager.java
+++ b/src/main/java/net/minecraft/server/CraftingManager.java
2019-06-21 20:00:00 +10:00
@@ -65,6 +65,7 @@ public class CraftingManager extends ResourceDataJson {
2019-01-07 10:30:38 +11:00
2019-06-21 20:00:00 +10:00
// CraftBukkit start
2019-04-23 12:00:00 +10:00
public void addRecipe(IRecipe<?> irecipe) {
2019-01-07 10:30:38 +11:00
+ org.spigotmc.AsyncCatcher.catchOp("Recipe Add"); // Spigot
2019-06-21 20:00:00 +10:00
Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>> map = this.recipes.get(irecipe.g()); // CraftBukkit
2019-04-23 12:00:00 +10:00
if (map.containsKey(irecipe.getKey())) {
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
2019-12-22 10:00:03 +11:00
index fec743be1..acf2bfd6f 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2019-12-11 09:00:00 +11:00
@@ -774,6 +774,7 @@ public abstract class EntityLiving extends Entity {
}
2018-07-20 16:13:18 +10:00
public boolean addEffect(MobEffect mobeffect, EntityPotionEffectEvent.Cause cause) {
+ org.spigotmc.AsyncCatcher.catchOp("effect add"); // Spigot
2015-02-12 14:25:18 +00:00
if (isTickingEffects) {
2018-07-20 16:13:18 +10:00
effectsToProcess.add(new ProcessableEffect(mobeffect, cause));
return true;
2019-04-23 12:00:00 +10:00
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
2019-12-22 10:00:03 +11:00
index f50c85b1d..2119e75dd 100644
2019-04-23 12:00:00 +10:00
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
2019-12-18 08:00:00 +11:00
@@ -967,6 +967,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
}
2019-04-23 12:00:00 +10:00
protected void addEntity(Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity track"); // Spigot
2019-04-23 12:00:00 +10:00
if (!(entity instanceof EntityComplexPart)) {
if (!(entity instanceof EntityLightning)) {
EntityTypes<?> entitytypes = entity.getEntityType();
2019-12-18 08:00:00 +11:00
@@ -1001,6 +1002,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
}
2019-04-23 12:00:00 +10:00
protected void removeEntity(Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity untrack"); // Spigot
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
2019-12-18 08:00:00 +11:00
@@ -1190,6 +1192,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
2019-04-23 12:00:00 +10:00
}
2019-04-23 12:00:00 +10:00
public void clear(EntityPlayer entityplayer) {
+ org.spigotmc.AsyncCatcher.catchOp("player tracker clear"); // Spigot
2019-04-23 12:00:00 +10:00
if (this.trackedPlayers.remove(entityplayer)) {
this.trackerEntry.a(entityplayer);
}
2019-12-18 08:00:00 +11:00
@@ -1197,6 +1200,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
2019-04-23 12:00:00 +10:00
}
2019-04-23 12:00:00 +10:00
public void updatePlayer(EntityPlayer entityplayer) {
+ org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
2019-04-23 12:00:00 +10:00
if (entityplayer != this.tracker) {
2019-12-11 09:00:00 +11:00
Vec3D vec3d = entityplayer.getPositionVector().d(this.tracker.getPositionVector()); // MC-155077, SPIGOT-5113
int i = Math.min(this.b(), (PlayerChunkMap.this.viewDistance - 1) * 16);
2019-04-23 12:00:00 +10:00
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2020-01-13 10:27:31 +11:00
index c6e3d9b5a..0157443e3 100644
2019-04-23 12:00:00 +10:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2019-12-22 10:00:03 +11:00
@@ -947,6 +947,7 @@ public class WorldServer extends World {
2019-04-23 12:00:00 +10:00
// CraftBukkit start
private boolean addEntity0(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
+ org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
2019-04-23 12:00:00 +10:00
if (entity.dead) {
2019-04-25 12:00:00 +10:00
// WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getName(entity.getEntityType())); // CraftBukkit
2018-12-17 12:35:20 +11:00
return false;
2019-12-22 10:00:03 +11:00
@@ -1015,6 +1016,7 @@ public class WorldServer extends World {
}
public void unregisterEntity(Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot
if (entity instanceof EntityEnderDragon) {
2019-12-11 09:00:00 +11:00
EntityComplexPart[] aentitycomplexpart = ((EntityEnderDragon) entity).eo();
int i = aentitycomplexpart.length;
2019-12-22 10:00:03 +11:00
@@ -1049,6 +1051,7 @@ public class WorldServer extends World {
}
private void registerEntity(Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity register"); // Spigot
2019-04-23 12:00:00 +10:00
if (this.tickingEntities) {
this.entitiesToAdd.add(entity);
2019-04-23 12:00:00 +10:00
} else {
2018-07-18 12:36:24 +10:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2020-01-13 10:27:31 +11:00
index 0eb3b16be..89ca00739 100644
2018-07-18 12:36:24 +10:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2019-12-11 09:00:00 +11:00
@@ -686,6 +686,7 @@ public final class CraftServer implements Server {
2018-07-18 12:36:24 +10:00
public boolean dispatchCommand(CommandSender sender, String commandLine) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(commandLine, "CommandLine cannot be null");
+ org.spigotmc.AsyncCatcher.catchOp("command dispatch"); // Spigot
2018-07-18 12:36:24 +10:00
if (commandMap.dispatch(sender, commandLine)) {
return true;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2020-01-13 10:27:31 +11:00
index 0e1bfa895..0ff24db92 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2020-01-13 10:27:31 +11:00
@@ -380,6 +380,7 @@ public class CraftWorld implements World {
2019-04-28 11:41:06 +10:00
@Override
2019-04-23 12:00:00 +10:00
public boolean unloadChunkRequest(int x, int z) {
+ org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
2019-04-23 12:00:00 +10:00
net.minecraft.server.IChunkAccess chunk = world.getChunkProvider().getChunkAt(x, z, ChunkStatus.FULL, false);
if (chunk != null) {
world.getChunkProvider().removeTicket(TicketType.PLUGIN, chunk.getPos(), 1, Unit.INSTANCE);
2020-01-13 10:27:31 +11:00
@@ -389,6 +390,7 @@ public class CraftWorld implements World {
}
2019-04-23 12:00:00 +10:00
private boolean unloadChunk0(int x, int z, boolean save) {
+ org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
2019-04-23 12:00:00 +10:00
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) world.getChunkProvider().getChunkAt(x, z, ChunkStatus.FULL, false);
if (chunk == null) {
return true;
2020-01-13 10:27:31 +11:00
@@ -403,6 +405,7 @@ public class CraftWorld implements World {
2019-04-28 11:41:06 +10:00
@Override
public boolean regenerateChunk(int x, int z) {
+ org.spigotmc.AsyncCatcher.catchOp("chunk regenerate"); // Spigot
2019-04-23 12:00:00 +10:00
throw new UnsupportedOperationException("Not supported in this Minecraft version! Unless you can fix it, this is not a bug :)");
/*
if (!unloadChunk0(x, z, false)) {
2020-01-13 10:27:31 +11:00
@@ -454,6 +457,7 @@ public class CraftWorld implements World {
2019-04-28 11:41:06 +10:00
@Override
public boolean loadChunk(int x, int z, boolean generate) {
+ org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot
2019-04-23 12:00:00 +10:00
IChunkAccess chunk = world.getChunkProvider().getChunkAt(x, z, generate ? ChunkStatus.FULL : ChunkStatus.EMPTY, true);
// If generate = false, but the chunk already exists, we will get this back.
2020-01-13 10:27:31 +11:00
@@ -1070,6 +1074,7 @@ public class CraftWorld implements World {
@Override
public Collection<Entity> getNearbyEntities(BoundingBox boundingBox, Predicate<Entity> filter) {
+ org.spigotmc.AsyncCatcher.catchOp("getNearbyEntities"); // Spigot
Validate.notNull(boundingBox, "Bounding box is null!");
AxisAlignedBB bb = new AxisAlignedBB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
2020-01-13 10:27:31 +11:00
@@ -1224,6 +1229,7 @@ public class CraftWorld implements World {
2019-08-13 20:38:28 +10:00
@Override
public void save() {
+ org.spigotmc.AsyncCatcher.catchOp("world save"); // Spigot
this.server.checkSaveState();
try {
boolean oldSave = world.savingDisabled;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2019-12-22 10:00:03 +11:00
index 57850343e..b48d81e51 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2019-12-11 09:00:00 +11:00
@@ -491,6 +491,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
@Override
public List<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z) {
+ org.spigotmc.AsyncCatcher.catchOp("getNearbyEntities"); // Spigot
List<Entity> notchEntityList = entity.world.getEntities(entity, entity.getBoundingBox().grow(x, y, z), null);
List<org.bukkit.entity.Entity> bukkitEntityList = new java.util.ArrayList<org.bukkit.entity.Entity>(notchEntityList.size());
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2020-01-13 10:27:31 +11:00
index 37ffc3944..9cba346a4 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2019-12-11 09:00:00 +11:00
@@ -299,6 +299,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2013-12-01 14:40:53 +11:00
@Override
public void kickPlayer(String message) {
+ org.spigotmc.AsyncCatcher.catchOp("player kick"); // Spigot
if (getHandle().playerConnection == null) return;
getHandle().playerConnection.disconnect(message == null ? "" : message);
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
2019-12-22 10:00:03 +11:00
index fd9949e1e..ca2be3060 100644
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
2019-04-28 11:41:06 +10:00
@@ -41,6 +41,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
2019-04-28 11:41:06 +10:00
@Override
public CraftScoreboard getNewScoreboard() {
+ org.spigotmc.AsyncCatcher.catchOp("scoreboard creation"); // Spigot
CraftScoreboard scoreboard = new CraftScoreboard(new ScoreboardServer(server));
scoreboards.add(scoreboard);
return scoreboard;
2017-06-19 19:56:13 +10:00
diff --git a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
2019-12-22 10:00:03 +11:00
index 2e057fd4c..ddef523ea 100644
2017-06-19 19:56:13 +10:00
--- a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
2019-04-23 12:00:00 +10:00
@@ -12,6 +12,7 @@ public class ServerShutdownThread extends Thread {
2017-06-19 19:56:13 +10:00
@Override
public void run() {
try {
+ org.spigotmc.AsyncCatcher.enabled = false; // Spigot
2019-04-23 12:00:00 +10:00
server.close();
} finally {
try {
diff --git a/src/main/java/org/spigotmc/AsyncCatcher.java b/src/main/java/org/spigotmc/AsyncCatcher.java
new file mode 100644
2019-12-22 10:00:03 +11:00
index 000000000..aeed76972
--- /dev/null
+++ b/src/main/java/org/spigotmc/AsyncCatcher.java
@@ -0,0 +1,17 @@
+package org.spigotmc;
+
+import net.minecraft.server.MinecraftServer;
+
+public class AsyncCatcher
+{
+
+ public static boolean enabled = true;
+
+ public static void catchOp(String reason)
+ {
2019-04-23 12:00:00 +10:00
+ if ( enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread )
+ {
+ throw new IllegalStateException( "Asynchronous " + reason + "!" );
+ }
+ }
+}
--
2019-04-23 09:33:25 +10:00
2.20.1