summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit
diff options
context:
space:
mode:
authorThinkofdeath <thinkofdeath@spigotmc.org>2014-12-07 13:22:56 +0000
committerThinkofdeath <thinkofdeath@spigotmc.org>2014-12-07 13:22:56 +0000
commit44ea9d88c2f814b1b25bce683b1be9c34089eb5a (patch)
tree13dc472e0331c0d6883bee6da7e174d553378035 /src/main/java/org/bukkit
parentfb445e533764a22e5d4a3e61e888c305db07e6aa (diff)
downloadcraftbukkit-44ea9d88c2f814b1b25bce683b1be9c34089eb5a.tar
craftbukkit-44ea9d88c2f814b1b25bce683b1be9c34089eb5a.tar.gz
craftbukkit-44ea9d88c2f814b1b25bce683b1be9c34089eb5a.tar.lz
craftbukkit-44ea9d88c2f814b1b25bce683b1be9c34089eb5a.tar.xz
craftbukkit-44ea9d88c2f814b1b25bce683b1be9c34089eb5a.zip
Add CraftMetaTileEntity, fixes the previously broken tests
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java20
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java13
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java3
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java23
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaTileEntity.java117
5 files changed, 153 insertions, 23 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
index 8dd889de..9e846b60 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
@@ -83,6 +83,26 @@ public final class CraftItemFactory implements ItemFactory {
return meta instanceof CraftMetaEnchantedBook ? meta : new CraftMetaEnchantedBook(meta);
case BANNER:
return meta instanceof CraftMetaBanner ? meta : new CraftMetaBanner(meta);
+ case COMMAND:
+ case CHEST:
+ case TRAPPED_CHEST:
+ case FURNACE:
+ case HOPPER:
+ case MOB_SPAWNER:
+ case SIGN:
+ case BREWING_STAND_ITEM:
+ case JUKEBOX:
+ case FLOWER_POT_ITEM:
+ case DISPENSER:
+ case DROPPER:
+ if (meta instanceof CraftMetaTileEntity) {
+ CraftMetaTileEntity te = (CraftMetaTileEntity) meta;
+ if (te.material != material) {
+ return new CraftMetaTileEntity((CraftMetaTileEntity) null, material);
+ }
+ return meta;
+ }
+ return new CraftMetaTileEntity(meta, material);
default:
return new CraftMetaItem(meta);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index 59be14b7..c8dadb53 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -347,6 +347,19 @@ public final class CraftItemStack extends ItemStack {
return new CraftMetaEnchantedBook(item.getTag());
case BANNER:
return new CraftMetaBanner(item.getTag());
+ case COMMAND:
+ case CHEST:
+ case TRAPPED_CHEST:
+ case FURNACE:
+ case HOPPER:
+ case MOB_SPAWNER:
+ case SIGN:
+ case BREWING_STAND_ITEM:
+ case JUKEBOX:
+ case FLOWER_POT_ITEM:
+ case DISPENSER:
+ case DROPPER:
+ return new CraftMetaTileEntity(item.getTag(), CraftMagicNumbers.getMaterial(item.getItem()));
default:
return new CraftMetaItem(item.getTag());
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
index bdf74baa..994b9aaa 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
@@ -27,7 +27,6 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
CraftMetaBanner(CraftMetaItem meta) {
super(meta);
- blockEntityTag = null;
if (!(meta instanceof CraftMetaBanner)) {
return;
@@ -40,7 +39,6 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
CraftMetaBanner(NBTTagCompound tag) {
super(tag);
- blockEntityTag = null;
if (!tag.hasKey("BlockEntityTag")) {
return;
@@ -61,7 +59,6 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
CraftMetaBanner(Map<String, Object> map) {
super(map);
- blockEntityTag = null;
String baseStr = SerializableMeta.getString(map, BASE.BUKKIT, true);
if (baseStr != null) {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
index c25d0819..661fbae8 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -97,6 +97,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
static {
classMap = ImmutableMap.<Class<? extends CraftMetaItem>, String>builder()
.put(CraftMetaBanner.class, "BANNER")
+ .put(CraftMetaTileEntity.class, "TILE_ENTITY")
.put(CraftMetaBook.class, "BOOK")
.put(CraftMetaSkull.class, "SKULL")
.put(CraftMetaLeatherArmor.class, "LEATHER_ARMOR")
@@ -196,20 +197,16 @@ class CraftMetaItem implements ItemMeta, Repairable {
static final ItemMetaKey ATTRIBUTES_UUID_HIGH = new ItemMetaKey("UUIDMost");
@Specific(Specific.To.NBT)
static final ItemMetaKey ATTRIBUTES_UUID_LOW = new ItemMetaKey("UUIDLeast");
- @Specific(Specific.To.NBT)
- static final ItemMetaKey BLOCK_ENTITY_TAG = new ItemMetaKey("BlockEntityTag");
private String displayName;
private List<String> lore;
private Map<Enchantment, Integer> enchantments;
private int repairCost;
private final NBTTagList attributes;
- protected NBTTagCompound blockEntityTag;
CraftMetaItem(CraftMetaItem meta) {
if (meta == null) {
attributes = null;
- blockEntityTag = null;
return;
}
@@ -225,7 +222,6 @@ class CraftMetaItem implements ItemMeta, Repairable {
this.repairCost = meta.repairCost;
this.attributes = meta.attributes;
- this.blockEntityTag = meta.blockEntityTag;
}
CraftMetaItem(NBTTagCompound tag) {
@@ -301,12 +297,6 @@ class CraftMetaItem implements ItemMeta, Repairable {
} else {
attributes = null;
}
-
- if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) {
- blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
- } else {
- blockEntityTag = null;
- }
}
static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
@@ -343,7 +333,6 @@ class CraftMetaItem implements ItemMeta, Repairable {
}
attributes = null;
- blockEntityTag = null;
}
static Map<Enchantment, Integer> buildEnchantments(Map<String, Object> map, ItemMetaKey key) {
@@ -383,10 +372,6 @@ class CraftMetaItem implements ItemMeta, Repairable {
if (attributes != null) {
itemTag.set(ATTRIBUTES.NBT, attributes);
}
-
- if (blockEntityTag != null) {
- itemTag.set(BLOCK_ENTITY_TAG.NBT, blockEntityTag);
- }
}
static NBTTagList createStringList(List<String> list) {
@@ -438,7 +423,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
@Overridden
boolean isEmpty() {
- return !(hasDisplayName() || hasEnchants() || hasLore() || hasAttributes() || hasRepairCost() || blockEntityTag != null);
+ return !(hasDisplayName() || hasEnchants() || hasLore() || hasAttributes() || hasRepairCost());
}
public String getDisplayName() {
@@ -555,8 +540,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
&& (this.hasEnchants() ? that.hasEnchants() && this.enchantments.equals(that.enchantments) : !that.hasEnchants())
&& (this.hasLore() ? that.hasLore() && this.lore.equals(that.lore) : !that.hasLore())
&& (this.hasAttributes() ? that.hasAttributes() && this.attributes.equals(that.attributes) : !that.hasAttributes())
- && (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
- && (this.blockEntityTag != null ? that.blockEntityTag != null && this.blockEntityTag.equals(that.blockEntityTag) : that.blockEntityTag == null);
+ && (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost());
}
/**
@@ -582,7 +566,6 @@ class CraftMetaItem implements ItemMeta, Repairable {
hash = 61 * hash + (hasEnchants() ? this.enchantments.hashCode() : 0);
hash = 61 * hash + (hasAttributes() ? this.attributes.hashCode() : 0);
hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0);
- hash = 61 * hash + (blockEntityTag != null ? this.blockEntityTag.hashCode() : 0);
return hash;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaTileEntity.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaTileEntity.java
new file mode 100644
index 00000000..919e8698
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaTileEntity.java
@@ -0,0 +1,117 @@
+package org.bukkit.craftbukkit.inventory;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import net.minecraft.server.NBTTagCompound;
+import org.bukkit.Material;
+import org.bukkit.configuration.serialization.DelegateDeserialization;
+
+@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
+public class CraftMetaTileEntity extends CraftMetaItem {
+
+ @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT)
+ static final ItemMetaKey BLOCK_ENTITY_TAG = new ItemMetaKey("BlockEntityTag");
+
+ final Material material;
+ private final NBTTagCompound blockEntityTag;
+
+ CraftMetaTileEntity(CraftMetaItem meta, Material material) {
+ super(meta);
+ this.material = material;
+
+ if (!(meta instanceof CraftMetaTileEntity)) {
+ blockEntityTag = null;
+ return;
+ }
+
+ CraftMetaTileEntity te = (CraftMetaTileEntity) meta;
+ this.blockEntityTag = te.blockEntityTag;
+ }
+
+ CraftMetaTileEntity(NBTTagCompound tag, Material material) {
+ super(tag);
+ this.material = material;
+
+ if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) {
+ blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
+ } else {
+ blockEntityTag = null;
+ }
+ }
+
+ CraftMetaTileEntity(Map<String, Object> map) {
+ super(map);
+ material = Material.AIR; // TODO
+
+ blockEntityTag = null;
+ }
+
+ @Override
+ void applyToItem(NBTTagCompound tag) {
+ super.applyToItem(tag);
+
+ if (blockEntityTag != null) {
+ tag.set(BLOCK_ENTITY_TAG.NBT, blockEntityTag);
+ }
+ }
+
+ @Override
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
+ super.serialize(builder);
+ return builder;
+ }
+
+ @Override
+ int applyHash() {
+ final int original;
+ int hash = original = super.applyHash();
+ if (blockEntityTag != null) {
+ hash = 61 * hash + this.blockEntityTag.hashCode();
+ }
+ return original != hash ? CraftMetaTileEntity.class.hashCode() ^ hash : hash;
+ }
+
+ @Override
+ public boolean equalsCommon(CraftMetaItem meta) {
+ if (!super.equalsCommon(meta)) {
+ return false;
+ }
+ if (meta instanceof CraftMetaTileEntity) {
+ CraftMetaTileEntity that = (CraftMetaTileEntity) meta;
+
+ return Objects.equal(this.blockEntityTag, that.blockEntityTag);
+ }
+ return true;
+ }
+
+ @Override
+ boolean notUncommon(CraftMetaItem meta) {
+ return super.notUncommon(meta) && (meta instanceof CraftMetaTileEntity || blockEntityTag == null);
+ }
+
+ @Override
+ boolean isEmpty() {
+ return super.isEmpty() && blockEntityTag == null;
+ }
+
+ @Override
+ boolean applicableTo(Material type) {
+ switch(type){
+ case COMMAND:
+ case CHEST:
+ case TRAPPED_CHEST:
+ case FURNACE:
+ case HOPPER:
+ case MOB_SPAWNER:
+ case SIGN:
+ case BREWING_STAND_ITEM:
+ case JUKEBOX:
+ case FLOWER_POT_ITEM:
+ case DISPENSER:
+ case DROPPER:
+ return true;
+ }
+ return false;
+ }
+}