2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-09-23 05:30:54 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/commands/arguments/blocks/ArgumentBlock.java b/src/main/java/net/minecraft/commands/arguments/blocks/ArgumentBlock.java
|
|
|
|
index 7e53d8b787c42f8592140f7de8974bc63e5149b2..d72b800e5f03422d0b2518980b1955ec7d2b08e8 100644
|
|
|
|
--- a/src/main/java/net/minecraft/commands/arguments/blocks/ArgumentBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/blocks/ArgumentBlock.java
|
|
|
|
@@ -57,7 +57,7 @@ public class ArgumentBlock {
|
2018-11-11 09:30:57 +01:00
|
|
|
private final boolean j;
|
2018-12-21 17:09:17 +01:00
|
|
|
private final Map<IBlockState<?>, Comparable<?>> k = Maps.newLinkedHashMap(); // CraftBukkit - stable
|
2018-11-11 09:30:57 +01:00
|
|
|
private final Map<String, String> l = Maps.newHashMap();
|
|
|
|
- private MinecraftKey m = new MinecraftKey("");
|
2020-08-02 07:39:36 +02:00
|
|
|
+ private MinecraftKey m = new MinecraftKey(""); public final MinecraftKey getBlockKey() { return this.m; } // Paper - OBFHELPER
|
2018-11-11 09:30:57 +01:00
|
|
|
private BlockStateList<Block, IBlockData> n;
|
|
|
|
private IBlockData o;
|
|
|
|
@Nullable
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -86,11 +86,13 @@ public class ArgumentBlock {
|
2018-11-11 09:30:57 +01:00
|
|
|
return this.p;
|
|
|
|
}
|
|
|
|
|
2020-08-02 07:39:36 +02:00
|
|
|
+ public final @Nullable MinecraftKey getTagKey() { return d(); } // Paper - OBFHELPER
|
2018-11-11 09:30:57 +01:00
|
|
|
@Nullable
|
|
|
|
public MinecraftKey d() {
|
|
|
|
return this.q;
|
|
|
|
}
|
|
|
|
|
2020-08-02 07:39:36 +02:00
|
|
|
+ public final ArgumentBlock parse(boolean parseTile) throws CommandSyntaxException { return this.a(parseTile); } // Paper - OBFHELPER
|
2018-11-11 09:30:57 +01:00
|
|
|
public ArgumentBlock a(boolean flag) throws CommandSyntaxException {
|
|
|
|
this.s = this::l;
|
2019-01-01 04:15:55 +01:00
|
|
|
if (this.i.canRead() && this.i.peek() == '#') {
|
2018-09-23 05:30:54 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2021-03-16 16:50:45 +01:00
|
|
|
index 7f790c484fec77e1d1f1dc6abe0daa19d009ae46..8f8dccd6fb2e49d65383d6e8f3fc5ffbabd2b7a5 100644
|
2018-09-23 05:30:54 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -39,12 +39,14 @@ import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
+import net.minecraft.commands.arguments.blocks.ArgumentBlock;
|
|
|
|
import net.minecraft.nbt.NBTBase;
|
|
|
|
import net.minecraft.nbt.NBTCompressedStreamTools;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
import net.minecraft.nbt.NBTTagString;
|
|
|
|
import net.minecraft.network.chat.ChatComponentText;
|
|
|
|
+import net.minecraft.resources.MinecraftKey;
|
|
|
|
import net.minecraft.world.entity.EnumItemSlot;
|
|
|
|
import net.minecraft.world.item.ItemBlock;
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
@@ -84,6 +86,12 @@ import org.bukkit.persistence.PersistentDataContainer;
|
2018-11-11 09:30:57 +01:00
|
|
|
import static org.spigotmc.ValidateUtils.*;
|
|
|
|
// Spigot end
|
|
|
|
|
|
|
|
+// Paper start
|
|
|
|
+import com.destroystokyo.paper.Namespaced;
|
|
|
|
+import com.destroystokyo.paper.NamespacedTag;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+// Paper end
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Children must include the following:
|
|
|
|
*
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -267,6 +275,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-09-23 05:30:54 +02:00
|
|
|
@Specific(Specific.To.NBT)
|
2019-05-05 10:33:44 +02:00
|
|
|
static final ItemMetaKey BLOCK_DATA = new ItemMetaKey("BlockStateTag");
|
2018-12-08 11:09:55 +01:00
|
|
|
static final ItemMetaKey BUKKIT_CUSTOM_TAG = new ItemMetaKey("PublicBukkitValues");
|
2018-09-23 05:30:54 +02:00
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
+ static final ItemMetaKey CAN_DESTROY = new ItemMetaKey("CanDestroy");
|
|
|
|
+ static final ItemMetaKey CAN_PLACE_ON = new ItemMetaKey("CanPlaceOn");
|
|
|
|
+ // Paper end
|
|
|
|
|
2021-01-01 05:03:19 +01:00
|
|
|
// We store the raw original JSON representation of all text data. See SPIGOT-5063, SPIGOT-5656, SPIGOT-5304
|
|
|
|
private String displayName;
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -280,6 +292,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-09-23 05:30:54 +02:00
|
|
|
private int hideFlag;
|
|
|
|
private boolean unbreakable;
|
|
|
|
private int damage;
|
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
2019-03-01 01:52:12 +01:00
|
|
|
+ private Set<Namespaced> placeableKeys = Sets.newHashSet();
|
|
|
|
+ private Set<Namespaced> destroyableKeys = Sets.newHashSet();
|
2018-09-23 05:30:54 +02:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
private static final Set<String> HANDLED_TAGS = Sets.newHashSet();
|
2019-05-06 04:58:04 +02:00
|
|
|
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -317,6 +333,15 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-09-23 05:30:54 +02:00
|
|
|
this.hideFlag = meta.hideFlag;
|
|
|
|
this.unbreakable = meta.unbreakable;
|
|
|
|
this.damage = meta.damage;
|
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
2018-11-11 09:30:57 +01:00
|
|
|
+ if (meta.hasPlaceableKeys()) {
|
|
|
|
+ this.placeableKeys = new java.util.HashSet<>(meta.placeableKeys);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (meta.hasDestroyableKeys()) {
|
|
|
|
+ this.destroyableKeys = new java.util.HashSet<>(meta.destroyableKeys);
|
|
|
|
+ }
|
2018-09-23 05:30:54 +02:00
|
|
|
+ // Paper end
|
|
|
|
this.unhandledTags.putAll(meta.unhandledTags);
|
2019-05-06 04:58:04 +02:00
|
|
|
this.persistentDataContainer.putAll(meta.persistentDataContainer.getRaw());
|
2018-09-23 05:30:54 +02:00
|
|
|
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -380,6 +405,31 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2019-05-06 04:58:04 +02:00
|
|
|
persistentDataContainer.put(key, compound.get(key));
|
2018-12-08 11:09:55 +01:00
|
|
|
}
|
2018-09-23 05:30:54 +02:00
|
|
|
}
|
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
+ if (tag.hasKey(CAN_DESTROY.NBT)) {
|
|
|
|
+ NBTTagList list = tag.getList(CAN_DESTROY.NBT, CraftMagicNumbers.NBT.TAG_STRING);
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
2018-11-11 09:30:57 +01:00
|
|
|
+ Namespaced namespaced = this.deserializeNamespaced(list.getString(i));
|
|
|
|
+ if (namespaced == null) {
|
2018-10-03 04:53:27 +02:00
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
2018-11-11 09:30:57 +01:00
|
|
|
+ this.destroyableKeys.add(namespaced);
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (tag.hasKey(CAN_PLACE_ON.NBT)) {
|
|
|
|
+ NBTTagList list = tag.getList(CAN_PLACE_ON.NBT, CraftMagicNumbers.NBT.TAG_STRING);
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
2018-11-11 09:30:57 +01:00
|
|
|
+ Namespaced namespaced = this.deserializeNamespaced(list.getString(i));
|
|
|
|
+ if (namespaced == null) {
|
2018-10-03 04:53:27 +02:00
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
2018-11-11 09:30:57 +01:00
|
|
|
+ this.placeableKeys.add(namespaced);
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
Set<String> keys = tag.getKeys();
|
|
|
|
for (String key : keys) {
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -518,6 +568,34 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-11-11 09:30:57 +01:00
|
|
|
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) {
|
|
|
|
+ for (Object canPlaceOnElement : canPlaceOnSerialized) {
|
|
|
|
+ String canPlaceOnRaw = (String) canPlaceOnElement;
|
|
|
|
+ Namespaced value = this.deserializeNamespaced(canPlaceOnRaw);
|
|
|
|
+ if (value == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.placeableKeys.add(value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Iterable<?> canDestroySerialized = SerializableMeta.getObject(Iterable.class, map, CAN_DESTROY.BUKKIT, true);
|
|
|
|
+ if (canDestroySerialized != null) {
|
|
|
|
+ for (Object canDestroyElement : canDestroySerialized) {
|
|
|
|
+ String canDestroyRaw = (String) canDestroyElement;
|
|
|
|
+ Namespaced value = this.deserializeNamespaced(canDestroyRaw);
|
|
|
|
+ if (value == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.destroyableKeys.add(value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
String internal = SerializableMeta.getString(map, "internal", true);
|
|
|
|
if (internal != null) {
|
|
|
|
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal));
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -646,6 +724,23 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-09-23 05:30:54 +02:00
|
|
|
if (hasDamage()) {
|
|
|
|
itemTag.setInt(DAMAGE.NBT, damage);
|
|
|
|
}
|
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
2018-11-11 09:30:57 +01:00
|
|
|
+ if (hasPlaceableKeys()) {
|
|
|
|
+ List<String> items = this.placeableKeys.stream()
|
|
|
|
+ .map(this::serializeNamespaced)
|
2018-09-23 05:30:54 +02:00
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
+
|
2019-05-05 10:33:44 +02:00
|
|
|
+ itemTag.set(CAN_PLACE_ON.NBT, createNonComponentStringList(items));
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
2018-11-11 09:30:57 +01:00
|
|
|
+ if (hasDestroyableKeys()) {
|
|
|
|
+ List<String> items = this.destroyableKeys.stream()
|
|
|
|
+ .map(this::serializeNamespaced)
|
2018-09-23 05:30:54 +02:00
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
+
|
2019-05-05 10:33:44 +02:00
|
|
|
+ itemTag.set(CAN_DESTROY.NBT, createNonComponentStringList(items));
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
for (Map.Entry<String, NBTBase> e : unhandledTags.entrySet()) {
|
|
|
|
itemTag.set(e.getKey(), e.getValue());
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -662,6 +757,21 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2019-05-05 10:33:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ static NBTTagList createNonComponentStringList(List<String> list) {
|
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ NBTTagList tagList = new NBTTagList();
|
|
|
|
+ for (String value : list) {
|
2019-12-13 02:18:18 +01:00
|
|
|
+ tagList.add(NBTTagString.a(value)); // Paper - NBTTagString.of(String str)
|
2019-05-05 10:33:44 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return tagList;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
2021-01-01 05:03:19 +01:00
|
|
|
NBTTagList createStringList(List<String> list) {
|
|
|
|
if (list == null) {
|
2019-05-05 10:33:44 +02:00
|
|
|
return null;
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -745,7 +855,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-11-11 09:30:57 +01:00
|
|
|
|
|
|
|
@Overridden
|
|
|
|
boolean isEmpty() {
|
2021-01-01 05:03:19 +01:00
|
|
|
- return !(hasDisplayName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasBlockData() || hasRepairCost() || !unhandledTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isUnbreakable() || hasDamage() || hasAttributeModifiers());
|
|
|
|
+ return !(hasDisplayName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasBlockData() || hasRepairCost() || !unhandledTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isUnbreakable() || hasDamage() || hasAttributeModifiers() || hasPlaceableKeys() || hasDestroyableKeys()); // Paper - Implement an API for CanPlaceOn and CanDestroy NBT values
|
2018-11-11 09:30:57 +01:00
|
|
|
}
|
|
|
|
|
2021-02-21 20:45:33 +01:00
|
|
|
// Paper start
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -1169,7 +1279,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-11-11 09:30:57 +01:00
|
|
|
&& (this.hideFlag == that.hideFlag)
|
|
|
|
&& (this.isUnbreakable() == that.isUnbreakable())
|
2019-05-05 10:33:44 +02:00
|
|
|
&& (this.hasDamage() ? that.hasDamage() && this.damage == that.damage : !that.hasDamage())
|
|
|
|
- && (this.version == that.version);
|
|
|
|
+ && (this.version == that.version)
|
2018-11-11 09:30:57 +01:00
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
+ && (this.hasPlaceableKeys() ? that.hasPlaceableKeys() && this.placeableKeys.equals(that.placeableKeys) : !that.hasPlaceableKeys())
|
|
|
|
+ && (this.hasDestroyableKeys() ? that.hasDestroyableKeys() && this.destroyableKeys.equals(that.destroyableKeys) : !that.hasDestroyableKeys());
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -1204,6 +1318,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-11-11 09:30:57 +01:00
|
|
|
hash = 61 * hash + (hasDamage() ? this.damage : 0);
|
|
|
|
hash = 61 * hash + (hasAttributeModifiers() ? this.attributeModifiers.hashCode() : 0);
|
2019-05-05 10:33:44 +02:00
|
|
|
hash = 61 * hash + version;
|
2018-11-11 09:30:57 +01:00
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
+ hash = 61 * hash + (hasPlaceableKeys() ? this.placeableKeys.hashCode() : 0);
|
|
|
|
+ hash = 61 * hash + (hasDestroyableKeys() ? this.destroyableKeys.hashCode() : 0);
|
|
|
|
+ // Paper end
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -1228,6 +1346,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-11-11 09:30:57 +01:00
|
|
|
clone.unbreakable = this.unbreakable;
|
|
|
|
clone.damage = this.damage;
|
2019-05-05 10:33:44 +02:00
|
|
|
clone.version = this.version;
|
2018-11-11 09:30:57 +01:00
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
+ if (this.placeableKeys != null) {
|
|
|
|
+ clone.placeableKeys = Sets.newHashSet(this.placeableKeys);
|
|
|
|
+ }
|
|
|
|
+ if (this.destroyableKeys != null) {
|
|
|
|
+ clone.destroyableKeys = Sets.newHashSet(this.destroyableKeys);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
return clone;
|
|
|
|
} catch (CloneNotSupportedException e) {
|
|
|
|
throw new Error(e);
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -1285,6 +1411,24 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-11-11 09:30:57 +01:00
|
|
|
builder.put(DAMAGE.BUKKIT, damage);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
+ if (hasPlaceableKeys()) {
|
|
|
|
+ List<String> cerealPlaceable = this.placeableKeys.stream()
|
|
|
|
+ .map(this::serializeNamespaced)
|
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
+
|
|
|
|
+ builder.put(CAN_PLACE_ON.BUKKIT, cerealPlaceable);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (hasDestroyableKeys()) {
|
|
|
|
+ List<String> cerealDestroyable = this.destroyableKeys.stream()
|
|
|
|
+ .map(this::serializeNamespaced)
|
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
+
|
|
|
|
+ builder.put(CAN_DESTROY.BUKKIT, cerealDestroyable);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
final Map<String, NBTBase> internalTags = new HashMap<String, NBTBase>(unhandledTags);
|
|
|
|
serializeInternal(internalTags);
|
|
|
|
if (!internalTags.isEmpty()) {
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -1449,6 +1593,8 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-09-23 05:30:54 +02:00
|
|
|
CraftMetaArmorStand.SHOW_ARMS.NBT,
|
|
|
|
CraftMetaArmorStand.SMALL.NBT,
|
2020-07-01 08:11:46 +02:00
|
|
|
CraftMetaArmorStand.MARKER.NBT,
|
2018-09-23 05:30:54 +02:00
|
|
|
+ CAN_DESTROY.NBT,
|
2020-07-01 08:11:46 +02:00
|
|
|
+ CAN_PLACE_ON.NBT,
|
2018-09-23 05:30:54 +02:00
|
|
|
// Paper end
|
2020-07-01 08:11:46 +02:00
|
|
|
CraftMetaCompass.LODESTONE_DIMENSION.NBT,
|
|
|
|
CraftMetaCompass.LODESTONE_POS.NBT,
|
2021-03-16 16:50:45 +01:00
|
|
|
@@ -1476,4 +1622,147 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2018-09-23 05:30:54 +02:00
|
|
|
}
|
2019-12-12 17:20:43 +01:00
|
|
|
// Paper end
|
|
|
|
|
2018-09-23 05:30:54 +02:00
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
+ @Override
|
2018-11-11 09:30:57 +01:00
|
|
|
+ @SuppressWarnings("deprecation")
|
2018-09-23 05:30:54 +02:00
|
|
|
+ public Set<Material> getCanDestroy() {
|
2019-03-01 01:52:12 +01:00
|
|
|
+ return !hasDestroyableKeys() ? Collections.emptySet() : legacyGetMatsFromKeys(this.destroyableKeys);
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @SuppressWarnings("deprecation")
|
|
|
|
+ public void setCanDestroy(Set<Material> canDestroy) {
|
2018-11-11 09:30:57 +01:00
|
|
|
+ Validate.notNull(canDestroy, "Cannot replace with null set!");
|
|
|
|
+ legacyClearAndReplaceKeys(this.destroyableKeys, canDestroy);
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2018-11-11 09:30:57 +01:00
|
|
|
+ @SuppressWarnings("deprecation")
|
2018-09-23 05:30:54 +02:00
|
|
|
+ public Set<Material> getCanPlaceOn() {
|
2019-03-01 01:52:12 +01:00
|
|
|
+ return !hasPlaceableKeys() ? Collections.emptySet() : legacyGetMatsFromKeys(this.placeableKeys);
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @SuppressWarnings("deprecation")
|
|
|
|
+ public void setCanPlaceOn(Set<Material> canPlaceOn) {
|
2018-11-11 09:30:57 +01:00
|
|
|
+ Validate.notNull(canPlaceOn, "Cannot replace with null set!");
|
|
|
|
+ legacyClearAndReplaceKeys(this.placeableKeys, canPlaceOn);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Set<Namespaced> getDestroyableKeys() {
|
2019-03-01 01:52:12 +01:00
|
|
|
+ return !hasDestroyableKeys() ? Collections.emptySet() : Sets.newHashSet(this.destroyableKeys);
|
2018-11-11 09:30:57 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setDestroyableKeys(Collection<Namespaced> canDestroy) {
|
|
|
|
+ Validate.notNull(canDestroy, "Cannot replace with null collection!");
|
|
|
|
+ Validate.isTrue(ofAcceptableType(canDestroy), "Can only use NamespacedKey or NamespacedTag objects!");
|
|
|
|
+ this.destroyableKeys.clear();
|
|
|
|
+ this.destroyableKeys.addAll(canDestroy);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Set<Namespaced> getPlaceableKeys() {
|
2019-03-01 01:52:12 +01:00
|
|
|
+ return !hasPlaceableKeys() ? Collections.emptySet() : Sets.newHashSet(this.placeableKeys);
|
2018-11-11 09:30:57 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setPlaceableKeys(Collection<Namespaced> canPlaceOn) {
|
|
|
|
+ Validate.notNull(canPlaceOn, "Cannot replace with null collection!");
|
|
|
|
+ Validate.isTrue(ofAcceptableType(canPlaceOn), "Can only use NamespacedKey or NamespacedTag objects!");
|
|
|
|
+ this.placeableKeys.clear();
|
|
|
|
+ this.placeableKeys.addAll(canPlaceOn);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean hasPlaceableKeys() {
|
|
|
|
+ return this.placeableKeys != null && !this.placeableKeys.isEmpty();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean hasDestroyableKeys() {
|
|
|
|
+ return this.destroyableKeys != null && !this.destroyableKeys.isEmpty();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Deprecated
|
|
|
|
+ private void legacyClearAndReplaceKeys(Collection<Namespaced> toUpdate, Collection<Material> beingSet) {
|
|
|
|
+ if (beingSet.stream().anyMatch(Material::isLegacy)) {
|
|
|
|
+ throw new IllegalArgumentException("Set must not contain any legacy materials!");
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
2018-11-11 09:30:57 +01:00
|
|
|
+
|
|
|
|
+ toUpdate.clear();
|
|
|
|
+ toUpdate.addAll(beingSet.stream().map(Material::getKey).collect(java.util.stream.Collectors.toSet()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Deprecated
|
|
|
|
+ private Set<Material> legacyGetMatsFromKeys(Collection<Namespaced> names) {
|
|
|
|
+ Set<Material> mats = Sets.newHashSet();
|
|
|
|
+ for (Namespaced key : names) {
|
|
|
|
+ if (!(key instanceof org.bukkit.NamespacedKey)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Material material = Material.matchMaterial(key.toString(), false);
|
|
|
|
+ if (material != null) {
|
|
|
|
+ mats.add(material);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return mats;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private @Nullable Namespaced deserializeNamespaced(String raw) {
|
2019-12-01 01:20:12 +01:00
|
|
|
+ boolean isTag = raw.length() > 0 && raw.codePointAt(0) == '#';
|
2021-03-16 16:50:45 +01:00
|
|
|
+ ArgumentBlock blockParser = new ArgumentBlock(new com.mojang.brigadier.StringReader(raw), true);
|
2018-11-11 09:30:57 +01:00
|
|
|
+ try {
|
|
|
|
+ blockParser = blockParser.parse(false);
|
|
|
|
+ } catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
2021-03-16 16:50:45 +01:00
|
|
|
+ MinecraftKey key;
|
2018-11-11 09:30:57 +01:00
|
|
|
+ if (isTag) {
|
|
|
|
+ key = blockParser.getTagKey();
|
|
|
|
+ } else {
|
|
|
|
+ key = blockParser.getBlockKey();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (key == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // don't DC the player if something slips through somehow
|
|
|
|
+ Namespaced resource = null;
|
|
|
|
+ try {
|
|
|
|
+ if (isTag) {
|
2019-07-20 06:01:24 +02:00
|
|
|
+ resource = new NamespacedTag(key.getNamespace(), key.getKey());
|
2018-11-11 09:30:57 +01:00
|
|
|
+ } else {
|
|
|
|
+ resource = CraftNamespacedKey.fromMinecraft(key);
|
|
|
|
+ }
|
|
|
|
+ } catch (IllegalArgumentException ex) {
|
|
|
|
+ org.bukkit.Bukkit.getLogger().warning("Namespaced resource does not validate: " + key.toString());
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resource;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private @Nonnull String serializeNamespaced(Namespaced resource) {
|
|
|
|
+ return resource.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // not a fan of this
|
|
|
|
+ private boolean ofAcceptableType(Collection<Namespaced> namespacedResources) {
|
2021-02-21 13:34:08 +01:00
|
|
|
+
|
2018-11-11 09:30:57 +01:00
|
|
|
+ for (Namespaced resource : namespacedResources) {
|
2021-02-21 13:34:08 +01:00
|
|
|
+ if (!(resource instanceof org.bukkit.NamespacedKey || resource instanceof com.destroystokyo.paper.NamespacedTag)) {
|
|
|
|
+ return false;
|
2018-11-11 09:30:57 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2021-02-21 13:34:08 +01:00
|
|
|
+ return true;
|
2018-09-23 05:30:54 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|