diff options
Diffstat (limited to 'src/main')
5 files changed, 16 insertions, 11 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index b84b376a..3d3ea631 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -197,7 +197,7 @@ public class CraftEventFactory { public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, EnumHand hand) { return callPlayerInteractEvent(who, action, position, direction, itemstack, false, hand); } - + public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) { Player player = (who == null) ? null : (Player) who.getBukkitEntity(); CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack); @@ -220,6 +220,10 @@ public class CraftEventFactory { } BlockFace blockFace = CraftBlock.notchToBlockFace(direction); + if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) { + itemInHand = null; + } + PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND)); if (cancelledBlock) { event.setUseInteractedBlock(Event.Result.DENY); @@ -992,7 +996,7 @@ public class CraftEventFactory { } public static PrepareAnvilEvent callPrepareAnvilEvent(InventoryView view, ItemStack item) { - PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item)); + PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone()); event.getView().getPlayer().getServer().getPluginManager().callEvent(event); event.getInventory().setItem(2, event.getResult()); return event; @@ -1012,7 +1016,7 @@ public class CraftEventFactory { public static EntityBreedEvent callEntityBreedEvent(EntityLiving child, EntityLiving mother, EntityLiving father, EntityLiving breeder, ItemStack bredWith, int experience) { org.bukkit.entity.LivingEntity breederEntity = (LivingEntity)(breeder == null ? null : breeder.getBukkitEntity()); - CraftItemStack bredWithStack = CraftItemStack.asCraftMirror(bredWith); + CraftItemStack bredWithStack = bredWith == null ? null : CraftItemStack.asCraftMirror(bredWith).clone(); EntityBreedEvent event = new EntityBreedEvent((LivingEntity) child.getBukkitEntity(), (LivingEntity) mother.getBukkitEntity(), (LivingEntity) father.getBukkitEntity(), breederEntity, bredWithStack, experience); child.world.getServer().getPluginManager().callEvent(event); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index bedc0854..0033246b 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -46,7 +46,7 @@ public class CraftInventory implements Inventory { public ItemStack getItem(int index) { net.minecraft.server.ItemStack item = getInventory().getItem(index); - return CraftItemStack.asCraftMirror(item); + return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); } @Override @@ -65,7 +65,7 @@ public class CraftInventory implements Inventory { int size = Math.min(items.length, mcItems.size()); for (int i = 0; i < size; i++) { - items[i] = CraftItemStack.asCraftMirror(mcItems.get(i)); + items[i] = (mcItems.get(i).isEmpty()) ? null : CraftItemStack.asCraftMirror(mcItems.get(i)); } return items; } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java index 997eaf66..6b415f23 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java @@ -28,10 +28,10 @@ public class CraftInventoryAnvil extends CraftInventory implements AnvilInventor public ItemStack getItem(int slot) { if (slot < getIngredientsInventory().getSize()) { net.minecraft.server.ItemStack item = getIngredientsInventory().getItem(slot); - return CraftItemStack.asCraftMirror(item); + return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); } else { net.minecraft.server.ItemStack item = getResultInventory().getItem(slot - getIngredientsInventory().getSize()); - return CraftItemStack.asCraftMirror(item); + return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCrafting.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCrafting.java index f4e5ddf4..2ae768fa 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCrafting.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCrafting.java @@ -70,10 +70,10 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn public CraftItemStack getItem(int index) { if (index < getResultInventory().getSize()) { net.minecraft.server.ItemStack item = getResultInventory().getItem(index); - return CraftItemStack.asCraftMirror(item); + return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); } else { net.minecraft.server.ItemStack item = getMatrixInventory().getItem(index - getResultInventory().getSize()); - return CraftItemStack.asCraftMirror(item); + return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); } } @@ -99,7 +99,8 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn public ItemStack getResult() { net.minecraft.server.ItemStack item = getResultInventory().getItem(0); - return CraftItemStack.asCraftMirror(item); + if (!item.isEmpty()) return CraftItemStack.asCraftMirror(item); + return null; } public void setMatrix(ItemStack[] contents) { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index 178a626d..0ce23f0f 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -68,7 +68,7 @@ public final class CraftItemStack extends ItemStack { } public static CraftItemStack asCraftMirror(net.minecraft.server.ItemStack original) { - return (original.isEmpty()) ? null : new CraftItemStack(original); + return new CraftItemStack(original); } public static CraftItemStack asCraftCopy(ItemStack original) { |