From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Fri, 5 Jul 2019 18:21:00 -0500
Subject: [PATCH] PlayerSetSpawnerTypeWithEggEvent


diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index 96b881fcb4c3871b2fc00080afc19900b28633f5..0811cc816ce8d72a35643b7a9c1d8b23cbfdab00 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -286,6 +286,16 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
         return (EntityType) Registry.register((Registry) Registry.ENTITY_TYPE, id, (Object) type.build(id));
     }
 
+    // Purpur start
+    public static EntityType<?> getFromBukkitType(org.bukkit.entity.EntityType bukkitType) {
+        return getFromKey(new ResourceLocation(bukkitType.getKey().toString()));
+    }
+
+    public static EntityType<?> getFromKey(ResourceLocation location) {
+        return Registry.ENTITY_TYPE.get(location);
+    }
+    // Purpur end
+
     public static ResourceLocation getKey(EntityType<?> type) {
         return Registry.ENTITY_TYPE.getKey(type);
     }
@@ -452,6 +462,16 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
         return this.category;
     }
 
+    // Purpur start
+    public String getName() {
+        return Registry.ENTITY_TYPE.getKey(this).getPath();
+    }
+
+    public String getTranslatedName() {
+        return getDescription().getString();
+    }
+    // Purpur end
+
     public String getDescriptionId() {
         if (this.descriptionId == null) {
             this.descriptionId = Util.makeDescriptionId("entity", Registry.ENTITY_TYPE.getKey(this));
diff --git a/src/main/java/net/minecraft/world/item/SpawnEggItem.java b/src/main/java/net/minecraft/world/item/SpawnEggItem.java
index 6afba641943717cc9c75420d9f3af1048543a17e..45e964a15a8afb85dd91638e800beaf0a6efdde9 100644
--- a/src/main/java/net/minecraft/world/item/SpawnEggItem.java
+++ b/src/main/java/net/minecraft/world/item/SpawnEggItem.java
@@ -68,6 +68,15 @@ public class SpawnEggItem extends Item {
                     BaseSpawner mobspawnerabstract = ((SpawnerBlockEntity) tileentity).getSpawner();
                     EntityType<?> entitytypes = this.getType(itemstack.getTag());
 
+                    // Purpur start
+                    org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+                    net.pl3x.purpur.event.PlayerSetSpawnerTypeWithEggEvent event = new  net.pl3x.purpur.event.PlayerSetSpawnerTypeWithEggEvent((org.bukkit.entity.Player) context.getPlayer().getBukkitEntity(), bukkitBlock, (org.bukkit.block.CreatureSpawner) bukkitBlock.getState(), org.bukkit.entity.EntityType.fromName(entitytypes.getName()));
+                    if (!event.callEvent()) {
+                        return InteractionResult.FAIL;
+                    }
+                    entitytypes = EntityType.getFromBukkitType(event.getEntityType());
+                    // Purpur end
+
                     mobspawnerabstract.setEntityId(entitytypes);
                     tileentity.setChanged();
                     world.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3);
