2018-12-13 11:00:00 +11:00
|
|
|
From c8651ebe88df15eb12df958cccffb81ae543c0c4 Mon Sep 17 00:00:00 2001
|
2014-03-25 16:11:22 +11:00
|
|
|
From: md_5 <git@md-5.net>
|
|
|
|
Date: Tue, 25 Mar 2014 16:10:01 +1100
|
2013-03-23 18:05:22 +11:00
|
|
|
Subject: [PATCH] Async Operation Catching
|
2013-03-07 20:12:53 +11:00
|
|
|
|
2013-03-23 18:05:22 +11:00
|
|
|
Catch and throw an exception when a potentially unsafe operation occurs on a thread other than the main server thread.
|
2013-03-07 20:12:53 +11:00
|
|
|
|
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
|
2018-12-13 11:00:00 +11:00
|
|
|
index a7f942de8..a30b21ad2 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
|
2018-12-06 10:00:00 +11:00
|
|
|
@@ -374,10 +374,14 @@ public class Block implements IMaterial {
|
2013-08-03 19:09:09 +10:00
|
|
|
}
|
|
|
|
|
2018-07-15 10:00:00 +10:00
|
|
|
@Deprecated
|
|
|
|
- public void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1) {}
|
|
|
|
+ public void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "block onPlace"); // Spigot
|
2013-08-03 19:09:09 +10:00
|
|
|
+ }
|
|
|
|
|
2018-07-15 10:00:00 +10:00
|
|
|
@Deprecated
|
|
|
|
- public void remove(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {}
|
|
|
|
+ public void remove(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "block remove"); // Spigot
|
2013-08-03 19:09:09 +10:00
|
|
|
+ }
|
|
|
|
|
2018-07-15 10:00:00 +10:00
|
|
|
public int a(IBlockData iblockdata, Random random) {
|
2013-08-03 19:09:09 +10:00
|
|
|
return 1;
|
2015-01-12 11:38:47 +11:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
2018-12-13 11:00:00 +11:00
|
|
|
index f411c0378..2f9944ba5 100644
|
2015-01-12 11:38:47 +11:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
2018-07-21 10:19:54 +10:00
|
|
|
@@ -725,6 +725,7 @@ public abstract class EntityLiving extends Entity {
|
2015-01-12 11:38:47 +11:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:13:18 +10:00
|
|
|
public boolean addEffect(MobEffect mobeffect, EntityPotionEffectEvent.Cause cause) {
|
2015-01-12 11:38:47 +11:00
|
|
|
+ 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;
|
2013-03-23 18:27:02 +11:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityTracker.java b/src/main/java/net/minecraft/server/EntityTracker.java
|
2018-12-13 11:00:00 +11:00
|
|
|
index ee261f25a..5cfa09fff 100644
|
2013-03-23 18:27:02 +11:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityTracker.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityTracker.java
|
2016-11-17 12:41:12 +11:00
|
|
|
@@ -105,6 +105,7 @@ public class EntityTracker {
|
2013-03-23 18:27:02 +11:00
|
|
|
}
|
|
|
|
|
2018-07-15 10:00:00 +10:00
|
|
|
public void addEntity(Entity entity, int i, int j, boolean flag) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "entity track"); // Spigot
|
2016-03-01 08:33:06 +11:00
|
|
|
try {
|
|
|
|
if (this.trackedEntities.b(entity.getId())) {
|
|
|
|
throw new IllegalStateException("Entity is already tracked!");
|
2018-07-15 10:00:00 +10:00
|
|
|
@@ -142,6 +143,7 @@ public class EntityTracker {
|
2013-03-23 18:27:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public void untrackEntity(Entity entity) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "entity untrack"); // Spigot
|
2013-03-23 18:27:02 +11:00
|
|
|
if (entity instanceof EntityPlayer) {
|
|
|
|
EntityPlayer entityplayer = (EntityPlayer) entity;
|
2013-12-01 14:40:53 +11:00
|
|
|
Iterator iterator = this.c.iterator();
|
2013-03-23 18:27:02 +11:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
2018-12-13 11:00:00 +11:00
|
|
|
index e6b492048..6a622f72e 100644
|
2013-03-23 18:27:02 +11:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
|
2016-03-01 08:33:06 +11:00
|
|
|
@@ -324,6 +324,7 @@ public class EntityTrackerEntry {
|
2013-03-23 18:27:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePlayer(EntityPlayer entityplayer) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "player tracker update"); // Spigot
|
2013-03-23 18:27:02 +11:00
|
|
|
if (entityplayer != this.tracker) {
|
2014-11-26 08:27:08 +11:00
|
|
|
if (this.c(entityplayer)) {
|
2015-02-28 11:36:22 +00:00
|
|
|
if (!this.trackedPlayers.contains(entityplayer) && (this.e(entityplayer) || this.tracker.attachedToPlayer)) {
|
2018-07-15 10:00:00 +10:00
|
|
|
@@ -567,6 +568,7 @@ public class EntityTrackerEntry {
|
2013-03-23 18:27:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clear(EntityPlayer entityplayer) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "player tracker clear"); // Spigot
|
2013-03-23 18:27:02 +11:00
|
|
|
if (this.trackedPlayers.contains(entityplayer)) {
|
|
|
|
this.trackedPlayers.remove(entityplayer);
|
2016-03-01 08:33:06 +11:00
|
|
|
this.tracker.c(entityplayer);
|
2013-03-23 18:27:02 +11:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2018-12-13 11:00:00 +11:00
|
|
|
index f51dbf185..fe95194e5 100644
|
2013-03-23 18:27:02 +11:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2018-08-26 12:00:00 +10:00
|
|
|
@@ -861,6 +861,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2013-03-23 18:27:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean addEntity(Entity entity, SpawnReason spawnReason) { // Changed signature, added SpawnReason
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "entity add"); // Spigot
|
2013-03-23 18:27:02 +11:00
|
|
|
if (entity == null) return false;
|
2017-12-09 18:08:16 +11:00
|
|
|
|
|
|
|
org.bukkit.event.Cancellable event = null;
|
2018-09-15 15:22:20 +10:00
|
|
|
@@ -958,6 +959,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2017-06-18 16:48:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
public void kill(Entity entity) {
|
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "entity kill"); // Spigot
|
|
|
|
if (entity.isVehicle()) {
|
|
|
|
entity.ejectPassengers();
|
|
|
|
}
|
2018-09-15 15:22:20 +10:00
|
|
|
@@ -976,6 +978,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2013-03-23 18:27:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removeEntity(Entity entity) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "entity remove"); // Spigot
|
2016-03-01 08:33:06 +11:00
|
|
|
entity.b(false);
|
2013-03-23 18:27:02 +11:00
|
|
|
entity.die();
|
|
|
|
if (entity instanceof EntityHuman) {
|
2018-09-21 20:57:04 +10:00
|
|
|
@@ -2193,6 +2196,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2013-05-01 16:39:55 +10:00
|
|
|
}
|
|
|
|
|
2018-08-26 12:00:00 +10:00
|
|
|
public void a(Stream<Entity> stream) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "entity world add"); // Spigot
|
2018-08-26 12:00:00 +10:00
|
|
|
stream.forEach((entity) -> {
|
|
|
|
this.entityList.add(entity);
|
|
|
|
this.b(entity);
|
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
|
2018-12-13 11:00:00 +11:00
|
|
|
index e00b59959..7166ddb46 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
|
2018-11-10 20:46:28 +11:00
|
|
|
@@ -678,6 +678,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
|
|
|
|
|
|
|
|
if (commandMap.dispatch(sender, commandLine)) {
|
|
|
|
return true;
|
2013-03-07 20:12:53 +11:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2018-12-13 11:00:00 +11:00
|
|
|
index afd44feff..15dc0ffbe 100644
|
2013-03-07 20:12:53 +11:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2018-10-26 20:03:06 +11:00
|
|
|
@@ -189,6 +189,7 @@ public class CraftWorld implements World {
|
2013-03-07 20:12:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean unloadChunkRequest(int x, int z, boolean safe) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "chunk unload"); // Spigot
|
2013-03-07 20:12:53 +11:00
|
|
|
if (safe && isChunkInUse(x, z)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-26 20:03:06 +11:00
|
|
|
@@ -202,6 +203,7 @@ public class CraftWorld implements World {
|
2013-03-07 20:12:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean unloadChunk(int x, int z, boolean save, boolean safe) {
|
2018-11-03 20:28:44 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "chunk unload" ); // Spigot
|
2016-03-19 14:46:10 +11:00
|
|
|
if (isChunkInUse(x, z)) {
|
2013-03-07 20:12:53 +11:00
|
|
|
return false;
|
|
|
|
}
|
2018-11-03 20:28:44 +11:00
|
|
|
@@ -220,6 +222,7 @@ public class CraftWorld implements World {
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean regenerateChunk(int x, int z) {
|
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "chunk regenerate" ); // Spigot
|
|
|
|
if (!unloadChunk0(x, z, false)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
@@ -265,6 +268,7 @@ public class CraftWorld implements World {
|
2013-03-07 20:12:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean loadChunk(int x, int z, boolean generate) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "chunk load"); // Spigot
|
2013-03-07 20:12:53 +11:00
|
|
|
chunkLoadCount++;
|
2018-12-13 11:00:00 +11:00
|
|
|
return world.getChunkProvider().getChunkAt(x, z, true, generate) != null;
|
2018-08-26 12:00:00 +10:00
|
|
|
}
|
2013-03-23 18:05:22 +11:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2018-11-10 20:46:28 +11:00
|
|
|
index f77241361..99226bffd 100644
|
2013-03-23 18:05:22 +11:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2018-08-06 10:32:15 +10:00
|
|
|
@@ -293,6 +293,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2013-03-23 18:05:22 +11:00
|
|
|
|
2013-12-01 14:40:53 +11:00
|
|
|
@Override
|
2013-03-23 18:05:22 +11:00
|
|
|
public void kickPlayer(String message) {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "player kick"); // Spigot
|
2013-03-23 18:05:22 +11:00
|
|
|
if (getHandle().playerConnection == null) return;
|
|
|
|
|
|
|
|
getHandle().playerConnection.disconnect(message == null ? "" : message);
|
2014-01-25 15:23:21 +11:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
2018-07-20 16:13:18 +10:00
|
|
|
index cac87d306..9cce899f5 100644
|
2014-01-25 15:23:21 +11:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java
|
2018-07-15 10:00:00 +10:00
|
|
|
@@ -43,6 +43,7 @@ public final class CraftScoreboardManager implements ScoreboardManager {
|
2014-01-25 15:23:21 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public CraftScoreboard getNewScoreboard() {
|
2014-03-25 16:11:22 +11:00
|
|
|
+ org.spigotmc.AsyncCatcher.catchOp( "scoreboard creation"); // Spigot
|
2014-01-25 15:23:21 +11:00
|
|
|
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
|
2018-07-20 16:13:18 +10:00
|
|
|
index ae3481ba8..a0cdd2317 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
|
|
|
|
@@ -13,6 +13,7 @@ public class ServerShutdownThread extends Thread {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
+ org.spigotmc.AsyncCatcher.enabled = false; // Spigot
|
|
|
|
server.stop();
|
|
|
|
} catch (ExceptionWorldConflict ex) {
|
|
|
|
ex.printStackTrace();
|
2014-03-25 16:11:22 +11:00
|
|
|
diff --git a/src/main/java/org/spigotmc/AsyncCatcher.java b/src/main/java/org/spigotmc/AsyncCatcher.java
|
|
|
|
new file mode 100644
|
2018-07-20 16:13:18 +10:00
|
|
|
index 000000000..4b3aa85c9
|
2014-03-25 16:11:22 +11:00
|
|
|
--- /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().primaryThread )
|
|
|
|
+ {
|
|
|
|
+ throw new IllegalStateException( "Asynchronous " + reason + "!" );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
2013-03-07 20:12:53 +11:00
|
|
|
--
|
2018-11-14 14:20:34 +11:00
|
|
|
2.19.1
|
2013-03-07 20:12:53 +11:00
|
|
|
|