diff options
author | Nathan Adams <dinnerbone@dinnerbone.com> | 2011-11-27 02:45:08 +0000 |
---|---|---|
committer | Nathan Adams <dinnerbone@dinnerbone.com> | 2011-11-27 02:45:08 +0000 |
commit | 693dfdbe8fa16a5cb4836ec87765e5e08e825199 (patch) | |
tree | 25dc9524dbab17a126344eeb5052cceaed22a54d | |
parent | 24804f641924fa212705355a852c3624d6af65d0 (diff) | |
download | bukkit-693dfdbe8fa16a5cb4836ec87765e5e08e825199.tar bukkit-693dfdbe8fa16a5cb4836ec87765e5e08e825199.tar.gz bukkit-693dfdbe8fa16a5cb4836ec87765e5e08e825199.tar.lz bukkit-693dfdbe8fa16a5cb4836ec87765e5e08e825199.tar.xz bukkit-693dfdbe8fa16a5cb4836ec87765e5e08e825199.zip |
Added utility methods to ItemStack to allow mass adding of enchantments
-rw-r--r-- | src/main/java/org/bukkit/inventory/ItemStack.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java index e1adce49..f7f41b39 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/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 @@ -247,6 +250,20 @@ public class ItemStack implements Serializable, ConfigurationSerializable { } /** + * Adds the specified enchantments to this item stack. + * <p> + * 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<Enchantment, Integer> enchantments) { + for (Map.Entry<Enchantment, Integer> entry : getEnchantments().entrySet()) { + addEnchantment(entry.getKey(), entry.getValue()); + } + } + + /** * Adds the specified {@link Enchantment} to this item stack. * <p> * If this item stack already contained the given enchantment (at any level), it will be replaced. @@ -265,6 +282,20 @@ public class ItemStack implements Serializable, ConfigurationSerializable { } /** + * Adds the specified enchantments to this item stack in an unsafe manner. + * <p> + * 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<Enchantment, Integer> enchantments) { + for (Map.Entry<Enchantment, Integer> entry : getEnchantments().entrySet()) { + addUnsafeEnchantment(entry.getKey(), entry.getValue()); + } + } + + /** * Adds the specified {@link Enchantment} to this item stack. * <p> * If this item stack already contained the given enchantment (at any level), it will be replaced. |