Additions to the async operation catching patch.

This commit is contained in:
md_5 2013-03-23 18:27:02 +11:00
parent cca2920506
commit ab31621dc0
6 changed files with 98 additions and 35 deletions

View File

@ -1,23 +1,86 @@
From 67cddbc9856c267a110cf7531b8fde518e327613 Mon Sep 17 00:00:00 2001
From c4e48c299169a97a90a6d75871c39c6998a39cb9 Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Thu, 7 Mar 2013 20:12:46 +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.
---
src/main/java/net/minecraft/server/EntityTracker.java | 2 ++
src/main/java/net/minecraft/server/EntityTrackerEntry.java | 2 ++
src/main/java/net/minecraft/server/World.java | 2 ++
src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 3 +++
src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | 1 +
2 files changed, 4 insertions(+)
5 files changed, 10 insertions(+)
diff --git a/src/main/java/net/minecraft/server/EntityTracker.java b/src/main/java/net/minecraft/server/EntityTracker.java
index 4de1273..db62084 100644
--- a/src/main/java/net/minecraft/server/EntityTracker.java
+++ b/src/main/java/net/minecraft/server/EntityTracker.java
@@ -89,6 +89,7 @@ public class EntityTracker {
}
public void addEntity(Entity entity, int i, int j, boolean flag) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous entity track!"); // Spigot
if (i > this.d) {
i = this.d;
}
@@ -124,6 +125,7 @@ public class EntityTracker {
}
public void untrackEntity(Entity entity) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous entity untrack!"); // Spigot
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
Iterator iterator = this.b.iterator();
diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
index ae9ed52..9c014ca 100644
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
@@ -286,6 +286,7 @@ public class EntityTrackerEntry {
}
public void updatePlayer(EntityPlayer entityplayer) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous player tracker update!"); // Spigot
if (entityplayer != this.tracker) {
double d0 = entityplayer.locX - (double) (this.xLoc / 32);
double d1 = entityplayer.locZ - (double) (this.zLoc / 32);
@@ -470,6 +471,7 @@ public class EntityTrackerEntry {
}
public void clear(EntityPlayer entityplayer) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous player tracker clear!"); // Spigot
if (this.trackedPlayers.contains(entityplayer)) {
this.trackedPlayers.remove(entityplayer);
entityplayer.removeQueue.add(Integer.valueOf(this.tracker.id));
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 0c378e7..4518acc 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -919,6 +919,7 @@ public abstract class World implements IBlockAccess {
}
public boolean addEntity(Entity entity, SpawnReason spawnReason) { // Changed signature, added SpawnReason
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous entity add!"); // Spigot
if (entity == null) return false;
// CraftBukkit end
@@ -1025,6 +1026,7 @@ public abstract class World implements IBlockAccess {
}
public void removeEntity(Entity entity) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous entity remove!"); // Spigot
entity.die();
if (entity instanceof EntityHuman) {
this.players.remove(entity);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 9343d46..b569dc4 100644
index 9343d46..e3732a0 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -232,6 +232,7 @@ public class CraftWorld implements World {
}
public boolean unloadChunkRequest(int x, int z, boolean safe) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk unload!");
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk unload!"); // Spigot
if (safe && isChunkInUse(x, z)) {
return false;
}
@ -25,7 +88,7 @@ index 9343d46..b569dc4 100644
}
public boolean unloadChunk(int x, int z, boolean save, boolean safe) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk unload!");
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk unload!"); // Spigot
if (safe && isChunkInUse(x, z)) {
return false;
}
@ -33,19 +96,19 @@ index 9343d46..b569dc4 100644
}
public boolean loadChunk(int x, int z, boolean generate) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk load!");
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk load!"); // Spigot
chunkLoadCount++;
if (generate) {
// Use the default variant of loadChunk when generate == true.
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 70111e7..59e63ef 100644
index 70111e7..f026c45 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -213,6 +213,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
public void kickPlayer(String message) {
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous player kick!");
+ if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous player kick!"); // Spigot
if (getHandle().playerConnection == null) return;
getHandle().playerConnection.disconnect(message == null ? "" : message);

View File

@ -1,4 +1,4 @@
From da35e236d47b4cf1f8abc96b0956e07ff4c97703 Mon Sep 17 00:00:00 2001
From 975bd5c6ca17b8323adefe96e8ac767b63e150c0 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 10 Jan 2013 00:18:11 -0500
Subject: [PATCH] Improved Timings System
@ -279,7 +279,7 @@ index db3fc42..174546d 100644
private static Map b = new HashMap();
protected World world;
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 7862b43..dd61607 100644
index e79e82a..6cd8a99 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -13,6 +13,7 @@ import java.util.concurrent.Callable;
@ -307,7 +307,7 @@ index 7862b43..dd61607 100644
}
protected abstract IChunkProvider j();
@@ -1270,6 +1274,7 @@ public abstract class World implements IBlockAccess {
@@ -1272,6 +1276,7 @@ public abstract class World implements IBlockAccess {
this.f.clear();
this.methodProfiler.c("regular");
@ -315,7 +315,7 @@ index 7862b43..dd61607 100644
for (i = 0; i < this.entityList.size(); ++i) {
entity = (Entity) this.entityList.get(i);
@@ -1292,7 +1297,9 @@ public abstract class World implements IBlockAccess {
@@ -1294,7 +1299,9 @@ public abstract class World implements IBlockAccess {
this.methodProfiler.a("tick");
if (!entity.dead) {
try {
@ -325,7 +325,7 @@ index 7862b43..dd61607 100644
} catch (Throwable throwable1) {
crashreport = CrashReport.a(throwable1, "Ticking entity");
crashreportsystemdetails = crashreport.a("Entity being ticked");
@@ -1317,7 +1324,9 @@ public abstract class World implements IBlockAccess {
@@ -1319,7 +1326,9 @@ public abstract class World implements IBlockAccess {
this.methodProfiler.b();
}
@ -335,7 +335,7 @@ index 7862b43..dd61607 100644
this.N = true;
Iterator iterator = this.tileEntityList.iterator();
@@ -1332,8 +1341,11 @@ public abstract class World implements IBlockAccess {
@@ -1334,8 +1343,11 @@ public abstract class World implements IBlockAccess {
if (!tileentity.r() && tileentity.o() && this.isLoaded(tileentity.x, tileentity.y, tileentity.z)) {
try {
@ -347,7 +347,7 @@ index 7862b43..dd61607 100644
crashreport = CrashReport.a(throwable2, "Ticking tile entity");
crashreportsystemdetails = crashreport.a("Tile entity being ticked");
tileentity.a(crashreportsystemdetails);
@@ -1353,6 +1365,8 @@ public abstract class World implements IBlockAccess {
@@ -1355,6 +1367,8 @@ public abstract class World implements IBlockAccess {
}
}
@ -356,7 +356,7 @@ index 7862b43..dd61607 100644
this.N = false;
if (!this.b.isEmpty()) {
this.tileEntityList.removeAll(this.b);
@@ -1391,6 +1405,7 @@ public abstract class World implements IBlockAccess {
@@ -1393,6 +1407,7 @@ public abstract class World implements IBlockAccess {
this.a.clear();
}
@ -364,7 +364,7 @@ index 7862b43..dd61607 100644
this.methodProfiler.b();
this.methodProfiler.b();
}
@@ -1413,6 +1428,7 @@ public abstract class World implements IBlockAccess {
@@ -1415,6 +1430,7 @@ public abstract class World implements IBlockAccess {
byte b0 = 32;
if (!flag || this.e(i - b0, 0, j - b0, i + b0, 0, j + b0)) {
@ -372,7 +372,7 @@ index 7862b43..dd61607 100644
entity.U = entity.locX;
entity.V = entity.locY;
entity.W = entity.locZ;
@@ -1474,6 +1490,7 @@ public abstract class World implements IBlockAccess {
@@ -1476,6 +1492,7 @@ public abstract class World implements IBlockAccess {
entity.passenger = null;
}
}

View File

@ -1,4 +1,4 @@
From 8983a18841624df38cbcdbd03ff22a22268295bb Mon Sep 17 00:00:00 2001
From 0de6bba3142ff26e1570ef9e0e08e89edfef21c5 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 19 Feb 2013 17:26:20 -0500
Subject: [PATCH] Only send maps in item frames upon tracking
@ -15,7 +15,7 @@ This means cursors will not dynamically update, but the map data should refresh
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
index ae9ed52..6fa425c 100644
index 9c014ca..dd569f4 100644
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
@@ -36,6 +36,7 @@ public class EntityTrackerEntry {
@ -58,7 +58,7 @@ index ae9ed52..6fa425c 100644
}
}
}
@@ -332,6 +333,17 @@ public class EntityTrackerEntry {
@@ -333,6 +334,17 @@ public class EntityTrackerEntry {
}
}
@ -76,7 +76,7 @@ index ae9ed52..6fa425c 100644
if (this.tracker instanceof EntityHuman) {
EntityHuman entityhuman = (EntityHuman) this.tracker;
@@ -358,6 +370,7 @@ public class EntityTrackerEntry {
@@ -359,6 +371,7 @@ public class EntityTrackerEntry {
}
} else if (this.trackedPlayers.contains(entityplayer)) {
this.trackedPlayers.remove(entityplayer);

View File

@ -1,4 +1,4 @@
From 6dfba0ed91a97e5035867d2e69837c1a788e9c74 Mon Sep 17 00:00:00 2001
From 29e7a6b4fcb63e03681589270efac8a5beb2c0e8 Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Sun, 3 Feb 2013 09:20:19 +1100
Subject: [PATCH] Detect, remove and warn about null tile entities.
@ -8,10 +8,10 @@ Subject: [PATCH] Detect, remove and warn about null tile entities.
1 file changed, 7 insertions(+)
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index dd61607..09c3720 100644
index 6cd8a99..522320a 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -1332,6 +1332,13 @@ public abstract class World implements IBlockAccess {
@@ -1334,6 +1334,13 @@ public abstract class World implements IBlockAccess {
while (iterator.hasNext()) {
TileEntity tileentity = (TileEntity) iterator.next();

View File

@ -1,4 +1,4 @@
From 9b92d009fe76ea4fa60853ecc131211ff7f448f2 Mon Sep 17 00:00:00 2001
From 4861d544fcc01c69c76bdc859ac8f380d6ae3b2d Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 3 Feb 2013 05:10:21 -0500
Subject: [PATCH] Entity Activation Range
@ -89,7 +89,7 @@ index 6d54e97..924b6ed 100644
// CraftBukkit start
if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 09c3720..ca6d3f0 100644
index 522320a..de0b6c6 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -13,6 +13,7 @@ import java.util.concurrent.Callable;
@ -100,7 +100,7 @@ index 09c3720..ca6d3f0 100644
import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.craftbukkit.util.UnsafeList;
import org.bukkit.generator.ChunkGenerator;
@@ -1274,6 +1275,7 @@ public abstract class World implements IBlockAccess {
@@ -1276,6 +1277,7 @@ public abstract class World implements IBlockAccess {
this.f.clear();
this.methodProfiler.c("regular");
@ -108,7 +108,7 @@ index 09c3720..ca6d3f0 100644
timings.entityTick.startTiming(); // Spigot
for (i = 0; i < this.entityList.size(); ++i) {
entity = (Entity) this.entityList.get(i);
@@ -1434,8 +1436,12 @@ public abstract class World implements IBlockAccess {
@@ -1436,8 +1438,12 @@ public abstract class World implements IBlockAccess {
int j = MathHelper.floor(entity.locZ);
byte b0 = 32;
@ -124,7 +124,7 @@ index 09c3720..ca6d3f0 100644
entity.V = entity.locY;
entity.W = entity.locZ;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index cedaf59..3bfc669 100644
index 53be4e1..c8a662b 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -102,8 +102,14 @@ public class CraftWorld implements World {

View File

@ -1,4 +1,4 @@
From bc6b6883004dfcf9bae2842933ae9603f720412b Mon Sep 17 00:00:00 2001
From d9b1a947233048d39e786322ca49cef869a3014d Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 20 Feb 2013 11:58:47 -0500
Subject: [PATCH] Entity Tracking Ranges
@ -18,19 +18,19 @@ This has multiple benefits:
4 files changed, 53 insertions(+)
diff --git a/src/main/java/net/minecraft/server/EntityTracker.java b/src/main/java/net/minecraft/server/EntityTracker.java
index 4de1273..0bc3733 100644
index db62084..32ce51d 100644
--- a/src/main/java/net/minecraft/server/EntityTracker.java
+++ b/src/main/java/net/minecraft/server/EntityTracker.java
@@ -89,6 +89,7 @@ public class EntityTracker {
}
@@ -90,6 +90,7 @@ public class EntityTracker {
public void addEntity(Entity entity, int i, int j, boolean flag) {
if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous entity track!"); // Spigot
+ i = org.bukkit.craftbukkit.Spigot.getEntityTrackingRange(entity, i); // Spigot
if (i > this.d) {
i = this.d;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 3bfc669..804da57 100644
index c8a662b..d463e40 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -106,6 +106,12 @@ public class CraftWorld implements World {