mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-04-13 09:32:09 +00:00
259 lines
14 KiB
Diff
259 lines
14 KiB
Diff
From b61c73275c120ac577332ff018dbe07d12ba4900 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 b544ea018..7ca61718b 100644
|
|
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
@@ -1195,6 +1195,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;
|
|
@@ -1230,6 +1231,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();
|
|
@@ -1449,6 +1451,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);
|
|
}
|
|
@@ -1456,6 +1459,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 23a3ae198..f07e8247e 100644
|
|
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
@@ -1073,6 +1073,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;
|
|
@@ -1870,6 +1871,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();
|
|
}
|
|
|
|
@@ -1975,6 +1977,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) {
|
|
WorldServer.this.players.add(entityplayer);
|
|
@@ -2008,6 +2011,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) {
|
|
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 44f12aefa..85336a6a9 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
@@ -1105,6 +1105,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 28715833f..09980fd09 100644
|
|
--- a/src/main/java/net/minecraft/world/item/crafting/CraftingManager.java
|
|
+++ b/src/main/java/net/minecraft/world/item/crafting/CraftingManager.java
|
|
@@ -84,6 +84,7 @@ public class CraftingManager extends ResourceDataJson {
|
|
|
|
// CraftBukkit start
|
|
public void addRecipe(RecipeHolder<?> irecipe) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("Recipe Add"); // Spigot
|
|
Collection<RecipeHolder<?>> map = this.byType.get(irecipe.value().getType()); // CraftBukkit
|
|
|
|
if (byName.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 bec71ad60..3b76307d3 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
|
|
@@ -154,9 +154,12 @@ public abstract class BlockBase implements FeatureElement {
|
|
PacketDebug.sendNeighborsUpdatePacket(world, blockposition);
|
|
}
|
|
|
|
- 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
|
|
+ }
|
|
|
|
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 7754c2864..a24b5f0d0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -896,6 +896,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 fd784d6a0..a8e1dc73f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -283,6 +283,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);
|
|
}
|
|
@@ -291,6 +292,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;
|
|
}
|
|
@@ -305,6 +307,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)) {
|
|
@@ -382,6 +385,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.
|
|
@@ -916,6 +920,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());
|
|
@@ -1070,6 +1075,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 dbc5e3262..8dae9176c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -229,6 +229,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 08cf2bdd7..0f9b9113b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -477,6 +477,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(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 726887ece..ec5670e24 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 2e057fd4c..ddef523ea 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 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)
|
|
+ {
|
|
+ if ( enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread )
|
|
+ {
|
|
+ throw new IllegalStateException( "Asynchronous " + reason + "!" );
|
|
+ }
|
|
+ }
|
|
+}
|
|
--
|
|
2.45.2
|
|
|