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

253 lines
13 KiB
Diff
Raw Normal View History

From 8a7f85758da06bc53fca5bc1e4d609611d7bb6c9 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
2020-04-14 12:42:02 +10:00
index f047e024b..ca9ed5739 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-04-14 12:42:02 +10:00
@@ -70,6 +70,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 25ee7f327..c05fa2682 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2020-01-22 08:00:00 +11:00
@@ -776,6 +776,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
2020-02-02 11:20:00 +11:00
index 70cf38177..381738798 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-01-22 08:00:00 +11:00
@@ -972,6 +972,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();
2020-01-22 08:00:00 +11:00
@@ -1006,6 +1007,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-01-22 08:00:00 +11:00
@@ -1195,6 +1197,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-01-22 08:00:00 +11:00
@@ -1202,6 +1205,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-02-20 09:26:22 +11:00
index 26248d91c..bbe5a08f2 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
2020-01-22 08:00:00 +11:00
@@ -957,6 +957,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;
2020-01-22 08:00:00 +11:00
@@ -1025,6 +1026,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;
2020-01-22 08:00:00 +11:00
@@ -1059,6 +1061,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-04-14 12:42:02 +10:00
index 8b039899a..6446de65f 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
2020-03-08 19:40:51 +11:00
@@ -698,6 +698,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 d387bf11c..99cf42026 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2020-04-22 11:50:25 +10:00
@@ -381,6 +381,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-04-22 11:50:25 +10:00
@@ -390,6 +391,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-04-22 11:50:25 +10:00
@@ -404,6 +406,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-04-22 11:50:25 +10:00
@@ -455,6 +458,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.
@@ -1089,6 +1093,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());
@@ -1243,6 +1248,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
2020-04-14 12:42:02 +10:00
index 275d41d89..978c32b50 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2020-04-14 12:42:02 +10:00
@@ -493,6 +493,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-04-14 12:42:02 +10:00
index deb86613c..cdb45b050 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -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 + "!" );
+ }
+ }
+}
--
2.25.1