2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2016-03-18 18:56:16 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Thu, 28 May 2015 23:00:19 -0400
|
|
|
|
Subject: [PATCH] Handle Item Meta Inconsistencies
|
|
|
|
|
|
|
|
First, Enchantment order would blow away seeing 2 items as the same,
|
|
|
|
however the Client forces enchantment list in a certain order, as well
|
|
|
|
as does the /enchant command. Anvils can insert it into forced order,
|
|
|
|
causing 2 same items to be considered different.
|
|
|
|
|
|
|
|
This change makes unhandled NBT Tags and Enchantments use a sorted tree map,
|
|
|
|
so they will always be in a consistent order.
|
|
|
|
|
|
|
|
Additionally, the old enchantment API was never updated when ItemMeta
|
|
|
|
was added, resulting in 2 different ways to modify an items enchantments.
|
|
|
|
|
|
|
|
For consistency, the old API methods now forward to use the
|
|
|
|
ItemMeta API equivalents, and should deprecate the old API's.
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
2021-06-11 06:29:15 +00:00
|
|
|
index f1a780768e3f4bdb43a7ca6d7850befefb71bf57..201ba7250b298f4a91bc45f5954f54ae557305f2 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
2020-06-25 11:00:35 +00:00
|
|
|
@@ -9,6 +9,8 @@ import com.mojang.serialization.Codec;
|
|
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
2018-07-15 01:53:17 +00:00
|
|
|
import java.text.DecimalFormat;
|
|
|
|
import java.text.DecimalFormatSymbols;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.Comparator;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Objects;
|
2020-06-25 11:00:35 +00:00
|
|
|
import java.util.Optional;
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -120,6 +122,23 @@ public final class ItemStack {
|
2020-06-25 11:00:35 +00:00
|
|
|
private ShapeDetectorBlock n;
|
|
|
|
private boolean o;
|
2019-12-11 02:43:21 +00:00
|
|
|
|
2017-12-19 22:56:13 +00:00
|
|
|
+ // Paper start
|
2018-07-15 01:53:17 +00:00
|
|
|
+ private static final java.util.Comparator<? super NBTTagCompound> enchantSorter = java.util.Comparator.comparing(o -> o.getString("id"));
|
2017-12-19 22:56:13 +00:00
|
|
|
+ private void processEnchantOrder(NBTTagCompound tag) {
|
2018-07-15 01:53:17 +00:00
|
|
|
+ if (tag == null || !tag.hasKeyOfType("Enchantments", 9)) {
|
2017-12-19 22:56:13 +00:00
|
|
|
+ return;
|
|
|
|
+ }
|
2018-07-15 01:53:17 +00:00
|
|
|
+ NBTTagList list = tag.getList("Enchantments", 10);
|
2017-12-19 22:56:13 +00:00
|
|
|
+ if (list.size() < 2) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ try {
|
2018-07-15 01:53:17 +00:00
|
|
|
+ //noinspection unchecked
|
|
|
|
+ list.sort((Comparator<? super NBTBase>) enchantSorter); // Paper
|
2017-12-19 22:56:13 +00:00
|
|
|
+ } catch (Exception ignored) {}
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2019-12-11 02:43:21 +00:00
|
|
|
+
|
2018-07-15 01:53:17 +00:00
|
|
|
public ItemStack(IMaterial imaterial) {
|
|
|
|
this(imaterial, 1);
|
2019-12-11 02:43:21 +00:00
|
|
|
}
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -162,6 +181,7 @@ public final class ItemStack {
|
2017-12-19 22:56:13 +00:00
|
|
|
if (nbttagcompound.hasKeyOfType("tag", 10)) {
|
|
|
|
// CraftBukkit start - make defensive copy as this data may be coming from the save thread
|
|
|
|
this.tag = (NBTTagCompound) nbttagcompound.getCompound("tag").clone();
|
|
|
|
+ processEnchantOrder(this.tag); // Paper
|
2020-06-25 11:00:35 +00:00
|
|
|
this.getItem().b(this.tag);
|
2018-07-15 01:53:17 +00:00
|
|
|
// CraftBukkit end
|
|
|
|
}
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -680,6 +700,7 @@ public final class ItemStack {
|
2018-06-29 04:55:29 +00:00
|
|
|
// Paper end
|
2017-12-19 22:56:13 +00:00
|
|
|
public void setTag(@Nullable NBTTagCompound nbttagcompound) {
|
|
|
|
this.tag = nbttagcompound;
|
|
|
|
+ processEnchantOrder(this.tag); // Paper
|
2019-12-17 22:39:07 +00:00
|
|
|
if (this.getItem().usesDurability()) {
|
2019-12-11 02:43:21 +00:00
|
|
|
this.setDamage(this.getDamage());
|
2019-12-17 22:39:07 +00:00
|
|
|
}
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -770,6 +791,7 @@ public final class ItemStack {
|
2018-08-26 18:11:49 +00:00
|
|
|
nbttagcompound.setString("id", String.valueOf(IRegistry.ENCHANTMENT.getKey(enchantment)));
|
2017-12-19 22:56:13 +00:00
|
|
|
nbttagcompound.setShort("lvl", (short) ((byte) i));
|
2019-04-26 01:24:00 +00:00
|
|
|
nbttaglist.add(nbttagcompound);
|
2017-12-19 22:56:13 +00:00
|
|
|
+ processEnchantOrder(nbttagcompound); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasEnchantments() {
|
2016-03-18 18:56:16 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
2021-03-16 07:19:45 +00:00
|
|
|
index 275b943a59ef28c831a068987e111e84ebba3bb7..7221ac52c9f66ae0af6f6cbf15c8d47f9c0291a0 100644
|
2016-03-18 18:56:16 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
2019-04-26 01:24:00 +00:00
|
|
|
@@ -178,28 +178,11 @@ public final class CraftItemStack extends ItemStack {
|
2016-03-18 18:56:16 +00:00
|
|
|
public void addUnsafeEnchantment(Enchantment ench, int level) {
|
|
|
|
Validate.notNull(ench, "Cannot add null enchantment");
|
|
|
|
|
|
|
|
- if (!makeTag(handle)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- NBTTagList list = getEnchantmentList(handle);
|
|
|
|
- if (list == null) {
|
|
|
|
- list = new NBTTagList();
|
|
|
|
- handle.getTag().set(ENCHANTMENTS.NBT, list);
|
|
|
|
- }
|
|
|
|
- int size = list.size();
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
|
- NBTTagCompound tag = (NBTTagCompound) list.get(i);
|
2018-07-15 01:53:17 +00:00
|
|
|
- String id = tag.getString(ENCHANTMENTS_ID.NBT);
|
|
|
|
- if (id.equals(ench.getKey().toString())) {
|
2016-03-18 18:56:16 +00:00
|
|
|
- tag.setShort(ENCHANTMENTS_LVL.NBT, (short) level);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- NBTTagCompound tag = new NBTTagCompound();
|
2018-07-15 01:53:17 +00:00
|
|
|
- tag.setString(ENCHANTMENTS_ID.NBT, ench.getKey().toString());
|
2016-03-18 18:56:16 +00:00
|
|
|
- tag.setShort(ENCHANTMENTS_LVL.NBT, (short) level);
|
|
|
|
- list.add(tag);
|
|
|
|
+ // Paper start - Replace whole method
|
|
|
|
+ final ItemMeta itemMeta = getItemMeta();
|
|
|
|
+ itemMeta.addEnchant(ench, level, true);
|
|
|
|
+ setItemMeta(itemMeta);
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
static boolean makeTag(net.minecraft.world.item.ItemStack item) {
|
2019-12-11 02:43:21 +00:00
|
|
|
@@ -216,66 +199,33 @@ public final class CraftItemStack extends ItemStack {
|
2016-03-18 18:56:16 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean containsEnchantment(Enchantment ench) {
|
|
|
|
- return getEnchantmentLevel(ench) > 0;
|
|
|
|
+ return hasItemMeta() && getItemMeta().hasEnchant(ench); // Paper - use meta
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnchantmentLevel(Enchantment ench) {
|
|
|
|
- Validate.notNull(ench, "Cannot find null enchantment");
|
|
|
|
- if (handle == null) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- return EnchantmentManager.getEnchantmentLevel(CraftEnchantment.getRaw(ench), handle);
|
2018-07-15 01:53:17 +00:00
|
|
|
+ return hasItemMeta() ? getItemMeta().getEnchantLevel(ench) : 0; // Paper - replace entire method with meta
|
2016-03-18 18:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int removeEnchantment(Enchantment ench) {
|
|
|
|
Validate.notNull(ench, "Cannot remove null enchantment");
|
2018-07-15 01:53:17 +00:00
|
|
|
|
2016-03-18 18:56:16 +00:00
|
|
|
- NBTTagList list = getEnchantmentList(handle), listCopy;
|
|
|
|
- if (list == null) {
|
|
|
|
- return 0;
|
2019-12-11 02:43:21 +00:00
|
|
|
- }
|
2016-03-18 18:56:16 +00:00
|
|
|
- int index = Integer.MIN_VALUE;
|
|
|
|
- int level = Integer.MIN_VALUE;
|
|
|
|
- int size = list.size();
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
|
- NBTTagCompound enchantment = (NBTTagCompound) list.get(i);
|
2018-07-15 01:53:17 +00:00
|
|
|
- String id = enchantment.getString(ENCHANTMENTS_ID.NBT);
|
|
|
|
- if (id.equals(ench.getKey().toString())) {
|
2016-03-18 18:56:16 +00:00
|
|
|
- index = i;
|
|
|
|
- level = 0xffff & enchantment.getShort(ENCHANTMENTS_LVL.NBT);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (index == Integer.MIN_VALUE) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- if (size == 1) {
|
|
|
|
- handle.getTag().remove(ENCHANTMENTS.NBT);
|
|
|
|
- if (handle.getTag().isEmpty()) {
|
|
|
|
- handle.setTag(null);
|
2018-08-04 05:13:10 +00:00
|
|
|
- }
|
2016-03-18 18:56:16 +00:00
|
|
|
- return level;
|
2018-08-04 05:13:10 +00:00
|
|
|
- }
|
2016-03-18 18:56:16 +00:00
|
|
|
-
|
|
|
|
- // This is workaround for not having an index removal
|
|
|
|
- listCopy = new NBTTagList();
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
|
- if (i != index) {
|
|
|
|
- listCopy.add(list.get(i));
|
|
|
|
- }
|
2019-12-11 02:43:21 +00:00
|
|
|
+ // Paper start - replace entire method
|
|
|
|
+ final ItemMeta itemMeta = getItemMeta();
|
|
|
|
+ int level = itemMeta.getEnchantLevel(ench);
|
|
|
|
+ if (level > 0) {
|
|
|
|
+ itemMeta.removeEnchant(ench);
|
|
|
|
+ setItemMeta(itemMeta);
|
|
|
|
}
|
2016-03-18 18:56:16 +00:00
|
|
|
- handle.getTag().set(ENCHANTMENTS.NBT, listCopy);
|
|
|
|
+ // Paper end
|
2019-12-11 02:43:21 +00:00
|
|
|
|
|
|
|
return level;
|
2016-03-18 18:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<Enchantment, Integer> getEnchantments() {
|
|
|
|
- return getEnchantments(handle);
|
|
|
|
+ return hasItemMeta() ? getItemMeta().getEnchants() : ImmutableMap.<Enchantment, Integer>of(); // Paper - use Item Meta
|
|
|
|
}
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
static Map<Enchantment, Integer> getEnchantments(net.minecraft.world.item.ItemStack item) {
|
2016-03-18 18:56:16 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2021-03-16 07:19:45 +00:00
|
|
|
index 7a11b2ddfa4244459253c918315aaab78ef2eb4a..57a6e66866ea82caccbbbfd55948a081f50f6bbe 100644
|
2016-03-18 18:56:16 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2019-08-17 03:26:58 +00:00
|
|
|
@@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableList;
|
2019-07-11 16:59:21 +00:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
import com.google.common.collect.ImmutableMultimap;
|
2019-08-17 03:26:58 +00:00
|
|
|
import com.google.common.collect.LinkedHashMultimap;
|
2019-07-11 16:59:21 +00:00
|
|
|
+import com.google.common.collect.ImmutableSortedMap; // Paper
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import com.google.common.collect.Multimap;
|
|
|
|
import com.google.common.collect.SetMultimap;
|
2021-01-01 04:03:19 +00:00
|
|
|
@@ -22,6 +23,7 @@ import java.lang.reflect.InvocationTargetException;
|
2019-12-11 02:43:21 +00:00
|
|
|
import java.util.ArrayList;
|
2019-04-26 01:24:00 +00:00
|
|
|
import java.util.Arrays;
|
2018-07-15 01:53:17 +00:00
|
|
|
import java.util.Collection;
|
2019-04-26 01:24:00 +00:00
|
|
|
+import java.util.Comparator; // Paper
|
2019-12-11 02:43:21 +00:00
|
|
|
import java.util.EnumSet;
|
2018-07-15 01:53:17 +00:00
|
|
|
import java.util.HashMap;
|
2018-09-21 15:29:17 +00:00
|
|
|
import java.util.Iterator;
|
2021-01-01 04:03:19 +00:00
|
|
|
@@ -32,6 +34,7 @@ import java.util.Map;
|
2019-04-26 01:24:00 +00:00
|
|
|
import java.util.NoSuchElementException;
|
2021-01-01 04:03:19 +00:00
|
|
|
import java.util.Objects;
|
2019-04-26 01:24:00 +00:00
|
|
|
import java.util.Set;
|
|
|
|
+import java.util.TreeMap; // Paper
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.annotation.Nonnull;
|
2020-07-01 06:11:46 +00:00
|
|
|
@@ -271,7 +274,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-01-01 04:03:19 +00:00
|
|
|
private List<String> lore; // null and empty are two different states internally
|
2019-04-26 01:24:00 +00:00
|
|
|
private Integer customModelData;
|
2019-07-11 16:59:21 +00:00
|
|
|
private NBTTagCompound blockData;
|
2016-03-18 18:56:16 +00:00
|
|
|
- private Map<Enchantment, Integer> enchantments;
|
|
|
|
+ private EnchantmentMap enchantments; // Paper
|
2018-09-21 15:29:17 +00:00
|
|
|
private Multimap<Attribute, AttributeModifier> attributeModifiers;
|
2016-03-18 18:56:16 +00:00
|
|
|
private int repairCost;
|
|
|
|
private int hideFlag;
|
2020-07-01 06:11:46 +00:00
|
|
|
@@ -282,7 +285,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2019-05-06 02:58:04 +00:00
|
|
|
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
2016-03-18 18:56:16 +00:00
|
|
|
|
2017-01-02 07:05:02 +00:00
|
|
|
private NBTTagCompound internalTag;
|
2016-03-18 18:56:16 +00:00
|
|
|
- private final Map<String, NBTBase> unhandledTags = new HashMap<String, NBTBase>();
|
|
|
|
+ private final Map<String, NBTBase> unhandledTags = new TreeMap<>(); // Paper
|
2020-03-02 19:13:59 +00:00
|
|
|
private CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
|
2016-03-18 18:56:16 +00:00
|
|
|
|
2019-04-26 01:24:00 +00:00
|
|
|
private int version = CraftMagicNumbers.INSTANCE.getDataVersion(); // Internal use only
|
2020-07-01 06:11:46 +00:00
|
|
|
@@ -303,7 +306,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2019-04-26 01:24:00 +00:00
|
|
|
this.blockData = meta.blockData;
|
2016-03-18 18:56:16 +00:00
|
|
|
|
|
|
|
if (meta.enchantments != null) { // Spigot
|
2019-04-03 03:27:20 +00:00
|
|
|
- this.enchantments = new LinkedHashMap<Enchantment, Integer>(meta.enchantments);
|
2016-03-18 18:56:16 +00:00
|
|
|
+ this.enchantments = new EnchantmentMap(meta.enchantments); // Paper
|
|
|
|
}
|
|
|
|
|
2018-09-21 15:29:17 +00:00
|
|
|
if (meta.hasAttributeModifiers()) {
|
2021-01-01 04:03:19 +00:00
|
|
|
@@ -386,13 +389,13 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2016-11-23 00:06:14 +00:00
|
|
|
}
|
2016-03-18 18:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
|
|
|
|
+ static EnchantmentMap buildEnchantments(NBTTagCompound tag, ItemMetaKey key) { // Paper
|
|
|
|
if (!tag.hasKey(key.NBT)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:49:47 +00:00
|
|
|
NBTTagList ench = tag.getList(key.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
|
2019-04-03 03:27:20 +00:00
|
|
|
- Map<Enchantment, Integer> enchantments = new LinkedHashMap<Enchantment, Integer>(ench.size());
|
2016-03-18 18:56:16 +00:00
|
|
|
+ EnchantmentMap enchantments = new EnchantmentMap(); // Paper
|
|
|
|
|
|
|
|
for (int i = 0; i < ench.size(); i++) {
|
2018-07-15 01:53:17 +00:00
|
|
|
String id = ((NBTTagCompound) ench.get(i)).getString(ENCHANTMENTS_ID.NBT);
|
2021-01-01 04:03:19 +00:00
|
|
|
@@ -545,13 +548,13 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2019-01-15 21:12:19 +00:00
|
|
|
}
|
2016-03-18 18:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- static Map<Enchantment, Integer> buildEnchantments(Map<String, Object> map, ItemMetaKey key) {
|
|
|
|
+ static EnchantmentMap buildEnchantments(Map<String, Object> map, ItemMetaKey key) { // Paper
|
|
|
|
Map<?, ?> ench = SerializableMeta.getObject(Map.class, map, key.BUKKIT, true);
|
|
|
|
if (ench == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-04-03 03:27:20 +00:00
|
|
|
- Map<Enchantment, Integer> enchantments = new LinkedHashMap<Enchantment, Integer>(ench.size());
|
2016-03-18 18:56:16 +00:00
|
|
|
+ EnchantmentMap enchantments = new EnchantmentMap(); // Paper
|
|
|
|
for (Map.Entry<?, ?> entry : ench.entrySet()) {
|
2017-06-26 00:26:00 +00:00
|
|
|
// Doctor older enchants
|
|
|
|
String enchantKey = entry.getKey().toString();
|
2021-02-21 19:45:33 +00:00
|
|
|
@@ -827,14 +830,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2016-03-18 18:56:16 +00:00
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2016-03-18 18:56:16 +00:00
|
|
|
public Map<Enchantment, Integer> getEnchants() {
|
|
|
|
- return hasEnchants() ? ImmutableMap.copyOf(enchantments) : ImmutableMap.<Enchantment, Integer>of();
|
|
|
|
+ return hasEnchants() ? ImmutableSortedMap.copyOfSorted(enchantments) : ImmutableMap.<Enchantment, Integer>of(); // Paper
|
|
|
|
}
|
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2016-03-18 18:56:16 +00:00
|
|
|
public boolean addEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
|
2017-06-30 23:13:06 +00:00
|
|
|
Validate.notNull(ench, "Enchantment cannot be null");
|
2016-03-18 18:56:16 +00:00
|
|
|
if (enchantments == null) {
|
2019-04-03 03:27:20 +00:00
|
|
|
- enchantments = new LinkedHashMap<Enchantment, Integer>(4);
|
2016-03-18 18:56:16 +00:00
|
|
|
+ enchantments = new EnchantmentMap(); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ignoreRestrictions || level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {
|
2021-02-21 19:45:33 +00:00
|
|
|
@@ -1215,7 +1218,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2019-04-26 01:24:00 +00:00
|
|
|
clone.customModelData = this.customModelData;
|
|
|
|
clone.blockData = this.blockData;
|
2016-03-18 18:56:16 +00:00
|
|
|
if (this.enchantments != null) {
|
2019-04-03 03:27:20 +00:00
|
|
|
- clone.enchantments = new LinkedHashMap<Enchantment, Integer>(this.enchantments);
|
2016-03-18 18:56:16 +00:00
|
|
|
+ clone.enchantments = new EnchantmentMap(this.enchantments); // Paper
|
|
|
|
}
|
2018-09-21 15:29:17 +00:00
|
|
|
if (this.hasAttributeModifiers()) {
|
2019-08-17 03:26:58 +00:00
|
|
|
clone.attributeModifiers = LinkedHashMultimap.create(this.attributeModifiers);
|
2021-02-21 19:45:33 +00:00
|
|
|
@@ -1447,4 +1450,22 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2019-12-11 02:43:21 +00:00
|
|
|
return HANDLED_TAGS;
|
2016-03-18 18:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-11 02:43:21 +00:00
|
|
|
+
|
2016-03-18 18:56:16 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ private static class EnchantmentMap extends TreeMap<Enchantment, Integer> {
|
|
|
|
+ private EnchantmentMap(Map<Enchantment, Integer> enchantments) {
|
|
|
|
+ this();
|
|
|
|
+ putAll(enchantments);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private EnchantmentMap() {
|
2018-07-15 01:53:17 +00:00
|
|
|
+ super(Comparator.comparing(o -> o.getKey().toString()));
|
2016-03-18 18:56:16 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public EnchantmentMap clone() {
|
|
|
|
+ return (EnchantmentMap) super.clone();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
2019-12-11 02:43:21 +00:00
|
|
|
}
|