2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
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.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
2023-12-05 20:54:55 +01:00
|
|
|
index 9861cd23b07f8fbacb1d125af835dee58c2debbb..e6a47317eb24fc65ed02a4d4f9c4b19b5abc920d 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
2023-12-05 20:54:55 +01:00
|
|
|
@@ -180,6 +180,23 @@ public final class ItemStack {
|
2021-06-12 02:57:04 +02:00
|
|
|
return this.getItem().getTooltipImage(this);
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ private static final java.util.Comparator<? super CompoundTag> enchantSorter = java.util.Comparator.comparing(o -> o.getString("id"));
|
2021-12-06 21:28:36 +01:00
|
|
|
+ private void processEnchantOrder(@Nullable CompoundTag tag) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (tag == null || !tag.contains("Enchantments", 9)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ ListTag list = tag.getList("Enchantments", 10);
|
|
|
|
+ if (list.size() < 2) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ //noinspection unchecked
|
2022-06-08 15:38:56 +02:00
|
|
|
+ list.sort((java.util.Comparator<? super net.minecraft.nbt.Tag>) enchantSorter); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
+ } catch (Exception ignored) {}
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
public ItemStack(ItemLike item) {
|
|
|
|
this(item, 1);
|
|
|
|
}
|
2023-12-05 20:54:55 +01:00
|
|
|
@@ -226,6 +243,7 @@ public final class ItemStack {
|
|
|
|
this.count = nbttagcompound.getByte("Count");
|
|
|
|
if (nbttagcompound.contains("tag", 10)) {
|
2021-11-23 13:15:10 +01:00
|
|
|
this.tag = nbttagcompound.getCompound("tag").copy();
|
2021-06-12 02:57:04 +02:00
|
|
|
+ this.processEnchantOrder(this.tag); // Paper
|
|
|
|
this.getItem().verifyTagAfterLoad(this.tag);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2021-06-12 02:57:04 +02:00
|
|
|
|
2023-12-05 20:54:55 +01:00
|
|
|
@@ -844,6 +862,7 @@ public final class ItemStack {
|
2021-12-06 21:28:36 +01:00
|
|
|
|
|
|
|
public void setTag(@Nullable CompoundTag nbt) {
|
|
|
|
this.tag = nbt;
|
|
|
|
+ this.processEnchantOrder(this.tag); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
if (this.getItem().canBeDepleted()) {
|
|
|
|
this.setDamageValue(this.getDamageValue());
|
|
|
|
}
|
2023-12-05 20:54:55 +01:00
|
|
|
@@ -1141,6 +1160,7 @@ public final class ItemStack {
|
2021-07-07 08:52:40 +02:00
|
|
|
ListTag nbttaglist = this.tag.getList("Enchantments", 10);
|
|
|
|
|
|
|
|
nbttaglist.add(EnchantmentHelper.storeEnchantment(EnchantmentHelper.getEnchantmentId(enchantment), (byte) level));
|
|
|
|
+ processEnchantOrder(this.tag); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEnchanted() {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
2023-12-06 21:28:59 +01:00
|
|
|
index 7278ac809eff364e8b838d63a2ec1291493869f8..7dd0c000fa7f363997178ffa6de7d39e17702348 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
2023-08-25 19:57:11 +02:00
|
|
|
@@ -188,28 +188,11 @@ public final class CraftItemStack extends ItemStack {
|
2021-06-11 14:02:28 +02:00
|
|
|
public void addUnsafeEnchantment(Enchantment ench, int level) {
|
2023-06-13 01:51:45 +02:00
|
|
|
Preconditions.checkArgument(ench != null, "Enchantment cannot be null");
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-06-12 02:57:04 +02:00
|
|
|
- if (!CraftItemStack.makeTag(this.handle)) {
|
2021-06-11 14:02:28 +02:00
|
|
|
- return;
|
|
|
|
- }
|
2021-06-12 02:57:04 +02:00
|
|
|
- ListTag list = CraftItemStack.getEnchantmentList(this.handle);
|
2021-06-11 14:02:28 +02:00
|
|
|
- if (list == null) {
|
|
|
|
- list = new ListTag();
|
2021-06-12 02:57:04 +02:00
|
|
|
- this.handle.getTag().put(ENCHANTMENTS.NBT, list);
|
2021-06-11 14:02:28 +02:00
|
|
|
- }
|
|
|
|
- int size = list.size();
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
|
- CompoundTag tag = (CompoundTag) list.get(i);
|
|
|
|
- String id = tag.getString(ENCHANTMENTS_ID.NBT);
|
2021-08-25 09:59:26 +02:00
|
|
|
- if (ench.getKey().equals(NamespacedKey.fromString(id))) {
|
2021-06-11 14:02:28 +02:00
|
|
|
- tag.putShort(ENCHANTMENTS_LVL.NBT, (short) level);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- CompoundTag tag = new CompoundTag();
|
|
|
|
- tag.putString(ENCHANTMENTS_ID.NBT, ench.getKey().toString());
|
|
|
|
- tag.putShort(ENCHANTMENTS_LVL.NBT, (short) level);
|
|
|
|
- list.add(tag);
|
|
|
|
+ // Paper start - Replace whole method
|
2021-06-12 02:57:04 +02:00
|
|
|
+ final ItemMeta itemMeta = this.getItemMeta();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ itemMeta.addEnchant(ench, level, true);
|
2021-06-12 02:57:04 +02:00
|
|
|
+ this.setItemMeta(itemMeta);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
static boolean makeTag(net.minecraft.world.item.ItemStack item) {
|
2023-12-06 21:28:59 +01:00
|
|
|
@@ -242,50 +225,22 @@ public final class CraftItemStack extends ItemStack {
|
2021-06-11 14:02:28 +02:00
|
|
|
public int removeEnchantment(Enchantment ench) {
|
2023-06-13 01:51:45 +02:00
|
|
|
Preconditions.checkArgument(ench != null, "Enchantment cannot be null");
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-06-12 02:57:04 +02:00
|
|
|
- ListTag list = CraftItemStack.getEnchantmentList(this.handle), listCopy;
|
2021-06-11 14:02:28 +02:00
|
|
|
- if (list == null) {
|
|
|
|
- return 0;
|
2023-03-23 22:57:03 +01:00
|
|
|
- }
|
2021-06-11 14:02:28 +02:00
|
|
|
- int index = Integer.MIN_VALUE;
|
|
|
|
- int level = Integer.MIN_VALUE;
|
|
|
|
- int size = list.size();
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
|
- CompoundTag enchantment = (CompoundTag) list.get(i);
|
|
|
|
- String id = enchantment.getString(ENCHANTMENTS_ID.NBT);
|
2021-08-25 09:59:26 +02:00
|
|
|
- if (ench.getKey().equals(NamespacedKey.fromString(id))) {
|
2021-06-11 14:02:28 +02:00
|
|
|
- index = i;
|
|
|
|
- level = 0xffff & enchantment.getShort(ENCHANTMENTS_LVL.NBT);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (index == Integer.MIN_VALUE) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- if (size == 1) {
|
2021-06-12 02:57:04 +02:00
|
|
|
- this.handle.getTag().remove(ENCHANTMENTS.NBT);
|
|
|
|
- if (this.handle.getTag().isEmpty()) {
|
|
|
|
- this.handle.setTag(null);
|
2021-06-11 14:02:28 +02:00
|
|
|
- }
|
|
|
|
- return level;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // This is workaround for not having an index removal
|
|
|
|
- listCopy = new ListTag();
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
|
- if (i != index) {
|
|
|
|
- listCopy.add(list.get(i));
|
|
|
|
- }
|
2023-03-23 22:57:03 +01:00
|
|
|
+ // Paper start - replace entire method
|
|
|
|
+ int level = getEnchantmentLevel(ench);
|
|
|
|
+ if (level > 0) {
|
|
|
|
+ final ItemMeta itemMeta = this.getItemMeta();
|
|
|
|
+ if (itemMeta == null) return 0;
|
|
|
|
+ itemMeta.removeEnchant(ench);
|
|
|
|
+ this.setItemMeta(itemMeta);
|
|
|
|
}
|
2021-06-12 02:57:04 +02:00
|
|
|
- this.handle.getTag().put(ENCHANTMENTS.NBT, listCopy);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<Enchantment, Integer> getEnchantments() {
|
2021-06-12 02:57:04 +02:00
|
|
|
- return CraftItemStack.getEnchantments(this.handle);
|
|
|
|
+ return this.hasItemMeta() ? this.getItemMeta().getEnchants() : ImmutableMap.<Enchantment, Integer>of(); // Paper - use Item Meta
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static Map<Enchantment, Integer> getEnchantments(net.minecraft.world.item.ItemStack item) {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2023-12-25 23:51:56 +01:00
|
|
|
index 9e74a28d77c4c91ad46750d924a3e0789683a875..89dac1d16a90717e6a99d41e8ea04810f78fdee4 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
@@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableList;
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
import com.google.common.collect.ImmutableMultimap;
|
|
|
|
import com.google.common.collect.LinkedHashMultimap;
|
|
|
|
+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-11-23 13:15:10 +01:00
|
|
|
@@ -23,6 +24,7 @@ import java.util.ArrayList;
|
2021-06-11 14:02:28 +02:00
|
|
|
import java.util.Arrays;
|
2021-11-23 13:15:10 +01:00
|
|
|
import java.util.Base64;
|
2021-06-11 14:02:28 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
+import java.util.Comparator; // Paper
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
2021-11-23 13:15:10 +01:00
|
|
|
@@ -33,6 +35,7 @@ import java.util.Map;
|
2021-06-11 14:02:28 +02:00
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Set;
|
|
|
|
+import java.util.TreeMap; // Paper
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.annotation.Nonnull;
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -276,7 +279,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-06-11 14:02:28 +02:00
|
|
|
private List<String> lore; // null and empty are two different states internally
|
|
|
|
private Integer customModelData;
|
|
|
|
private CompoundTag blockData;
|
|
|
|
- private Map<Enchantment, Integer> enchantments;
|
|
|
|
+ private EnchantmentMap enchantments; // Paper
|
|
|
|
private Multimap<Attribute, AttributeModifier> attributeModifiers;
|
|
|
|
private int repairCost;
|
|
|
|
private int hideFlag;
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -287,7 +290,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-06-11 14:02:28 +02:00
|
|
|
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
|
|
|
|
|
|
|
private CompoundTag internalTag;
|
2021-11-23 13:15:10 +01:00
|
|
|
- final Map<String, Tag> unhandledTags = new HashMap<String, Tag>(); // Visible for testing only
|
|
|
|
+ final Map<String, Tag> unhandledTags = new TreeMap<String, Tag>(); // Visible for testing only // Paper
|
2021-06-12 02:57:04 +02:00
|
|
|
private CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftMetaItem.DATA_TYPE_REGISTRY);
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
private int version = CraftMagicNumbers.INSTANCE.getDataVersion(); // Internal use only
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -308,7 +311,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-06-11 14:02:28 +02:00
|
|
|
this.blockData = meta.blockData;
|
|
|
|
|
2023-12-25 23:51:56 +01:00
|
|
|
if (meta.enchantments != null) {
|
2021-06-11 14:02:28 +02:00
|
|
|
- this.enchantments = new LinkedHashMap<Enchantment, Integer>(meta.enchantments);
|
|
|
|
+ this.enchantments = new EnchantmentMap(meta.enchantments); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meta.hasAttributeModifiers()) {
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -391,13 +394,13 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- static Map<Enchantment, Integer> buildEnchantments(CompoundTag tag, ItemMetaKey key) {
|
|
|
|
+ static EnchantmentMap buildEnchantments(CompoundTag tag, ItemMetaKey key) { // Paper
|
|
|
|
if (!tag.contains(key.NBT)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListTag ench = tag.getList(key.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
|
|
|
|
- Map<Enchantment, Integer> enchantments = new LinkedHashMap<Enchantment, Integer>(ench.size());
|
|
|
|
+ EnchantmentMap enchantments = new EnchantmentMap(); // Paper
|
|
|
|
|
|
|
|
for (int i = 0; i < ench.size(); i++) {
|
2023-10-27 01:34:58 +02:00
|
|
|
String id = ((CompoundTag) ench.get(i)).getString(CraftMetaItem.ENCHANTMENTS_ID.NBT);
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -550,13 +553,13 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-06-11 14:02:28 +02: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- Map<Enchantment, Integer> enchantments = new LinkedHashMap<Enchantment, Integer>(ench.size());
|
|
|
|
+ EnchantmentMap enchantments = new EnchantmentMap(); // Paper
|
|
|
|
for (Map.Entry<?, ?> entry : ench.entrySet()) {
|
|
|
|
// Doctor older enchants
|
|
|
|
String enchantKey = entry.getKey().toString();
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -832,14 +835,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<Enchantment, Integer> getEnchants() {
|
2023-10-27 01:34:58 +02:00
|
|
|
- return this.hasEnchants() ? ImmutableMap.copyOf(this.enchantments) : ImmutableMap.<Enchantment, Integer>of();
|
2021-06-12 02:57:04 +02:00
|
|
|
+ return this.hasEnchants() ? ImmutableSortedMap.copyOfSorted(this.enchantments) : ImmutableMap.<Enchantment, Integer>of(); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
|
2023-06-13 01:51:45 +02:00
|
|
|
Preconditions.checkArgument(ench != null, "Enchantment cannot be null");
|
2021-06-12 02:57:04 +02:00
|
|
|
if (this.enchantments == null) {
|
|
|
|
- this.enchantments = new LinkedHashMap<Enchantment, Integer>(4);
|
|
|
|
+ this.enchantments = new EnchantmentMap(); // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ignoreRestrictions || level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {
|
2023-12-25 23:51:56 +01:00
|
|
|
@@ -1226,7 +1229,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-06-11 14:02:28 +02:00
|
|
|
clone.customModelData = this.customModelData;
|
|
|
|
clone.blockData = this.blockData;
|
|
|
|
if (this.enchantments != null) {
|
|
|
|
- clone.enchantments = new LinkedHashMap<Enchantment, Integer>(this.enchantments);
|
|
|
|
+ clone.enchantments = new EnchantmentMap(this.enchantments); // Paper
|
|
|
|
}
|
|
|
|
if (this.hasAttributeModifiers()) {
|
|
|
|
clone.attributeModifiers = LinkedHashMultimap.create(this.attributeModifiers);
|
2023-12-25 23:51:56 +01:00
|
|
|
@@ -1468,4 +1471,22 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2021-06-12 02:57:04 +02:00
|
|
|
return CraftMetaItem.HANDLED_TAGS;
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ private static class EnchantmentMap extends TreeMap<Enchantment, Integer> {
|
|
|
|
+ private EnchantmentMap(Map<Enchantment, Integer> enchantments) {
|
|
|
|
+ this();
|
|
|
|
+ putAll(enchantments);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private EnchantmentMap() {
|
|
|
|
+ super(Comparator.comparing(o -> o.getKey().toString()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public EnchantmentMap clone() {
|
|
|
|
+ return (EnchantmentMap) super.clone();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
}
|