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() {
|
||||
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;
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren