mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-19 05:31:32 +01:00
Added utility methods to ItemStack to allow mass adding of enchantments
By: Nathan Adams <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
868b48c82c
commit
636640607d
1 changed files with 32 additions and 1 deletions
|
@ -205,7 +205,10 @@ public class ItemStack implements Serializable, ConfigurationSerializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack clone() {
|
public ItemStack clone() {
|
||||||
return new ItemStack(type, amount, durability);
|
ItemStack result = new ItemStack(type, amount, durability);
|
||||||
|
result.addEnchantments(getEnchantments());
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -246,6 +249,20 @@ public class ItemStack implements Serializable, ConfigurationSerializable {
|
||||||
return ImmutableMap.copyOf(enchantments);
|
return ImmutableMap.copyOf(enchantments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Adds the specified {@link Enchantment} to this item stack.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -264,6 +281,20 @@ public class ItemStack implements Serializable, ConfigurationSerializable {
|
||||||
addUnsafeEnchantment(ench, level);
|
addUnsafeEnchantment(ench, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Adds the specified {@link Enchantment} to this item stack.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
Loading…
Add table
Reference in a new issue