From 9c5dd3b8379f135814b8e65776042d128bfaf1b4 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 20 Aug 2021 19:40:31 +1000 Subject: [PATCH] SPIGOT-6716: Preserve the order of stored enchantments of enchanted books. In some cases, differences in this order can result in item stack comparisons to fails. By: blablubbabc --- .../craftbukkit/inventory/CraftMetaEnchantedBook.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java index 943af29e5e..424098ebc7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java @@ -2,7 +2,7 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import net.minecraft.nbt.NBTTagCompound; import org.bukkit.Material; @@ -28,7 +28,7 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage CraftMetaEnchantedBook that = (CraftMetaEnchantedBook) meta; if (that.hasEnchants()) { - this.enchantments = new HashMap(that.enchantments); + this.enchantments = new LinkedHashMap(that.enchantments); } } @@ -105,7 +105,7 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage CraftMetaEnchantedBook meta = (CraftMetaEnchantedBook) super.clone(); if (this.enchantments != null) { - meta.enchantments = new HashMap(this.enchantments); + meta.enchantments = new LinkedHashMap(this.enchantments); } return meta; @@ -146,7 +146,7 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage @Override public boolean addStoredEnchant(Enchantment ench, int level, boolean ignoreRestrictions) { if (enchantments == null) { - enchantments = new HashMap(4); + enchantments = new LinkedHashMap(4); } if (ignoreRestrictions || level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {