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

297 lines
15 KiB
Diff
Raw Normal View History

From 2aa0ec5ac2659044ad447f8979b32e1278348b2c 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.
2020-06-25 10:00:00 +10:00
diff --git a/src/main/java/net/minecraft/server/BlockBase.java b/src/main/java/net/minecraft/server/BlockBase.java
index 753bdb7e..f28b9c09 100644
2020-06-25 10:00:00 +10:00
--- a/src/main/java/net/minecraft/server/BlockBase.java
+++ b/src/main/java/net/minecraft/server/BlockBase.java
@@ -69,10 +69,13 @@ public abstract class BlockBase {
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
2020-06-25 10:00:00 +10:00
if (this.isTileEntity() && !iblockdata.a(iblockdata1.getBlock())) {
2019-04-23 12:00:00 +10:00
world.removeTileEntity(blockposition);
}
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index f0954d03..2c952e2d 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -333,6 +333,7 @@ public class Chunk implements IChunkAccess {
@Override
public void a(Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("Chunk add entity"); // Spigot
this.q = true;
int i = MathHelper.floor(entity.locX() / 16.0D);
int j = MathHelper.floor(entity.locZ() / 16.0D);
@@ -369,6 +370,7 @@ public class Chunk implements IChunkAccess {
}
public void a(Entity entity, int i) {
+ org.spigotmc.AsyncCatcher.catchOp("Chunk remove entity"); // Spigot
if (i < 0) {
i = 0;
}
@@ -557,6 +559,7 @@ public class Chunk implements IChunkAccess {
}
public void a(@Nullable Entity entity, AxisAlignedBB axisalignedbb, List<Entity> list, @Nullable Predicate<? super Entity> predicate) {
+ org.spigotmc.AsyncCatcher.catchOp("Chunk getEntities call"); // Spigot
int i = MathHelper.floor((axisalignedbb.minY - 2.0D) / 16.0D);
int j = MathHelper.floor((axisalignedbb.maxY + 2.0D) / 16.0D);
@@ -595,6 +598,7 @@ public class Chunk implements IChunkAccess {
}
public <T extends Entity> void a(@Nullable EntityTypes<?> entitytypes, AxisAlignedBB axisalignedbb, List<? super T> list, Predicate<? super T> predicate) {
+ org.spigotmc.AsyncCatcher.catchOp("Chunk getEntities call"); // Spigot
int i = MathHelper.floor((axisalignedbb.minY - 2.0D) / 16.0D);
int j = MathHelper.floor((axisalignedbb.maxY + 2.0D) / 16.0D);
@@ -616,6 +620,7 @@ public class Chunk implements IChunkAccess {
}
public <T extends Entity> void a(Class<? extends T> oclass, AxisAlignedBB axisalignedbb, List<T> list, @Nullable Predicate<? super T> predicate) {
+ org.spigotmc.AsyncCatcher.catchOp("Chunk getEntities call"); // Spigot
int i = MathHelper.floor((axisalignedbb.minY - 2.0D) / 16.0D);
int j = MathHelper.floor((axisalignedbb.maxY + 2.0D) / 16.0D);
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
index f9762de9..fdb7d96c 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
2020-06-25 10:00:00 +10:00
@@ -71,6 +71,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
index fd9f4689..295cbb5e 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2021-01-01 08:53:21 +11:00
@@ -889,6 +889,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
index be6d3548..b9e44767 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
2020-06-25 10:00:00 +10:00
@@ -1005,6 +1005,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)) {
2020-06-25 10:00:00 +10:00
EntityTypes<?> entitytypes = entity.getEntityType();
int i = entitytypes.getChunkRange() * 16;
@@ -1037,6 +1038,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;
2020-06-25 10:00:00 +10:00
@@ -1226,6 +1228,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);
}
2020-06-25 10:00:00 +10:00
@@ -1233,6 +1236,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
index 46fc05b9..bd154420 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
@@ -887,6 +887,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
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;
@@ -994,6 +995,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
}
public void unregisterEntity(Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot
if (entity instanceof EntityEnderDragon) {
2020-08-12 07:00:00 +10:00
EntityComplexPart[] aentitycomplexpart = ((EntityEnderDragon) entity).eJ();
int i = aentitycomplexpart.length;
@@ -1028,6 +1030,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
}
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
index e3fa6ead..27b4683a 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
2021-01-31 10:08:46 +11:00
@@ -737,6 +737,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
index c902748c..3584690a 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -388,6 +388,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
2020-06-06 19:28:03 +10:00
if (isChunkLoaded(x, z)) {
world.getChunkProvider().removeTicket(TicketType.PLUGIN, new ChunkCoordIntPair(x, z), 1, Unit.INSTANCE);
}
@@ -396,6 +397,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
2020-06-06 19:28:03 +10:00
if (!isChunkLoaded(x, z)) {
2019-04-23 12:00:00 +10:00
return true;
2020-06-06 19:28:03 +10:00
}
@@ -410,6 +412,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)) {
@@ -461,6 +464,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.
@@ -1087,6 +1091,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());
@@ -1241,6 +1246,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();
2020-06-25 10:00:00 +10:00
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
index 07777994..b677f8a7 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2021-01-01 08:53:21 +11:00
@@ -512,6 +512,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
index e8df8fed..d65f88b3 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2021-01-31 10:08:46 +11:00
@@ -326,6 +326,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
index fd9949e1..ca2be306 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
index 2e057fd4..ddef523e 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
index 00000000..aeed7697
--- /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 + "!" );
+ }
+ }
+}
--
2.30.0.windows.2