geforkt von Mirrors/Paper
SPIGOT-5907: Item Frame NBT data disappears
Dieser Commit ist enthalten in:
Ursprung
5a6c529833
Commit
a13b8cfc71
@ -259,6 +259,8 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
return meta instanceof CraftMetaCrossbow ? meta : new CraftMetaCrossbow(meta);
|
||||
case SUSPICIOUS_STEW:
|
||||
return meta instanceof CraftMetaSuspiciousStew ? meta : new CraftMetaSuspiciousStew(meta);
|
||||
case ITEM_FRAME:
|
||||
return meta instanceof CraftMetaEntityTag ? meta : new CraftMetaEntityTag(meta);
|
||||
default:
|
||||
return new CraftMetaItem(meta);
|
||||
}
|
||||
|
@ -528,6 +528,8 @@ public final class CraftItemStack extends ItemStack {
|
||||
return new CraftMetaCrossbow(item.getTag());
|
||||
case SUSPICIOUS_STEW:
|
||||
return new CraftMetaSuspiciousStew(item.getTag());
|
||||
case ITEM_FRAME:
|
||||
return new CraftMetaEntityTag(item.getTag());
|
||||
default:
|
||||
return new CraftMetaItem(item.getTag());
|
||||
}
|
||||
|
123
src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java
Normale Datei
123
src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java
Normale Datei
@ -0,0 +1,123 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import java.util.Map;
|
||||
import net.minecraft.server.NBTBase;
|
||||
import net.minecraft.server.NBTTagCompound;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||
|
||||
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
|
||||
public class CraftMetaEntityTag extends CraftMetaItem {
|
||||
|
||||
static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag");
|
||||
NBTTagCompound entityTag;
|
||||
|
||||
CraftMetaEntityTag(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
CraftMetaEntityTag(NBTTagCompound tag) {
|
||||
super(tag);
|
||||
|
||||
if (tag.hasKey(ENTITY_TAG.NBT)) {
|
||||
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||
}
|
||||
}
|
||||
|
||||
CraftMetaEntityTag(Map<String, Object> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
void deserializeInternal(NBTTagCompound tag, Object context) {
|
||||
super.deserializeInternal(tag, context);
|
||||
|
||||
if (tag.hasKey(ENTITY_TAG.NBT)) {
|
||||
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void serializeInternal(Map<String, NBTBase> internalTags) {
|
||||
if (entityTag != null && !entityTag.isEmpty()) {
|
||||
internalTags.put(ENTITY_TAG.NBT, entityTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void applyToItem(NBTTagCompound tag) {
|
||||
super.applyToItem(tag);
|
||||
|
||||
if (entityTag != null) {
|
||||
tag.set(ENTITY_TAG.NBT, entityTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean applicableTo(Material type) {
|
||||
switch (type) {
|
||||
case ITEM_FRAME:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isEmpty() {
|
||||
return super.isEmpty() && isEntityTagEmpty();
|
||||
}
|
||||
|
||||
boolean isEntityTagEmpty() {
|
||||
return !(entityTag != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean equalsCommon(CraftMetaItem meta) {
|
||||
if (!super.equalsCommon(meta)) {
|
||||
return false;
|
||||
}
|
||||
if (meta instanceof CraftMetaEntityTag) {
|
||||
CraftMetaEntityTag that = (CraftMetaEntityTag) meta;
|
||||
|
||||
return entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : entityTag == null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean notUncommon(CraftMetaItem meta) {
|
||||
return super.notUncommon(meta) && (meta instanceof CraftMetaEntityTag || isEntityTagEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
int applyHash() {
|
||||
final int original;
|
||||
int hash = original = super.applyHash();
|
||||
|
||||
if (entityTag != null) {
|
||||
hash = 73 * hash + entityTag.hashCode();
|
||||
}
|
||||
|
||||
return original != hash ? CraftMetaEntityTag.class.hashCode() ^ hash : hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
Builder<String, Object> serialize(Builder<String, Object> builder) {
|
||||
super.serialize(builder);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftMetaEntityTag clone() {
|
||||
CraftMetaEntityTag clone = (CraftMetaEntityTag) super.clone();
|
||||
|
||||
if (entityTag != null) {
|
||||
clone.entityTag = entityTag.clone();
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
@ -155,6 +155,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
.put(CraftMetaTropicalFishBucket.class, "TROPICAL_FISH_BUCKET")
|
||||
.put(CraftMetaCrossbow.class, "CROSSBOW")
|
||||
.put(CraftMetaSuspiciousStew.class, "SUSPICIOUS_STEW")
|
||||
.put(CraftMetaEntityTag.class, "ENTITY_TAG")
|
||||
.put(CraftMetaItem.class, "UNSPECIFIC")
|
||||
.build();
|
||||
|
||||
|
@ -324,6 +324,15 @@ public class ItemMetaTest extends AbstractTestingBase {
|
||||
cleanStack.setItemMeta(meta);
|
||||
return cleanStack;
|
||||
}
|
||||
},
|
||||
new StackProvider(Material.ITEM_FRAME) {
|
||||
@Override ItemStack operate(ItemStack cleanStack) {
|
||||
final CraftMetaEntityTag meta = ((CraftMetaEntityTag) cleanStack.getItemMeta());
|
||||
meta.entityTag = new NBTTagCompound();
|
||||
meta.entityTag.setBoolean("Invisible", true);
|
||||
cleanStack.setItemMeta(meta);
|
||||
return cleanStack;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren