2019-04-03 03:27:20 +00:00
|
|
|
From 7586c4a617d2bfa2125e91fcd391fcefc9fd9d17 Mon Sep 17 00:00:00 2001
|
2018-09-23 03:30:54 +00: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
|
|
|
|
|
|
|
|
|
2018-11-11 08:30:57 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ArgumentBlock.java b/src/main/java/net/minecraft/server/ArgumentBlock.java
|
2019-03-20 00:28:15 +00:00
|
|
|
index 8e8390282..f52936581 100644
|
2018-11-11 08:30:57 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/ArgumentBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ArgumentBlock.java
|
2018-12-21 16:09:17 +00:00
|
|
|
@@ -43,7 +43,7 @@ public class ArgumentBlock {
|
2018-11-11 08:30:57 +00:00
|
|
|
private final boolean j;
|
2018-12-21 16:09:17 +00:00
|
|
|
private final Map<IBlockState<?>, Comparable<?>> k = Maps.newLinkedHashMap(); // CraftBukkit - stable
|
2018-11-11 08:30:57 +00:00
|
|
|
private final Map<String, String> l = Maps.newHashMap();
|
|
|
|
- private MinecraftKey m = new MinecraftKey("");
|
|
|
|
+ private MinecraftKey m = new MinecraftKey(""); public MinecraftKey getBlockKey() { return this.m; } // Paper - OBFHELPER
|
|
|
|
private BlockStateList<Block, IBlockData> n;
|
|
|
|
private IBlockData o;
|
|
|
|
@Nullable
|
2018-12-21 16:09:17 +00:00
|
|
|
@@ -72,11 +72,13 @@ public class ArgumentBlock {
|
2018-11-11 08:30:57 +00:00
|
|
|
return this.p;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public @Nullable MinecraftKey getTagKey() { return d(); } // Paper - OBFHELPER
|
|
|
|
@Nullable
|
|
|
|
public MinecraftKey d() {
|
|
|
|
return this.q;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public ArgumentBlock parse(boolean parseTile) throws CommandSyntaxException { return this.a(parseTile); } // Paper - OBFHELPER
|
|
|
|
public ArgumentBlock a(boolean flag) throws CommandSyntaxException {
|
|
|
|
this.s = this::l;
|
2019-01-01 03:15:55 +00:00
|
|
|
if (this.i.canRead() && this.i.peek() == '#') {
|
2018-09-23 03:30:54 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2019-04-03 03:27:20 +00:00
|
|
|
index 570f695d8..ec91ab72d 100644
|
2018-09-23 03:30:54 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -82,6 +82,12 @@ import javax.annotation.Nullable;
|
2018-11-11 08:30:57 +00: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:
|
|
|
|
*
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -257,6 +263,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-09-23 03:30:54 +00:00
|
|
|
@Specific(Specific.To.NBT)
|
|
|
|
static final ItemMetaKey DAMAGE = new ItemMetaKey("Damage");
|
2018-12-08 10:09:55 +00:00
|
|
|
static final ItemMetaKey BUKKIT_CUSTOM_TAG = new ItemMetaKey("PublicBukkitValues");
|
2018-09-23 03:30:54 +00: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
|
|
|
|
|
|
|
|
private IChatBaseComponent displayName;
|
|
|
|
private IChatBaseComponent locName;
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -267,6 +277,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-09-23 03:30:54 +00:00
|
|
|
private int hideFlag;
|
|
|
|
private boolean unbreakable;
|
|
|
|
private int damage;
|
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
2019-03-01 00:52:12 +00:00
|
|
|
+ private Set<Namespaced> placeableKeys = Sets.newHashSet();
|
|
|
|
+ private Set<Namespaced> destroyableKeys = Sets.newHashSet();
|
2018-09-23 03:30:54 +00:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
private static final Set<String> HANDLED_TAGS = Sets.newHashSet();
|
2018-12-08 10:09:55 +00:00
|
|
|
private static final CraftCustomTagTypeRegistry TAG_TYPE_REGISTRY = new CraftCustomTagTypeRegistry();
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -299,6 +313,15 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-09-23 03:30:54 +00: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 08:30:57 +00: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 03:30:54 +00:00
|
|
|
+ // Paper end
|
|
|
|
this.unhandledTags.putAll(meta.unhandledTags);
|
2018-12-08 10:09:55 +00:00
|
|
|
this.publicItemTagContainer.putAll(meta.publicItemTagContainer.getRaw());
|
2018-09-23 03:30:54 +00:00
|
|
|
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -362,6 +385,31 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-12-08 10:09:55 +00:00
|
|
|
publicItemTagContainer.put(key, compound.get(key));
|
|
|
|
}
|
2018-09-23 03:30:54 +00: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 08:30:57 +00:00
|
|
|
+ Namespaced namespaced = this.deserializeNamespaced(list.getString(i));
|
|
|
|
+ if (namespaced == null) {
|
2018-10-03 02:53:27 +00:00
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
2018-11-11 08:30:57 +00:00
|
|
|
+ this.destroyableKeys.add(namespaced);
|
2018-09-23 03:30:54 +00: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 08:30:57 +00:00
|
|
|
+ Namespaced namespaced = this.deserializeNamespaced(list.getString(i));
|
|
|
|
+ if (namespaced == null) {
|
2018-10-03 02:53:27 +00:00
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
2018-11-11 08:30:57 +00:00
|
|
|
+ this.placeableKeys.add(namespaced);
|
2018-09-23 03:30:54 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
Set<String> keys = tag.getKeys();
|
|
|
|
for (String key : keys) {
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -489,6 +537,34 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-11-11 08:30:57 +00: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));
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -609,6 +685,23 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-09-23 03:30:54 +00:00
|
|
|
if (hasDamage()) {
|
|
|
|
itemTag.setInt(DAMAGE.NBT, damage);
|
|
|
|
}
|
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
2018-11-11 08:30:57 +00:00
|
|
|
+ if (hasPlaceableKeys()) {
|
|
|
|
+ List<String> items = this.placeableKeys.stream()
|
|
|
|
+ .map(this::serializeNamespaced)
|
2018-09-23 03:30:54 +00:00
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
+
|
|
|
|
+ itemTag.set(CAN_PLACE_ON.NBT, createStringList(items));
|
|
|
|
+ }
|
|
|
|
+
|
2018-11-11 08:30:57 +00:00
|
|
|
+ if (hasDestroyableKeys()) {
|
|
|
|
+ List<String> items = this.destroyableKeys.stream()
|
|
|
|
+ .map(this::serializeNamespaced)
|
2018-09-23 03:30:54 +00:00
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
|
+
|
|
|
|
+ itemTag.set(CAN_DESTROY.NBT, createStringList(items));
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
for (Map.Entry<String, NBTBase> e : unhandledTags.entrySet()) {
|
|
|
|
itemTag.set(e.getKey(), e.getValue());
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -707,7 +800,8 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-11-11 08:30:57 +00:00
|
|
|
|
|
|
|
@Overridden
|
|
|
|
boolean isEmpty() {
|
2018-12-08 10:09:55 +00:00
|
|
|
- return !(hasDisplayName() || hasLocalizedName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || !publicItemTagContainer.isEmpty() || hideFlag != 0 || isUnbreakable() || hasDamage() || hasAttributeModifiers());
|
|
|
|
+ return !(hasDisplayName() || hasLocalizedName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || !publicItemTagContainer.isEmpty() || hideFlag != 0 || isUnbreakable() || hasDamage() || hasAttributeModifiers()
|
2018-11-11 08:30:57 +00:00
|
|
|
+ || hasPlaceableKeys() || hasDestroyableKeys()); // Paper - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDisplayName() {
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -1049,7 +1143,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-12-08 10:09:55 +00:00
|
|
|
&& (this.publicItemTagContainer.equals(that.publicItemTagContainer))
|
2018-11-11 08:30:57 +00:00
|
|
|
&& (this.hideFlag == that.hideFlag)
|
|
|
|
&& (this.isUnbreakable() == that.isUnbreakable())
|
|
|
|
- && (this.hasDamage() ? that.hasDamage() && this.damage == that.damage : !that.hasDamage());
|
|
|
|
+ && (this.hasDamage() ? that.hasDamage() && this.damage == that.damage : !that.hasDamage())
|
|
|
|
+ // 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
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -1081,6 +1179,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-11-11 08:30:57 +00:00
|
|
|
hash = 61 * hash + (isUnbreakable() ? 1231 : 1237);
|
|
|
|
hash = 61 * hash + (hasDamage() ? this.damage : 0);
|
|
|
|
hash = 61 * hash + (hasAttributeModifiers() ? this.attributeModifiers.hashCode() : 0);
|
|
|
|
+ // 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;
|
|
|
|
}
|
|
|
|
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -1101,6 +1203,15 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-11-11 08:30:57 +00:00
|
|
|
clone.hideFlag = this.hideFlag;
|
|
|
|
clone.unbreakable = this.unbreakable;
|
|
|
|
clone.damage = this.damage;
|
|
|
|
+ // 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);
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -1150,6 +1261,24 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-11-11 08:30:57 +00: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()) {
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -1299,7 +1428,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-09-23 03:30:54 +00:00
|
|
|
CraftMetaArmorStand.NO_BASE_PLATE.NBT,
|
|
|
|
CraftMetaArmorStand.SHOW_ARMS.NBT,
|
|
|
|
CraftMetaArmorStand.SMALL.NBT,
|
|
|
|
- CraftMetaArmorStand.MARKER.NBT
|
|
|
|
+ CraftMetaArmorStand.MARKER.NBT,
|
|
|
|
+ CAN_DESTROY.NBT,
|
|
|
|
+ CAN_PLACE_ON.NBT
|
|
|
|
// Paper end
|
|
|
|
));
|
|
|
|
}
|
2019-04-03 03:27:20 +00:00
|
|
|
@@ -1346,4 +1477,147 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
2018-09-23 03:30:54 +00:00
|
|
|
return spigot;
|
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
+ // Paper start - Implement an API for CanPlaceOn and CanDestroy NBT values
|
|
|
|
+ @Override
|
2018-11-11 08:30:57 +00:00
|
|
|
+ @SuppressWarnings("deprecation")
|
2018-09-23 03:30:54 +00:00
|
|
|
+ public Set<Material> getCanDestroy() {
|
2019-03-01 00:52:12 +00:00
|
|
|
+ return !hasDestroyableKeys() ? Collections.emptySet() : legacyGetMatsFromKeys(this.destroyableKeys);
|
2018-09-23 03:30:54 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @SuppressWarnings("deprecation")
|
|
|
|
+ public void setCanDestroy(Set<Material> canDestroy) {
|
2018-11-11 08:30:57 +00:00
|
|
|
+ Validate.notNull(canDestroy, "Cannot replace with null set!");
|
|
|
|
+ legacyClearAndReplaceKeys(this.destroyableKeys, canDestroy);
|
2018-09-23 03:30:54 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2018-11-11 08:30:57 +00:00
|
|
|
+ @SuppressWarnings("deprecation")
|
2018-09-23 03:30:54 +00:00
|
|
|
+ public Set<Material> getCanPlaceOn() {
|
2019-03-01 00:52:12 +00:00
|
|
|
+ return !hasPlaceableKeys() ? Collections.emptySet() : legacyGetMatsFromKeys(this.placeableKeys);
|
2018-09-23 03:30:54 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @SuppressWarnings("deprecation")
|
|
|
|
+ public void setCanPlaceOn(Set<Material> canPlaceOn) {
|
2018-11-11 08:30:57 +00:00
|
|
|
+ Validate.notNull(canPlaceOn, "Cannot replace with null set!");
|
|
|
|
+ legacyClearAndReplaceKeys(this.placeableKeys, canPlaceOn);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Set<Namespaced> getDestroyableKeys() {
|
2019-03-01 00:52:12 +00:00
|
|
|
+ return !hasDestroyableKeys() ? Collections.emptySet() : Sets.newHashSet(this.destroyableKeys);
|
2018-11-11 08:30:57 +00: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 00:52:12 +00:00
|
|
|
+ return !hasPlaceableKeys() ? Collections.emptySet() : Sets.newHashSet(this.placeableKeys);
|
2018-11-11 08:30:57 +00: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 03:30:54 +00:00
|
|
|
+ }
|
2018-11-11 08:30:57 +00: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) {
|
|
|
|
+ boolean isTag = raw.codePointAt(0) == '#';
|
|
|
|
+ net.minecraft.server.ArgumentBlock blockParser = new net.minecraft.server.ArgumentBlock(new com.mojang.brigadier.StringReader(raw), true);
|
|
|
|
+ try {
|
|
|
|
+ blockParser = blockParser.parse(false);
|
|
|
|
+ } catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ net.minecraft.server.MinecraftKey key;
|
|
|
|
+ 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) {
|
|
|
|
+ resource = new NamespacedTag(key.b(), key.getKey());
|
|
|
|
+ } 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) {
|
|
|
|
+ boolean valid = true;
|
|
|
|
+ for (Namespaced resource : namespacedResources) {
|
|
|
|
+ if (valid && !(resource instanceof org.bukkit.NamespacedKey || resource instanceof com.destroystokyo.paper.NamespacedTag)) {
|
|
|
|
+ valid = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return valid;
|
2018-09-23 03:30:54 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
--
|
2019-03-20 00:28:15 +00:00
|
|
|
2.21.0
|
2018-09-23 03:30:54 +00:00
|
|
|
|