Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 12:30:06 +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.
Dieser Commit ist enthalten in:
Ursprung
1a7e5a75ae
Commit
acd637d48b
@ -106,8 +106,8 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage
|
|||||||
public CraftMetaEnchantedBook clone() {
|
public CraftMetaEnchantedBook clone() {
|
||||||
CraftMetaEnchantedBook meta = (CraftMetaEnchantedBook) super.clone();
|
CraftMetaEnchantedBook meta = (CraftMetaEnchantedBook) super.clone();
|
||||||
|
|
||||||
if (hasStoredEnchants()) {
|
if (this.enchantments != null) {
|
||||||
meta.enchantments = new HashMap<Enchantment, Integer>(enchantments);
|
meta.enchantments = new HashMap<Enchantment, Integer>(this.enchantments);
|
||||||
}
|
}
|
||||||
|
|
||||||
return meta;
|
return meta;
|
||||||
|
@ -490,7 +490,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
@Override
|
@Override
|
||||||
public CraftMetaItem clone() {
|
public CraftMetaItem clone() {
|
||||||
try {
|
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) {
|
} catch (CloneNotSupportedException e) {
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
}
|
}
|
||||||
|
@ -117,8 +117,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
|||||||
@Override
|
@Override
|
||||||
public CraftMetaPotion clone() {
|
public CraftMetaPotion clone() {
|
||||||
CraftMetaPotion clone = (CraftMetaPotion) super.clone();
|
CraftMetaPotion clone = (CraftMetaPotion) super.clone();
|
||||||
if (hasCustomEffects()) {
|
if (this.customEffects != null) {
|
||||||
clone.customEffects = new ArrayList<PotionEffect>(customEffects);
|
clone.customEffects = new ArrayList<PotionEffect>(this.customEffects);
|
||||||
}
|
}
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren