mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2024-11-21 22:06:13 +00:00
265 lines
14 KiB
Diff
265 lines
14 KiB
Diff
From 3a74f6c100d03a14c698ae26e71dff33327d70dd 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.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
index 4d8aa931fb..5043631d14 100644
|
|
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
@@ -1249,6 +1249,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
|
|
}
|
|
|
|
protected void addEntity(Entity entity) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("entity track"); // Spigot
|
|
if (!(entity instanceof EntityComplexPart)) {
|
|
EntityTypes<?> entitytypes = entity.getType();
|
|
int i = entitytypes.clientTrackingRange() * 16;
|
|
@@ -1284,6 +1285,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
|
|
}
|
|
|
|
protected void removeEntity(Entity entity) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("entity untrack"); // Spigot
|
|
if (entity instanceof EntityPlayer entityplayer) {
|
|
this.updatePlayerStatus(entityplayer, false);
|
|
ObjectIterator objectiterator = this.entityMap.values().iterator();
|
|
@@ -1503,6 +1505,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
|
|
}
|
|
|
|
public void removePlayer(EntityPlayer entityplayer) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("player tracker clear"); // Spigot
|
|
if (this.seenBy.remove(entityplayer.connection)) {
|
|
this.serverEntity.removePairing(entityplayer);
|
|
}
|
|
@@ -1510,6 +1513,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
|
|
}
|
|
|
|
public void updatePlayer(EntityPlayer entityplayer) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
|
|
if (entityplayer != this.entity) {
|
|
Vec3D vec3d = entityplayer.position().subtract(this.entity.position());
|
|
int i = PlayerChunkMap.this.getPlayerViewDistance(entityplayer);
|
|
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
index b61ac113a1..0166025d16 100644
|
|
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
@@ -1067,6 +1067,7 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
|
|
|
|
// CraftBukkit start
|
|
private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
|
|
if (entity.isRemoved()) {
|
|
// WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
|
|
return false;
|
|
@@ -1926,6 +1927,7 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
|
|
|
|
@Override
|
|
public LevelEntityGetter<Entity> getEntities() {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Chunk getEntities call"); // Spigot
|
|
return this.entityManager.getEntityGetter();
|
|
}
|
|
|
|
@@ -2045,6 +2047,7 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
|
|
}
|
|
|
|
public void onTrackingStart(Entity entity) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("entity register"); // Spigot
|
|
WorldServer.this.getChunkSource().addEntity(entity);
|
|
if (entity instanceof EntityPlayer entityplayer) {
|
|
WorldServer.this.players.add(entityplayer);
|
|
@@ -2078,6 +2081,7 @@ public class WorldServer extends World implements ServerEntityGetter, GeneratorA
|
|
}
|
|
|
|
public void onTrackingEnd(Entity entity) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot
|
|
WorldServer.this.getChunkSource().removeEntity(entity);
|
|
if (entity instanceof EntityPlayer entityplayer) {
|
|
WorldServer.this.players.remove(entityplayer);
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
index 02f729d695..7fe581b308 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
@@ -1129,6 +1129,7 @@ public abstract class EntityLiving extends Entity implements Attackable {
|
|
}
|
|
|
|
public boolean addEffect(MobEffect mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("effect add"); // Spigot
|
|
if (isTickingEffects) {
|
|
effectsToProcess.add(new ProcessableEffect(mobeffect, cause));
|
|
return true;
|
|
diff --git a/src/main/java/net/minecraft/world/item/crafting/CraftingManager.java b/src/main/java/net/minecraft/world/item/crafting/CraftingManager.java
|
|
index dd28f90d90..7f58791c8a 100644
|
|
--- a/src/main/java/net/minecraft/world/item/crafting/CraftingManager.java
|
|
+++ b/src/main/java/net/minecraft/world/item/crafting/CraftingManager.java
|
|
@@ -116,6 +116,7 @@ public class CraftingManager extends ResourceDataAbstract<RecipeMap> implements
|
|
|
|
// CraftBukkit start
|
|
public void addRecipe(RecipeHolder<?> irecipe) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Recipe Add"); // Spigot
|
|
this.recipes.addRecipe(irecipe);
|
|
finalizeRecipeLoading();
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBase.java b/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
|
|
index 3a143fffa3..8d15390052 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
|
|
@@ -161,7 +161,9 @@ public abstract class BlockBase implements FeatureElement {
|
|
|
|
protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, @Nullable Orientation orientation, boolean flag) {}
|
|
|
|
- protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {}
|
|
+ protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("block onPlace"); // Spigot
|
|
+ }
|
|
|
|
// CraftBukkit start
|
|
protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag, @Nullable ItemActionContext context) {
|
|
@@ -170,6 +172,7 @@ public abstract class BlockBase implements FeatureElement {
|
|
// CraftBukkit end
|
|
|
|
protected void onRemove(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("block remove"); // Spigot
|
|
if (iblockdata.hasBlockEntity() && !iblockdata.is(iblockdata1.getBlock())) {
|
|
world.removeBlockEntity(blockposition);
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 7a5f99dc86..10c80d8563 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -900,6 +900,7 @@ public final class CraftServer implements Server {
|
|
public boolean dispatchCommand(CommandSender sender, String commandLine) {
|
|
Preconditions.checkArgument(sender != null, "sender cannot be null");
|
|
Preconditions.checkArgument(commandLine != null, "commandLine cannot be null");
|
|
+ org.spigotmc.AsyncCatcher.catchOp("command dispatch"); // Spigot
|
|
|
|
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 09506adef0..5fc6924dfa 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -287,6 +287,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public boolean unloadChunkRequest(int x, int z) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
|
|
if (isChunkLoaded(x, z)) {
|
|
world.getChunkSource().removeRegionTicket(TicketType.PLUGIN, new ChunkCoordIntPair(x, z), 1, Unit.INSTANCE);
|
|
}
|
|
@@ -295,6 +296,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
}
|
|
|
|
private boolean unloadChunk0(int x, int z, boolean save) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("chunk unload"); // Spigot
|
|
if (!isChunkLoaded(x, z)) {
|
|
return true;
|
|
}
|
|
@@ -311,6 +313,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public boolean regenerateChunk(int x, int z) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("chunk regenerate"); // Spigot
|
|
throw new UnsupportedOperationException("Not supported in this Minecraft version! Unless you can fix it, this is not a bug :)");
|
|
/*
|
|
if (!unloadChunk0(x, z, false)) {
|
|
@@ -388,6 +391,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
|
|
IChunkAccess chunk = world.getChunkSource().getChunk(x, z, generate ? ChunkStatus.FULL : ChunkStatus.EMPTY, true);
|
|
|
|
// If generate = false, but the chunk already exists, we will get this back.
|
|
@@ -923,6 +927,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public Collection<Entity> getNearbyEntities(BoundingBox boundingBox, Predicate<? super Entity> filter) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("getNearbyEntities"); // Spigot
|
|
Preconditions.checkArgument(boundingBox != null, "BoundingBox cannot be null");
|
|
|
|
AxisAlignedBB bb = new AxisAlignedBB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
|
|
@@ -1077,6 +1082,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public void save() {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("world save"); // Spigot
|
|
this.server.checkSaveState();
|
|
boolean oldSave = world.noSave;
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index ff47b09dcc..f9aba6e6d0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -230,6 +230,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
@Override
|
|
public List<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z) {
|
|
Preconditions.checkState(!entity.generation, "Cannot get nearby entities during world generation");
|
|
+ org.spigotmc.AsyncCatcher.catchOp("getNearbyEntities"); // Spigot
|
|
|
|
List<Entity> notchEntityList = entity.level().getEntities(entity, entity.getBoundingBox().inflate(x, y, z), Predicates.alwaysTrue());
|
|
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 241a17ddd9..0738f19a44 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -496,6 +496,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
|
|
@Override
|
|
public void kickPlayer(String message) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("player kick"); // Spigot
|
|
getHandle().transferCookieConnection.kickPlayer(CraftChatMessage.fromStringOrEmpty(message, true));
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
|
index 726887ece2..ec5670e24b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
|
@@ -41,6 +41,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
|
|
|
|
@Override
|
|
public CraftScoreboard getNewScoreboard() {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("scoreboard creation"); // Spigot
|
|
CraftScoreboard scoreboard = new CraftScoreboard(new ScoreboardServer(server));
|
|
scoreboards.add(scoreboard);
|
|
return scoreboard;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
index 2e057fd4c0..ddef523ea8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
@@ -12,6 +12,7 @@ public class ServerShutdownThread extends Thread {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
+ org.spigotmc.AsyncCatcher.enabled = false; // Spigot
|
|
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 0000000000..aeed769725
|
|
--- /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)
|
|
+ {
|
|
+ if ( enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread )
|
|
+ {
|
|
+ throw new IllegalStateException( "Asynchronous " + reason + "!" );
|
|
+ }
|
|
+ }
|
|
+}
|
|
--
|
|
2.47.0
|
|
|