summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvilSeph <evilseph@gmail.com>2012-01-20 02:26:26 -0500
committerEvilSeph <evilseph@gmail.com>2012-01-20 05:40:10 -0500
commit76d7a1ce1d88ba8546e8f4da3e8fcb9104d03b7d (patch)
tree02f83891708c92e1127a39dd93228d7188556c74
parent4b0f819af21dc5196f704b595e1ae3dd47ad2372 (diff)
downloadcraftbukkit-76d7a1ce1d88ba8546e8f4da3e8fcb9104d03b7d.tar
craftbukkit-76d7a1ce1d88ba8546e8f4da3e8fcb9104d03b7d.tar.gz
craftbukkit-76d7a1ce1d88ba8546e8f4da3e8fcb9104d03b7d.tar.lz
craftbukkit-76d7a1ce1d88ba8546e8f4da3e8fcb9104d03b7d.tar.xz
craftbukkit-76d7a1ce1d88ba8546e8f4da3e8fcb9104d03b7d.zip
Properly handle null and air items. Fixes BUKKIT-435 and BUKKIT-550
We'll probably want to implement an ItemStack.EMPTY and return that instead of NULL in the near future.
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftWorld.java4
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java6
2 files changed, 7 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index dd5388e4..969e25e9 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -3,6 +3,8 @@ package org.bukkit.craftbukkit;
import com.google.common.collect.MapMaker;
import java.io.File;
import java.util.Set;
+import org.apache.commons.lang.Validate;
+
import org.bukkit.craftbukkit.entity.*;
import org.bukkit.entity.*;
import org.bukkit.entity.Entity;
@@ -299,6 +301,8 @@ public class CraftWorld implements World {
}
public org.bukkit.entity.Item dropItem(Location loc, ItemStack item) {
+ Validate.notNull(item, "Cannot drop a Null item.");
+ Validate.isTrue(item.getTypeId() != 0, "Cannot drop AIR.");
CraftItemStack clone = new CraftItemStack(item);
EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), clone.getHandle());
entity.pickupDelay = 10;
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
index b8f045d0..b5391b35 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
@@ -27,7 +27,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
}
public ItemStack getItem(int index) {
- return new CraftItemStack(getInventory().getItem(index));
+ return getInventory().getItem(index).id == 0 ? null : new CraftItemStack(getInventory().getItem(index));
}
public ItemStack[] getContents() {
@@ -59,7 +59,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
}
public void setItem(int index, ItemStack item) {
- getInventory().setItem(index, (item == null ? null : CraftItemStack.createNMSItemStack(item)));
+ getInventory().setItem(index, ((item == null || item.getTypeId() == 0) ? null : CraftItemStack.createNMSItemStack(item)));
}
public boolean contains(int materialId) {
@@ -170,7 +170,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
ItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) {
if (inventory[i] == null) continue;
-
+
boolean equals = false;
if (withAmount) {