[Bleeding] Fixed item duping in certain occasions. Fixes BUKKIT-1310

By: feildmaster <admin@feildmaster.com>
This commit is contained in:
CraftBukkit/Spigot 2012-03-25 17:53:59 -05:00
parent 11ea95ba9d
commit ade2618d1d

View File

@ -528,9 +528,10 @@ public class CraftEventFactory {
((EntityPlayer) player).netServerHandler.sendPacket(packet); ((EntityPlayer) player).netServerHandler.sendPacket(packet);
} }
List<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>(); List<ItemStack> calculatedDrops = blockType.calculateDrops(world, player, x, y, z, data);
List<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>(calculatedDrops.size());
if (!creative && player.b(blockType)) { if (!creative && player.b(blockType)) {
for (ItemStack stack : blockType.calculateDrops(world, player, x, y, z, data)) { for (ItemStack stack : calculatedDrops) {
drops.add(new CraftItemStack(stack)); drops.add(new CraftItemStack(stack));
} }
} }
@ -539,17 +540,17 @@ public class CraftEventFactory {
world.getServer().getPluginManager().callEvent(event); world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
blockType.setDrops(new ArrayList<ItemStack>()); blockType.dropList.clear();
// Let the client know the block still exists // Let the client know the block still exists
((EntityPlayer) player).netServerHandler.sendPacket(new Packet53BlockChange(x, y, z, world)); ((EntityPlayer) player).netServerHandler.sendPacket(new Packet53BlockChange(x, y, z, world));
return true; return true;
} }
ArrayList<ItemStack> toDrop = new ArrayList<ItemStack>(); ArrayList<ItemStack> toDrop = new ArrayList<ItemStack>(drops.size());
for (org.bukkit.inventory.ItemStack stack : drops) { for (org.bukkit.inventory.ItemStack stack : drops) {
toDrop.add(CraftItemStack.createNMSItemStack(stack)); toDrop.add(CraftItemStack.createNMSItemStack(stack));
} }
blockType.setDrops(toDrop); blockType.dropList = toDrop;
return false; // Event not cancelled return false; // Event not cancelled
} }