Change return type of ItemStack#editMeta to allow checking for successful vs non-successful edits

This commit is contained in:
Riley Park 2021-05-23 12:32:43 -07:00
parent 7aabe7d56b
commit 47d48790d1
No known key found for this signature in database
GPG key ID: D831AF236C834E45

View file

@ -5,10 +5,10 @@ Subject: [PATCH] ItemStack#editMeta
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index 0f8c593ae9bca46081f0b22c2d763a2699175398..08599c42e4f80a7b8306792c5af0c34aa598a7f6 100644 index 1bd9f7582bb907ff178fd110fdc92834885d1d78..3e2c08641edffcf00b230ad624685aaff30af0e5 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java --- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -542,6 +542,21 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor @@ -542,6 +542,24 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
return result.ensureServerConversions(); // Paper return result.ensureServerConversions(); // Paper
} }
@ -17,13 +17,16 @@ index 0f8c593ae9bca46081f0b22c2d763a2699175398..08599c42e4f80a7b8306792c5af0c34a
+ * Edits the {@link ItemMeta} of this stack. + * Edits the {@link ItemMeta} of this stack.
+ * + *
+ * @param consumer the meta consumer + * @param consumer the meta consumer
+ * @return {@code true} if the edit was successful, {@code false} otherwise
+ */ + */
+ public void editMeta(final @NotNull java.util.function.Consumer<? super ItemMeta> consumer) { + public boolean editMeta(final @NotNull java.util.function.Consumer<? super ItemMeta> consumer) {
+ final ItemMeta meta = this.getItemMeta(); + final ItemMeta meta = this.getItemMeta();
+ if (meta != null) { + if (meta != null) {
+ consumer.accept(meta); + consumer.accept(meta);
+ this.setItemMeta(meta); + this.setItemMeta(meta);
+ return true;
+ } + }
+ return false;
+ } + }
+ // Paper end + // Paper end
+ +