PreCreatureSpawnEvent - Closes #917

Adds an event to fire before an Entity is created, so that plugins that need to cancel
CreatureSpawnEvent can do so from this event instead.

Cancelling CreatureSpawnEvent rapidly causes a lot of garbage collection and CPU waste
as it's done after the Entity object has been fully created.

Mob Limiting plugins and blanket "ban this type of monster" plugins should use this event
instead and save a lot of server resources.

See: https://github.com/PaperMC/Paper/issues/917
This commit is contained in:
Aikar
2018-01-14 17:02:38 -05:00
parent 241f7f59d8
commit 2e05bc73b3
4 changed files with 239 additions and 3 deletions

View File

@@ -51,9 +51,33 @@ index 1f2fe87b6..2cb462b8e 100644
protected DataBits b;
protected DataPalette c;
private int e;
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
index ba461ad48..66c270493 100644
--- a/src/main/java/net/minecraft/server/EntityTypes.java
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
@@ -0,0 +0,0 @@ public class EntityTypes {
a("zombie_villager", 5651507, 7969893);
EntityTypes.d.add(EntityTypes.a);
}
+ // Paper start
+ public static Map<Class<? extends Entity>, MinecraftKey> clsToKeyMap = new java.util.HashMap<>();
+ public static Map<Class<? extends Entity>, org.bukkit.entity.EntityType> clsToTypeMap = new java.util.HashMap<>();
+ // Paper end
private static void a(int i, String s, Class<? extends Entity> oclass, String s1) {
try {
@@ -0,0 +0,0 @@ public class EntityTypes {
EntityTypes.b.a(i, minecraftkey, oclass);
EntityTypes.d.add(minecraftkey);
+ clsToKeyMap.put(oclass, minecraftkey); // Paper
+ clsToTypeMap.put(oclass, org.bukkit.entity.EntityType.fromName(s)); // Paper
while (EntityTypes.g.size() <= i) {
EntityTypes.g.add(null); // Paper - Decompile fix
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
new file mode 100644
index 000000000..1159eea1a
index 000000000..a4b0901cf
--- /dev/null
+++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -0,0 +0,0 @@
@@ -176,6 +200,18 @@ index 000000000..1159eea1a
+ /**
+ * Converts a NMS World/BlockPosition to Bukkit Location
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @return
+ */
+ public static Location toLocation(World world, double x, double y, double z) {
+ return new Location(world.getWorld(), x, y, z);
+ }
+
+ /**
+ * Converts a NMS World/BlockPosition to Bukkit Location
+ * @param world
+ * @param pos
+ * @return
+ */