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/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
index 93b5a6471cde31739d2bd5f2a9fc0e0d974d0eb0..36f572990a0c08f21df6f4dc40c5878b669ca00c 100644
--- a/src/main/java/net/minecraft/server/EntityTypes.java
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
@@ -143,6 +143,16 @@ public class EntityTypes<T extends Entity> {
         return (EntityTypes) IRegistry.a((IRegistry) IRegistry.ENTITY_TYPE, s, (Object) entitytypes_builder.a(s));
     }
 
+    // Purpur start
+    public static EntityTypes getFromBukkitType(org.bukkit.entity.EntityType bukkitType) {
+        return getFromKey(new MinecraftKey(bukkitType.getKey().toString()));
+    }
+
+    public static EntityTypes getFromKey(MinecraftKey key) {
+        return IRegistry.ENTITY_TYPE.get(key);
+    }
+    // Purpur end
+
     public static MinecraftKey getName(EntityTypes<?> entitytypes) {
         return IRegistry.ENTITY_TYPE.getKey(entitytypes);
     }
@@ -301,6 +311,16 @@ public class EntityTypes<T extends Entity> {
         return this.bg;
     }
 
+    // Purpur start
+    public String getName() {
+        return IRegistry.ENTITY_TYPE.getKey(this).getKey();
+    }
+
+    public String getTranslatedName() {
+        return getNameComponent().getString();
+    }
+    // Purpur end
+
     public String getDescriptionId() { return f(); } // Paper - OBFHELPER
     public String f() {
         if (this.bo == null) {
@@ -310,6 +330,7 @@ public class EntityTypes<T extends Entity> {
         return this.bo;
     }
 
+    public IChatBaseComponent getNameComponent() { return g(); } // Purpur - OBFHELPER
     public IChatBaseComponent g() {
         if (this.bp == null) {
             this.bp = new ChatMessage(this.f());
diff --git a/src/main/java/net/minecraft/server/ItemMonsterEgg.java b/src/main/java/net/minecraft/server/ItemMonsterEgg.java
index eeac4aeaf21b43647aa643ec55a1ae842a7ac197..d66acf90d0b1bcd5c6481d2a2ee753c7693995b0 100644
--- a/src/main/java/net/minecraft/server/ItemMonsterEgg.java
+++ b/src/main/java/net/minecraft/server/ItemMonsterEgg.java
@@ -7,6 +7,13 @@ import java.util.Objects;
 import java.util.Optional;
 import javax.annotation.Nullable;
 
+// Purpur start
+import net.pl3x.purpur.event.PlayerSetSpawnerTypeWithEggEvent;
+import org.bukkit.block.CreatureSpawner;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+// Purpur end
+
 public class ItemMonsterEgg extends Item {
 
     public static final Map<EntityTypes<?>, ItemMonsterEgg> a = Maps.newIdentityHashMap(); // Purpur - private -> public
@@ -41,6 +48,15 @@ public class ItemMonsterEgg extends Item {
                     MobSpawnerAbstract mobspawnerabstract = ((TileEntityMobSpawner) tileentity).getSpawner();
                     EntityTypes<?> entitytypes = this.a(itemstack.getTag());
 
+                    // Purpur start
+                    org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+                    PlayerSetSpawnerTypeWithEggEvent event = new PlayerSetSpawnerTypeWithEggEvent((Player) itemactioncontext.getEntity().getBukkitEntity(), bukkitBlock, (CreatureSpawner) bukkitBlock.getState(), EntityType.fromName(entitytypes.getName()));
+                    if (!event.callEvent()) {
+                        return EnumInteractionResult.FAIL;
+                    }
+                    entitytypes = EntityTypes.getFromBukkitType(event.getEntityType());
+                    // Purpur end
+
                     mobspawnerabstract.setMobName(entitytypes);
                     tileentity.update();
                     world.notify(blockposition, iblockdata, iblockdata, 3);
