From 636640607d5fb9642ae99a977cd32b9534ee02fc Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sun, 27 Nov 2011 02:45:08 +0000 Subject: [PATCH] Added utility methods to ItemStack to allow mass adding of enchantments By: Nathan Adams --- .../java/org/bukkit/inventory/ItemStack.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/paper-api/src/main/java/org/bukkit/inventory/ItemStack.java b/paper-api/src/main/java/org/bukkit/inventory/ItemStack.java index e1adce497f..f7f41b39c8 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/paper-api/src/main/java/org/bukkit/inventory/ItemStack.java @@ -205,7 +205,10 @@ public class ItemStack implements Serializable, ConfigurationSerializable { @Override public ItemStack clone() { - return new ItemStack(type, amount, durability); + ItemStack result = new ItemStack(type, amount, durability); + result.addEnchantments(getEnchantments()); + + return result; } @Override @@ -246,6 +249,20 @@ public class ItemStack implements Serializable, ConfigurationSerializable { return ImmutableMap.copyOf(enchantments); } + /** + * Adds the specified enchantments to this item stack. + *

+ * This method is the same as calling {@link #addEnchantment(org.bukkit.enchantments.Enchantment, int)} + * for each element of the map. + * + * @param enchantments Enchantments to add + */ + public void addEnchantments(Map enchantments) { + for (Map.Entry entry : getEnchantments().entrySet()) { + addEnchantment(entry.getKey(), entry.getValue()); + } + } + /** * Adds the specified {@link Enchantment} to this item stack. *

@@ -264,6 +281,20 @@ public class ItemStack implements Serializable, ConfigurationSerializable { addUnsafeEnchantment(ench, level); } + /** + * Adds the specified enchantments to this item stack in an unsafe manner. + *

+ * This method is the same as calling {@link #addUnsafeEnchantment(org.bukkit.enchantments.Enchantment, int)} + * for each element of the map. + * + * @param enchantments Enchantments to add + */ + public void addUnsafeEnchantments(Map enchantments) { + for (Map.Entry entry : getEnchantments().entrySet()) { + addUnsafeEnchantment(entry.getKey(), entry.getValue()); + } + } + /** * Adds the specified {@link Enchantment} to this item stack. *