Fix CanDestroy CanPlaceOn on untagged items
This commit is contained in:
parent
025a590fbd
commit
24fed5a3a5
|
@ -1,4 +1,4 @@
|
|||
From e6dbfd0102cfdbd27f6ab61825b79a82954d0409 Mon Sep 17 00:00:00 2001
|
||||
From 9c6760e875a439ae7ba701e267a32fe52a0e547e Mon Sep 17 00:00:00 2001
|
||||
From: Mark Vainomaa <mikroskeem@mikroskeem.eu>
|
||||
Date: Wed, 12 Sep 2018 18:53:55 +0300
|
||||
Subject: [PATCH] Implement an API for CanPlaceOn and CanDestroy NBT values
|
||||
|
@ -32,7 +32,7 @@ index 8e8390282..f52936581 100644
|
|||
this.s = this::l;
|
||||
if (this.i.canRead() && this.i.peek() == '#') {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
index eaf4cd11c..03644365c 100644
|
||||
index eaf4cd11c..dc417fb9d 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
@@ -81,6 +81,12 @@ import javax.annotation.Nullable;
|
||||
|
@ -64,8 +64,8 @@ index eaf4cd11c..03644365c 100644
|
|||
private boolean unbreakable;
|
||||
private int damage;
|
||||
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
||||
+ private Set<Namespaced> placeableKeys;
|
||||
+ private Set<Namespaced> destroyableKeys;
|
||||
+ private Set<Namespaced> placeableKeys = Sets.newHashSet();
|
||||
+ private Set<Namespaced> destroyableKeys = Sets.newHashSet();
|
||||
+ // Paper end
|
||||
|
||||
private static final Set<String> HANDLED_TAGS = Sets.newHashSet();
|
||||
|
@ -86,7 +86,7 @@ index eaf4cd11c..03644365c 100644
|
|||
this.unhandledTags.putAll(meta.unhandledTags);
|
||||
this.publicItemTagContainer.putAll(meta.publicItemTagContainer.getRaw());
|
||||
|
||||
@@ -361,6 +384,33 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -361,6 +384,32 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
publicItemTagContainer.put(key, compound.get(key));
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,6 @@ index eaf4cd11c..03644365c 100644
|
|||
+ }
|
||||
+
|
||||
+ if (tag.hasKey(CAN_PLACE_ON.NBT)) {
|
||||
+ this.placeableKeys = Sets.newHashSet();
|
||||
+ NBTTagList list = tag.getList(CAN_PLACE_ON.NBT, CraftMagicNumbers.NBT.TAG_STRING);
|
||||
+ for (int i = 0; i < list.size(); i++) {
|
||||
+ Namespaced namespaced = this.deserializeNamespaced(list.getString(i));
|
||||
|
@ -120,14 +119,13 @@ index eaf4cd11c..03644365c 100644
|
|||
|
||||
Set<String> keys = tag.getKeys();
|
||||
for (String key : keys) {
|
||||
@@ -488,6 +538,36 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -488,6 +537,35 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
setDamage(damage);
|
||||
}
|
||||
|
||||
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
||||
+ Iterable<?> canPlaceOnSerialized = SerializableMeta.getObject(Iterable.class, map, CAN_PLACE_ON.BUKKIT, true);
|
||||
+ if (canPlaceOnSerialized != null) {
|
||||
+ this.placeableKeys = Sets.newHashSet();
|
||||
+ for (Object canPlaceOnElement : canPlaceOnSerialized) {
|
||||
+ String canPlaceOnRaw = (String) canPlaceOnElement;
|
||||
+ Namespaced value = this.deserializeNamespaced(canPlaceOnRaw);
|
||||
|
@ -157,7 +155,7 @@ index eaf4cd11c..03644365c 100644
|
|||
String internal = SerializableMeta.getString(map, "internal", true);
|
||||
if (internal != null) {
|
||||
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal));
|
||||
@@ -608,6 +688,23 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -608,6 +686,23 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
if (hasDamage()) {
|
||||
itemTag.setInt(DAMAGE.NBT, damage);
|
||||
}
|
||||
|
@ -181,7 +179,7 @@ index eaf4cd11c..03644365c 100644
|
|||
|
||||
for (Map.Entry<String, NBTBase> e : unhandledTags.entrySet()) {
|
||||
itemTag.set(e.getKey(), e.getValue());
|
||||
@@ -706,7 +803,8 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -706,7 +801,8 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
|
||||
@Overridden
|
||||
boolean isEmpty() {
|
||||
|
@ -191,7 +189,7 @@ index eaf4cd11c..03644365c 100644
|
|||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
@@ -1048,7 +1146,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -1048,7 +1144,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
&& (this.publicItemTagContainer.equals(that.publicItemTagContainer))
|
||||
&& (this.hideFlag == that.hideFlag)
|
||||
&& (this.isUnbreakable() == that.isUnbreakable())
|
||||
|
@ -204,7 +202,7 @@ index eaf4cd11c..03644365c 100644
|
|||
}
|
||||
|
||||
/**
|
||||
@@ -1080,6 +1182,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -1080,6 +1180,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
hash = 61 * hash + (isUnbreakable() ? 1231 : 1237);
|
||||
hash = 61 * hash + (hasDamage() ? this.damage : 0);
|
||||
hash = 61 * hash + (hasAttributeModifiers() ? this.attributeModifiers.hashCode() : 0);
|
||||
|
@ -215,7 +213,7 @@ index eaf4cd11c..03644365c 100644
|
|||
return hash;
|
||||
}
|
||||
|
||||
@@ -1100,6 +1206,15 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -1100,6 +1204,15 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
clone.hideFlag = this.hideFlag;
|
||||
clone.unbreakable = this.unbreakable;
|
||||
clone.damage = this.damage;
|
||||
|
@ -231,7 +229,7 @@ index eaf4cd11c..03644365c 100644
|
|||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new Error(e);
|
||||
@@ -1149,6 +1264,24 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -1149,6 +1262,24 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
builder.put(DAMAGE.BUKKIT, damage);
|
||||
}
|
||||
|
||||
|
@ -256,7 +254,7 @@ index eaf4cd11c..03644365c 100644
|
|||
final Map<String, NBTBase> internalTags = new HashMap<String, NBTBase>(unhandledTags);
|
||||
serializeInternal(internalTags);
|
||||
if (!internalTags.isEmpty()) {
|
||||
@@ -1298,7 +1431,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -1298,7 +1429,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
CraftMetaArmorStand.NO_BASE_PLATE.NBT,
|
||||
CraftMetaArmorStand.SHOW_ARMS.NBT,
|
||||
CraftMetaArmorStand.SMALL.NBT,
|
||||
|
@ -267,7 +265,7 @@ index eaf4cd11c..03644365c 100644
|
|||
// Paper end
|
||||
));
|
||||
}
|
||||
@@ -1345,4 +1480,147 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
@@ -1345,4 +1478,147 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
return spigot;
|
||||
}
|
||||
// Spigot end
|
||||
|
@ -275,7 +273,7 @@ index eaf4cd11c..03644365c 100644
|
|||
+ @Override
|
||||
+ @SuppressWarnings("deprecation")
|
||||
+ public Set<Material> getCanDestroy() {
|
||||
+ return this.destroyableKeys == null ? Collections.emptySet() : legacyGetMatsFromKeys(this.destroyableKeys);
|
||||
+ return !hasDestroyableKeys() ? Collections.emptySet() : legacyGetMatsFromKeys(this.destroyableKeys);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
@ -288,7 +286,7 @@ index eaf4cd11c..03644365c 100644
|
|||
+ @Override
|
||||
+ @SuppressWarnings("deprecation")
|
||||
+ public Set<Material> getCanPlaceOn() {
|
||||
+ return this.placeableKeys == null ? Collections.emptySet() : legacyGetMatsFromKeys(this.placeableKeys);
|
||||
+ return !hasPlaceableKeys() ? Collections.emptySet() : legacyGetMatsFromKeys(this.placeableKeys);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
@ -300,7 +298,7 @@ index eaf4cd11c..03644365c 100644
|
|||
+
|
||||
+ @Override
|
||||
+ public Set<Namespaced> getDestroyableKeys() {
|
||||
+ return this.destroyableKeys == null ? Collections.emptySet() : Sets.newHashSet(this.destroyableKeys);
|
||||
+ return !hasDestroyableKeys() ? Collections.emptySet() : Sets.newHashSet(this.destroyableKeys);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
@ -313,7 +311,7 @@ index eaf4cd11c..03644365c 100644
|
|||
+
|
||||
+ @Override
|
||||
+ public Set<Namespaced> getPlaceableKeys() {
|
||||
+ return this.placeableKeys == null ? Collections.emptySet() : Sets.newHashSet(this.placeableKeys);
|
||||
+ return !hasPlaceableKeys() ? Collections.emptySet() : Sets.newHashSet(this.placeableKeys);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
@ -416,5 +414,5 @@ index eaf4cd11c..03644365c 100644
|
|||
+ // Paper end
|
||||
}
|
||||
--
|
||||
2.20.1
|
||||
2.21.0
|
||||
|
||||
|
|
Loading…
Reference in New Issue