Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
b68b282439
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Warning: this commit contains more mapping changes from upstream, As always, ensure that you have working backups and test this build before deployment; Developers working on paper will, yet again, need to delete their work/Minecraft/1.13.2 folder Bukkit Changes: 7fca5fd4 SPIGOT-4558: Preserve user order in the face of copied defaults in configurations 15c9b1eb Ignore spurious slot IDs sent by client, e.g. in enchanting tables 5d2a10c5 SPIGOT-3747: Add API for force loaded chunks d6dd2bb3 SPIGOT-3538: Add getHitBlockFace for ProjectileHitEvent 771db4aa SPIGOT-794: Call EntityPlaceEvent for Minecart placement 55462509 Add InventoryView#getSlotType 2f3ce5b6 Remove EntityTransformEvent and CustomItemTagContainer from draft API f04ad7b6 Make ProjectileLaunchEvent extend EntitySpawnEvent ccb85808 Define EntitySpawnEvent b8cc3ebe Add PlayerItemDamageEvent 184a495d Ease ClassLoader Deadlocks Where Possible 11ac4728 Expand Boolean Prompt Values in Conversation API aae62d51 Added getAllSessionData() to the Conversation API. 9290ff91 Add InventoryView#getInventory API 995e530f Add API to get / set base arrow damage CraftBukkit Changes:c4a67eed
SPIGOT-4556: Fix plugins closing inventory during drop events5be2ddcb
Replace version constants with methods to prevent compiler inlininga5b9c7b3
Use API method to create offset command completions2bc7d1df
SPIGOT-3747: Add API for force loaded chunksa408f375
SPIGOT-3538: Add getHitBlockFace for ProjectileHitEventb54b9409
SPIGOT-2864: Make Arrow / Item setTicksLived behave like FallingBlock79ded7a8
SPIGOT-1811: Death message not shown on respawn screenb4a4f15d
SPIGOT-943: InventoryCloseEvent called on death regardless of open inventory0afed592
SPIGOT-794: Call EntityPlaceEvent for Minecart placement2b2d084a
Add InventoryView#getSlotType01a9959a
Do not use deprecated ItemSpawnEvent constructor9642498d
SPIGOT-4547: Call EntitySpawnEvent as general spawn fallback event963f4a5f
Add PlayerItemDamageEvent63db0445
Add API to get / set base arrow damage531c25d7
Add CraftMagicNumbers.MAPPINGS_VERSION for use by NMS pluginsd05c8b14
Mappings Updatebd36e200
SPIGOT-4551: Ignore invalid attribute modifier slots Spigot Changes: 518206a1 Remove redundant trove depend 1959ad21 MC-11211,SPIGOT-4552: Fix placing double slabs at y = 255 29ab5e43 SPIGOT-3661: Allow arguments in restart-script 7cc46316 SPIGOT-852: Growth modifiers for beetroots, potatoes, carrots 82e117e1 Squelch "fatal: Resolve operation not in progress" message 0a1a68e7 Mappings Update & Patch Rebuild
335 Zeilen
12 KiB
Diff
335 Zeilen
12 KiB
Diff
From 830ac878de07dc95bcef19e838d0d5bf78986b47 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 00000000..2baf58b7
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/Namespaced.java
|
|
@@ -0,0 +1,36 @@
|
|
+package com.destroystokyo.paper;
|
|
+
|
|
+/**
|
|
+ * 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.
|
|
+ */
|
|
+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
|
|
+ */
|
|
+ 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
|
|
+ */
|
|
+ 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 00000000..89949827
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/NamespacedTag.java
|
|
@@ -0,0 +1,138 @@
|
|
+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;
|
|
+
|
|
+/**
|
|
+ * 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
|
|
+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(String namespace, 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(Plugin plugin, 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);
|
|
+ }
|
|
+
|
|
+ public String getNamespace() {
|
|
+ return namespace;
|
|
+ }
|
|
+
|
|
+ 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
|
|
+ */
|
|
+ public static NamespacedTag minecraft(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 fe8d3468..074769c1 100644
|
|
--- a/src/main/java/org/bukkit/NamespacedKey.java
|
|
+++ b/src/main/java/org/bukkit/NamespacedKey.java
|
|
@@ -17,7 +17,7 @@ import org.bukkit.plugin.Plugin;
|
|
* underscores, hyphens, and forward slashes.
|
|
*
|
|
*/
|
|
-public final class NamespacedKey {
|
|
+public final class NamespacedKey implements com.destroystokyo.paper.Namespaced { // Paper - implement namespaced
|
|
|
|
/**
|
|
* The namespace representing all inbuilt keys.
|
|
@@ -81,10 +81,12 @@ public final class NamespacedKey {
|
|
Preconditions.checkArgument(string.length() < 256, "NamespacedKey must be less than 256 characters (%s)", string);
|
|
}
|
|
|
|
+ @Override // Paper
|
|
public String getNamespace() {
|
|
return namespace;
|
|
}
|
|
|
|
+ @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 4d0351c4..03e3cfd4 100644
|
|
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
|
|
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
|
|
@@ -82,13 +82,13 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable {
|
|
* <p>
|
|
* Plugins should check if hasLore() returns <code>true</code> before
|
|
* calling this method.
|
|
- *
|
|
+ *
|
|
* @return a list of lore that is set
|
|
*/
|
|
List<String> getLore();
|
|
|
|
/**
|
|
- * Sets the lore for this item.
|
|
+ * Sets the lore for this item.
|
|
* Removes lore when given null.
|
|
*
|
|
* @param lore the lore that will be set
|
|
@@ -119,7 +119,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable {
|
|
int getEnchantLevel(Enchantment ench);
|
|
|
|
/**
|
|
- * Returns a copy the enchantments in this ItemMeta. <br>
|
|
+ * Returns a copy the enchantments in this ItemMeta. <br>
|
|
* Returns an empty map if none.
|
|
*
|
|
* @return An immutable copy of the enchantments
|
|
@@ -363,4 +363,83 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable {
|
|
|
|
Spigot spigot();
|
|
// Spigot end
|
|
+ // Paper start - Add an API for CanPlaceOn and CanDestroy NBT values
|
|
+ /**
|
|
+ * Gets set of materials what given item can destroy in {@link org.bukkit.GameMode#ADVENTURE}
|
|
+ *
|
|
+ * @return Set of materials
|
|
+ * @deprecated Minecraft does not limit this to the material enum, Use {@link #getDestroyableKeys()} as a replacement
|
|
+ */
|
|
+ @Deprecated
|
|
+ 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 Minecraft does not limit this to the material enum, Use {@link #setDestroyableKeys(Collection)} as a replacement
|
|
+ */
|
|
+ @Deprecated
|
|
+ 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 Minecraft does not limit this to the material enum, Use {@link #getPlaceableKeys()} as a replacement
|
|
+ */
|
|
+ @Deprecated
|
|
+ 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 Minecraft does not limit this to the material enum, Use {@link #setPlaceableKeys(Collection)} as a replacement
|
|
+ */
|
|
+ @Deprecated
|
|
+ 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}
|
|
+ */
|
|
+ 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}
|
|
+ */
|
|
+ void setDestroyableKeys(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}
|
|
+ */
|
|
+ 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}
|
|
+ */
|
|
+ void setPlaceableKeys(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
|
|
+ */
|
|
+ boolean hasPlaceableKeys();
|
|
+
|
|
+ /**
|
|
+ * Checks for the existence of any keys that the item can destroy
|
|
+ *
|
|
+ * @return true if this item has destroyable keys
|
|
+ */
|
|
+ boolean hasDestroyableKeys();
|
|
+ // Paper end
|
|
}
|
|
--
|
|
2.20.1
|
|
|