From 25050e38eb02c93b32fc9b1eaf2de82992a7ff3a Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Sun, 15 Jan 2012 09:45:16 +0000 Subject: [PATCH] Disallow people spawning invalid entities using monster eggs. Thanks to md-5 for the PR. --- src/main/java/net/minecraft/server/ItemMonsterEgg.java | 6 +++--- src/main/java/net/minecraft/server/NetServerHandler.java | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minecraft/server/ItemMonsterEgg.java b/src/main/java/net/minecraft/server/ItemMonsterEgg.java index c4bd8644ca..58bf9b7bee 100644 --- a/src/main/java/net/minecraft/server/ItemMonsterEgg.java +++ b/src/main/java/net/minecraft/server/ItemMonsterEgg.java @@ -9,7 +9,7 @@ public class ItemMonsterEgg extends Item { } public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) { - if (world.isStatic) { + if (world.isStatic || itemstack.getData() == 48 || itemstack.getData() == 49 || itemstack.getData() == 63) { // CraftBukkit return true; } else { i += Facing.b[l]; @@ -17,7 +17,7 @@ public class ItemMonsterEgg extends Item { k += Facing.d[l]; Entity entity = EntityTypes.a(itemstack.getData(), world); - if (entity != null) { + if (entity != null && entity instanceof EntityLiving) { // CraftBukkit if (!entityhuman.abilities.canInstantlyBuild) { --itemstack.count; } @@ -29,4 +29,4 @@ public class ItemMonsterEgg extends Item { return true; } } -} +} \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index 24a39212d5..a03b96776e 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -7,6 +7,8 @@ import java.util.logging.Level; import java.util.logging.Logger; // CraftBukkit start +import java.util.Arrays; +import java.util.HashSet; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.ChunkCompressionThread; import org.bukkit.Location; @@ -89,6 +91,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener { public CraftPlayer getPlayer() { return (this.player == null) ? null : (CraftPlayer) this.player.getBukkitEntity(); } + private final static HashSet invalidItems = new HashSet(Arrays.asList(8, 9, 10, 11, 26, 34, 36, 51, 52, 55, 59, 60, 63, 64, 68, 71, 75, 78, 83, 90, 92, 93, 94, 95)); // CraftBukkit end public void a() { @@ -1012,7 +1015,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener { boolean flag = packet107setcreativeslot.a < 0; ItemStack itemstack = packet107setcreativeslot.b; boolean flag1 = packet107setcreativeslot.a >= 36 && packet107setcreativeslot.a < 36 + PlayerInventory.getHotbarSize(); - boolean flag2 = itemstack == null || itemstack.id < Item.byId.length && itemstack.id >= 0 && Item.byId[itemstack.id] != null; + boolean flag2 = itemstack == null || itemstack.id < Item.byId.length && itemstack.id >= 0 && Item.byId[itemstack.id] != null && !invalidItems.contains(itemstack.id); // CraftBukkit boolean flag3 = itemstack == null || itemstack.getData() >= 0 && itemstack.getData() >= 0 && itemstack.count <= 64 && itemstack.count > 0; if (flag1 && flag2 && flag3) { @@ -1142,4 +1145,4 @@ public class NetServerHandler extends NetHandler implements ICommandListener { } } // CraftBukkit end -} +} \ No newline at end of file