13
0
geforkt von Mirrors/Paper
Paper/patches/api/0479-Add-an-API-for-CanPlaceOn-and-CanDestroy-NBT-values.patch
Bjarne Koll 3b9db2b194
Updated Upstream (Bukkit/CraftBukkit) (#11501)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
bb4e97c6 Add support for Java 23
bc6874dd Bump asm to 9.7.1
50e8a00b PR-1064: Add specific getTopInventory methods for InventoryView derivatives
758b0a0f SPIGOT-7911: Fix Location#isWorldLoaded() for re-loaded worlds
133a64a7 Improve Registry#getOrThrow messages
be0f5957 PR-1058: Add tests for Minecraft registry <-> Bukkit fields
d1b31df2 PR-1062: Clarify BeaconView documentation
3fab4384 PR-1060: Cache Material to BlockType and ItemType conversion
967a7301 SPIGOT-7906: Increase YAML nesting limit to 100
6ecf033d SPIGOT-7899: Smithing recipes don't require inputs

CraftBukkit Changes:
0a7bd6c81 PR-1493: Improve reroute performance and add some tests
54941524c Add support for Java 23
f4d957fff SPIGOT-7915: Fix World#getKeepSpawnInMemory() using Spawn Radius rather than Spawn Chunk Radius
ded183674 Fix HIDE_ENCHANTS flag in items without enchantments
308785a0a Bump asm to 9.7.1 and re-add ClassReader to ClassWriter
72ce823cd PR-1487: Add specific getTopInventory methods for InventoryView derivatives
11a5e840c SPIGOT-7907, PR-1484: Improve merchant recipe item matching behavior to more closely align with older versions
45b66f7e4 SPIGOT-7909: Always set HIDE_ENCHANTS flag to item if flag is set
963459791 Increase outdated build delay
fc5b2d75f SPIGOT-7910: Fix launching breeze wind charge from API and improve dispenser launch API
c7d6428f2 SPIGOT-7856, PR-1483: End platform not dropping items after replacing blocks
2a5572b52 SPIGOT-7780, PR-1482: Cannot edit chunks during unload event
527041ab5 SPIGOT-7902, PR-1477: Fix CraftMetaPotion#hasCustomEffects() does not check if customEffects (List) is empty
5529a1769 Implement base methods for tags
30fbdbaaf Improve Registry#getOrThrow messages
6b71a7322 PR-1475: Add tests for Minecraft registry <-> Bukkit fields
5f24c255c SPIGOT-7908: Mark junit-platform-suite-engine as test scope
e4c92ef65 PR-1473: Change tests to use suites, to run tests in different environments and feature flags
d25e1e722 PR-1481: Fix BeaconView#set[X]Effect(null)
d69a05362 PR-1480: Fix PerMaterialTest#isEdible test running for legacy materials
bb3284a89 PR-1479: Use custom #isBlock method in legacy init instead of the one in Material, since it relies on legacy being init
98c57cbbe SPIGOT-7904: Fix NPE for PlayerItemBreakEvent
f35bae9ec Fix missing hasJukeboxPlayable
8a6f8b6d8 SPIGOT-7881: CTRL+Pick Block saves position data into item
7913b3be7 SPIGOT-7899: Smithing recipes don't require inputs
2024-10-21 00:06:54 +02:00

333 Zeilen
13 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mark Vainomaa <mikroskeem@mikroskeem.eu>
Date: Wed, 12 Sep 2018 18:53:35 +0300
Subject: [PATCH] Add an API for CanPlaceOn and CanDestroy NBT values
diff --git a/src/main/java/com/destroystokyo/paper/Namespaced.java b/src/main/java/com/destroystokyo/paper/Namespaced.java
new file mode 100644
index 0000000000000000000000000000000000000000..e708cc48f480e91a60834897e447e4a2fc1244d4
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/Namespaced.java
@@ -0,0 +1,41 @@
+package com.destroystokyo.paper;
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Represents a namespaced resource, see {@link org.bukkit.NamespacedKey} for single elements
+ * or {@link com.destroystokyo.paper.NamespacedTag} for a collection of elements
+ *
+ * Namespaces may only contain lowercase alphanumeric characters, periods,
+ * underscores, and hyphens.
+ * <p>
+ * Keys may only contain lowercase alphanumeric characters, periods,
+ * underscores, hyphens, and forward slashes.
+ * <p>
+ * You should not be implementing this interface yourself, use {@link org.bukkit.NamespacedKey}
+ * or {@link com.destroystokyo.paper.NamespacedTag} as needed instead.
+ */
+@Deprecated(forRemoval = true, since = "1.20.6")
+public interface Namespaced {
+ /**
+ * Gets the namespace this resource is a part of
+ * <p>
+ * This is contractually obligated to only contain lowercase alphanumeric characters,
+ * periods, underscores, and hyphens.
+ *
+ * @return resource namespace
+ */
+ @NotNull
+ String getNamespace();
+
+ /**
+ * Gets the key corresponding to this resource
+ * <p>
+ * This is contractually obligated to only contain lowercase alphanumeric characters,
+ * periods, underscores, hyphens, and forward slashes.
+ *
+ * @return resource key
+ */
+ @NotNull
+ String getKey();
+}
diff --git a/src/main/java/com/destroystokyo/paper/NamespacedTag.java b/src/main/java/com/destroystokyo/paper/NamespacedTag.java
new file mode 100644
index 0000000000000000000000000000000000000000..c976995a0fceaf0cbddd399906a866747b12a202
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/NamespacedTag.java
@@ -0,0 +1,143 @@
+package com.destroystokyo.paper;
+
+import com.google.common.base.Preconditions;
+import java.util.Locale;
+import java.util.UUID;
+import java.util.regex.Pattern;
+import org.bukkit.plugin.Plugin;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Represents a String based key pertaining to a tagged entry. Consists of two components - a namespace
+ * and a key.
+ * <p>
+ * Namespaces may only contain lowercase alphanumeric characters, periods,
+ * underscores, and hyphens.
+ * <p>
+ * Keys may only contain lowercase alphanumeric characters, periods,
+ * underscores, hyphens, and forward slashes.
+ *
+ */
+// Paper - entire class, based on org.bukkit.NamespacedKey
+@Deprecated(forRemoval = true, since = "1.20.6")
+public final class NamespacedTag implements com.destroystokyo.paper.Namespaced {
+
+ /**
+ * The namespace representing all inbuilt keys.
+ */
+ public static final String MINECRAFT = "minecraft";
+ /**
+ * The namespace representing all keys generated by Bukkit for backwards
+ * compatibility measures.
+ */
+ public static final String BUKKIT = "bukkit";
+ //
+ private static final Pattern VALID_NAMESPACE = Pattern.compile("[a-z0-9._-]+");
+ private static final Pattern VALID_KEY = Pattern.compile("[a-z0-9/._-]+");
+ //
+ private final String namespace;
+ private final String key;
+
+ /**
+ * Create a key in a specific namespace.
+ *
+ * @param namespace String representing a grouping of keys
+ * @param key Name for this specific key
+ * @deprecated should never be used by plugins, for internal use only!!
+ */
+ @Deprecated
+ public NamespacedTag(@NotNull String namespace, @NotNull String key) {
+ Preconditions.checkArgument(namespace != null && VALID_NAMESPACE.matcher(namespace).matches(), "Invalid namespace. Must be [a-z0-9._-]: %s", namespace);
+ Preconditions.checkArgument(key != null && VALID_KEY.matcher(key).matches(), "Invalid key. Must be [a-z0-9/._-]: %s", key);
+
+ this.namespace = namespace;
+ this.key = key;
+
+ String string = toString();
+ Preconditions.checkArgument(string.length() < 256, "NamespacedTag must be less than 256 characters", string);
+ }
+
+ /**
+ * Create a key in the plugin's namespace.
+ * <p>
+ * Namespaces may only contain lowercase alphanumeric characters, periods,
+ * underscores, and hyphens.
+ * <p>
+ * Keys may only contain lowercase alphanumeric characters, periods,
+ * underscores, hyphens, and forward slashes.
+ *
+ * @param plugin the plugin to use for the namespace
+ * @param key the key to create
+ */
+ public NamespacedTag(@NotNull Plugin plugin, @NotNull String key) {
+ Preconditions.checkArgument(plugin != null, "Plugin cannot be null");
+ Preconditions.checkArgument(key != null, "Key cannot be null");
+
+ this.namespace = plugin.getName().toLowerCase(Locale.ROOT);
+ this.key = key.toLowerCase().toLowerCase(Locale.ROOT);
+
+ // Check validity after normalization
+ Preconditions.checkArgument(VALID_NAMESPACE.matcher(this.namespace).matches(), "Invalid namespace. Must be [a-z0-9._-]: %s", this.namespace);
+ Preconditions.checkArgument(VALID_KEY.matcher(this.key).matches(), "Invalid key. Must be [a-z0-9/._-]: %s", this.key);
+
+ String string = toString();
+ Preconditions.checkArgument(string.length() < 256, "NamespacedTag must be less than 256 characters (%s)", string);
+ }
+
+ @NotNull
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @NotNull
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 47 * hash + this.namespace.hashCode();
+ hash = 47 * hash + this.key.hashCode();
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final NamespacedTag other = (NamespacedTag) obj;
+ return this.namespace.equals(other.namespace) && this.key.equals(other.key);
+ }
+
+ @Override
+ public String toString() {
+ return "#" + this.namespace + ":" + this.key;
+ }
+
+ /**
+ * Return a new random key in the {@link #BUKKIT} namespace.
+ *
+ * @return new key
+ * @deprecated should never be used by plugins, for internal use only!!
+ */
+ @Deprecated
+ public static NamespacedTag randomKey() {
+ return new NamespacedTag(BUKKIT, UUID.randomUUID().toString());
+ }
+
+ /**
+ * Get a key in the Minecraft namespace.
+ *
+ * @param key the key to use
+ * @return new key in the Minecraft namespace
+ */
+ @NotNull
+ public static NamespacedTag minecraft(@NotNull String key) {
+ return new NamespacedTag(MINECRAFT, key);
+ }
+}
diff --git a/src/main/java/org/bukkit/NamespacedKey.java b/src/main/java/org/bukkit/NamespacedKey.java
index 7ff6d60deb129e23b2a4d772aee123eb6c0b6433..52a2763773b234c581b2dcc6f0584f8d8b0fbc60 100644
--- a/src/main/java/org/bukkit/NamespacedKey.java
+++ b/src/main/java/org/bukkit/NamespacedKey.java
@@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
* underscores, hyphens, and forward slashes.
*
*/
-public final class NamespacedKey implements net.kyori.adventure.key.Key { // Paper - implement Key
+public final class NamespacedKey implements net.kyori.adventure.key.Key, com.destroystokyo.paper.Namespaced { // Paper - implement Key and Namespaced
/**
* The namespace representing all inbuilt keys.
@@ -121,11 +121,13 @@ public final class NamespacedKey implements net.kyori.adventure.key.Key { // Pap
}
@NotNull
+ @Override // Paper
public String getNamespace() {
return namespace;
}
@NotNull
+ @Override // Paper
public String getKey() {
return key;
}
diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
index 5d5fcb2720b62e47d47f441032c4de02574b051a..f5541454ba5e508a72c83989c6feaef5406e2535 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -806,4 +806,98 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@SuppressWarnings("javadoc")
@NotNull
ItemMeta clone();
+
+ // Paper start - Add an API for can-place-on/can-break adventure mode predicates
+ /**
+ * Gets set of materials what given item can destroy in {@link org.bukkit.GameMode#ADVENTURE}
+ *
+ * @return Set of materials
+ * @deprecated this API is unsupported and will be replaced, its usage may result in data loss related to place/destroy predicates.
+ */
+ @Deprecated(forRemoval = true, since = "1.14")
+ Set<org.bukkit.Material> getCanDestroy();
+
+ /**
+ * Sets set of materials what given item can destroy in {@link org.bukkit.GameMode#ADVENTURE}
+ *
+ * @param canDestroy Set of materials
+ * @deprecated this API is unsupported and will be replaced, its usage may result in data loss related to place/destroy predicates.
+ */
+ @Deprecated(forRemoval = true, since = "1.14")
+ void setCanDestroy(Set<org.bukkit.Material> canDestroy);
+
+ /**
+ * Gets set of materials where given item can be placed on in {@link org.bukkit.GameMode#ADVENTURE}
+ *
+ * @return Set of materials
+ * @deprecated this API is unsupported and will be replaced, its usage may result in data loss related to place/destroy predicates.
+ */
+ @Deprecated(forRemoval = true, since = "1.14")
+ Set<org.bukkit.Material> getCanPlaceOn();
+
+ /**
+ * Sets set of materials where given item can be placed on in {@link org.bukkit.GameMode#ADVENTURE}
+ *
+ * @param canPlaceOn Set of materials
+ * @deprecated this API is unsupported and will be replaced, its usage may result in data loss related to place/destroy predicates.
+ */
+ @Deprecated(forRemoval = true, since = "1.14")
+ void setCanPlaceOn(Set<org.bukkit.Material> canPlaceOn);
+
+ /**
+ * Gets the collection of namespaced keys that the item can destroy in {@link org.bukkit.GameMode#ADVENTURE}
+ *
+ * @return Set of {@link com.destroystokyo.paper.Namespaced}
+ * @deprecated this API is unsupported and will be replaced, its usage may result in data loss related to place/destroy predicates.
+ */
+ @Deprecated(forRemoval = true, since = "1.20.6")
+ @NotNull
+ Set<com.destroystokyo.paper.Namespaced> getDestroyableKeys();
+
+ /**
+ * Sets the collection of namespaced keys that the item can destroy in {@link org.bukkit.GameMode#ADVENTURE}
+ *
+ * @param canDestroy Collection of {@link com.destroystokyo.paper.Namespaced}
+ * @deprecated this API is unsupported and will be replaced, its usage may result in data loss related to place/destroy predicates.
+ */
+ @Deprecated(forRemoval = true, since = "1.20.6")
+ void setDestroyableKeys(@NotNull Collection<com.destroystokyo.paper.Namespaced> canDestroy);
+
+ /**
+ * Gets the collection of namespaced keys that the item can be placed on in {@link org.bukkit.GameMode#ADVENTURE}
+ *
+ * @return Set of {@link com.destroystokyo.paper.Namespaced}
+ * @deprecated this API is unsupported and will be replaced, its usage may result in data loss related to place/destroy predicates.
+ */
+ @NotNull
+ @Deprecated(forRemoval = true, since = "1.20.6")
+ Set<com.destroystokyo.paper.Namespaced> getPlaceableKeys();
+
+ /**
+ * Sets the set of namespaced keys that the item can be placed on in {@link org.bukkit.GameMode#ADVENTURE}
+ *
+ * @param canPlaceOn Collection of {@link com.destroystokyo.paper.Namespaced}
+ * @deprecated this API is unsupported and will be replaced, its usage may result in data loss related to place/destroy predicates.
+ */
+ @Deprecated(forRemoval = true, since = "1.20.6")
+ void setPlaceableKeys(@NotNull Collection<com.destroystokyo.paper.Namespaced> canPlaceOn);
+
+ /**
+ * Checks for the existence of any keys that the item can be placed on
+ *
+ * @return true if this item has placeable keys
+ * @deprecated this API is unsupported and will be replaced
+ */
+ @Deprecated(forRemoval = true, since = "1.20.6")
+ boolean hasPlaceableKeys();
+
+ /**
+ * Checks for the existence of any keys that the item can destroy
+ *
+ * @return true if this item has destroyable keys
+ * @deprecated this API is unsupported and will be replaced
+ */
+ @Deprecated(forRemoval = true, since = "1.20.6")
+ boolean hasDestroyableKeys();
+ // Paper end - Add an API for can-place-on/can-break adventure mode predicates
}