mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-04-13 09:32:09 +00:00
261 lines
14 KiB
Diff
261 lines
14 KiB
Diff
From 8a0d5c16b2a049a7bebf980ccd48647ef0398069 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 72e1ebb2e2..d2f7178031 100644
|
|
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
@@ -1299,6 +1299,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
|
}
|
|
|
|
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;
|
|
@@ -1334,6 +1335,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
|
}
|
|
|
|
protected void removeEntity(Entity entity) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("entity untrack"); // Spigot
|
|
if (entity instanceof EntityPlayer) {
|
|
EntityPlayer entityplayer = (EntityPlayer) entity;
|
|
|
|
@@ -1557,6 +1559,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
|
}
|
|
|
|
public void removePlayer(EntityPlayer entityplayer) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("player tracker clear"); // Spigot
|
|
if (this.seenBy.remove(entityplayer.connection)) {
|
|
this.serverEntity.removePairing(entityplayer);
|
|
}
|
|
@@ -1564,6 +1567,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
|
|
}
|
|
|
|
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 046e1483d3..2437fc257b 100644
|
|
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
@@ -1050,6 +1050,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
|
|
|
// 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;
|
|
@@ -1848,6 +1849,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
|
|
|
@Override
|
|
public LevelEntityGetter<Entity> getEntities() {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Chunk getEntities call"); // Spigot
|
|
return this.entityManager.getEntityGetter();
|
|
}
|
|
|
|
@@ -1934,6 +1936,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
|
}
|
|
|
|
public void onTrackingStart(Entity entity) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("entity register"); // Spigot
|
|
WorldServer.this.getChunkSource().addEntity(entity);
|
|
if (entity instanceof EntityPlayer) {
|
|
EntityPlayer entityplayer = (EntityPlayer) entity;
|
|
@@ -1971,6 +1974,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
|
}
|
|
|
|
public void onTrackingEnd(Entity entity) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot
|
|
WorldServer.this.getChunkSource().removeEntity(entity);
|
|
if (entity instanceof EntityPlayer) {
|
|
EntityPlayer entityplayer = (EntityPlayer) entity;
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
index cabfdd41b0..d0ba845d01 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
@@ -1102,6 +1102,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 7917e442cd..1efa5da7a5 100644
|
|
--- a/src/main/java/net/minecraft/world/item/crafting/CraftingManager.java
|
|
+++ b/src/main/java/net/minecraft/world/item/crafting/CraftingManager.java
|
|
@@ -89,6 +89,7 @@ public class CraftingManager extends ResourceDataJson {
|
|
|
|
// CraftBukkit start
|
|
public void addRecipe(RecipeHolder<?> irecipe) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Recipe Add"); // Spigot
|
|
Object2ObjectLinkedOpenHashMap<MinecraftKey, RecipeHolder<?>> map = this.recipes.get(irecipe.value().getType()); // CraftBukkit
|
|
|
|
if (byName.containsKey(irecipe.id()) || map.containsKey(irecipe.id())) {
|
|
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 1a8d0e5688..148c019544 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
|
|
@@ -145,11 +145,14 @@ public abstract class BlockBase implements FeatureElement {
|
|
|
|
/** @deprecated */
|
|
@Deprecated
|
|
- 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
|
|
+ }
|
|
|
|
/** @deprecated */
|
|
@Deprecated
|
|
public 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 32e151e78c..f5c3c793ea 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -855,6 +855,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 8dc870a5d9..8621c949e7 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -273,6 +273,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);
|
|
}
|
|
@@ -281,6 +282,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;
|
|
}
|
|
@@ -295,6 +297,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)) {
|
|
@@ -347,6 +350,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.
|
|
@@ -841,6 +845,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
@Override
|
|
public Collection<Entity> getNearbyEntities(BoundingBox boundingBox, Predicate<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());
|
|
@@ -995,6 +1000,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 6917e5f088..05ce211d50 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -569,6 +569,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 b887b19c82..b4477e693c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -388,6 +388,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
|
|
@Override
|
|
public void kickPlayer(String message) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("player kick"); // Spigot
|
|
if (getHandle().connection == null) return;
|
|
|
|
getHandle().connection.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 1713b8698e..a9acf1d067 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.42.0
|
|
|