mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 11:44:19 +01:00
Properly copy collection references in ItemMeta.clone(). Fixes BUKKIT-3913
When cloning an item, all references are copied to the new item. For collections, this makes internal changes become visible in both the old and new items. In CraftMetaItem, clone was not making copies of the appropriate collections and has been fixed for non-null values. In CraftMetaEnchantedBook and CraftMetaPotion, clone was using possible empty collection references and has been changed to explicitly null-check instead. By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
parent
3c6a12547b
commit
f84dc2d381
3 changed files with 12 additions and 5 deletions
|
@ -106,8 +106,8 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage
|
|||
public CraftMetaEnchantedBook clone() {
|
||||
CraftMetaEnchantedBook meta = (CraftMetaEnchantedBook) super.clone();
|
||||
|
||||
if (hasStoredEnchants()) {
|
||||
meta.enchantments = new HashMap<Enchantment, Integer>(enchantments);
|
||||
if (this.enchantments != null) {
|
||||
meta.enchantments = new HashMap<Enchantment, Integer>(this.enchantments);
|
||||
}
|
||||
|
||||
return meta;
|
||||
|
|
|
@ -490,7 +490,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||
@Override
|
||||
public CraftMetaItem clone() {
|
||||
try {
|
||||
return (CraftMetaItem) super.clone();
|
||||
CraftMetaItem clone = (CraftMetaItem) super.clone();
|
||||
if (this.lore != null) {
|
||||
clone.lore = new ArrayList<String>(this.lore);
|
||||
}
|
||||
if (this.enchantments != null) {
|
||||
clone.enchantments = new HashMap<Enchantment, Integer>(this.enchantments);
|
||||
}
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
|
|
|
@ -117,8 +117,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||
@Override
|
||||
public CraftMetaPotion clone() {
|
||||
CraftMetaPotion clone = (CraftMetaPotion) super.clone();
|
||||
if (hasCustomEffects()) {
|
||||
clone.customEffects = new ArrayList<PotionEffect>(customEffects);
|
||||
if (this.customEffects != null) {
|
||||
clone.customEffects = new ArrayList<PotionEffect>(this.customEffects);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue