Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
Fix ItemStack.removeEnchantment returning wrong value
Dieser Commit ist enthalten in:
Ursprung
aea67db7a0
Commit
b78002eeba
@ -1,4 +1,4 @@
|
||||
From 841254f7471189b0be7020ad4f65eea1c697d2c1 Mon Sep 17 00:00:00 2001
|
||||
From bac28e529e52e14d9d21ff4ac3d62e6e35079395 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
|
||||
@ -18,7 +18,7 @@ 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/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
|
||||
index 82d72ea15..5047a57e9 100644
|
||||
index 82d72ea158..5047a57e9b 100644
|
||||
--- a/src/main/java/net/minecraft/server/ItemStack.java
|
||||
+++ b/src/main/java/net/minecraft/server/ItemStack.java
|
||||
@@ -57,6 +57,22 @@ public final class ItemStack {
|
||||
@ -69,7 +69,7 @@ index 82d72ea15..5047a57e9 100644
|
||||
|
||||
public boolean hasEnchantments() {
|
||||
diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java
|
||||
index ca9eb2f3b..576c3b714 100644
|
||||
index ca9eb2f3b2..576c3b7141 100644
|
||||
--- a/src/main/java/net/minecraft/server/NBTTagList.java
|
||||
+++ b/src/main/java/net/minecraft/server/NBTTagList.java
|
||||
@@ -14,6 +14,12 @@ public class NBTTagList extends NBTBase {
|
||||
@ -86,7 +86,7 @@ index ca9eb2f3b..576c3b714 100644
|
||||
|
||||
public NBTTagList() {}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
index fb1dc542d..cdf16e15a 100644
|
||||
index fb1dc542dd..8ffe18b092 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
@@ -4,6 +4,7 @@ import static org.bukkit.craftbukkit.inventory.CraftMetaItem.ENCHANTMENTS;
|
||||
@ -131,7 +131,7 @@ index fb1dc542d..cdf16e15a 100644
|
||||
}
|
||||
|
||||
static boolean makeTag(net.minecraft.server.ItemStack item) {
|
||||
@@ -221,66 +205,34 @@ public final class CraftItemStack extends ItemStack {
|
||||
@@ -221,66 +205,31 @@ public final class CraftItemStack extends ItemStack {
|
||||
|
||||
@Override
|
||||
public boolean containsEnchantment(Enchantment ench) {
|
||||
@ -156,7 +156,13 @@ index fb1dc542d..cdf16e15a 100644
|
||||
- NBTTagList list = getEnchantmentList(handle), listCopy;
|
||||
- if (list == null) {
|
||||
- return 0;
|
||||
- }
|
||||
+ // Paper start - replace entire method
|
||||
+ final ItemMeta itemMeta = getItemMeta();
|
||||
+ int level = itemMeta.getEnchantLevel(ench);
|
||||
+ if (level > 0) {
|
||||
+ itemMeta.removeEnchant(ench);
|
||||
+ setItemMeta(itemMeta);
|
||||
}
|
||||
- int index = Integer.MIN_VALUE;
|
||||
- int level = Integer.MIN_VALUE;
|
||||
- int size = list.size();
|
||||
@ -178,17 +184,9 @@ index fb1dc542d..cdf16e15a 100644
|
||||
- handle.getTag().remove(ENCHANTMENTS.NBT);
|
||||
- if (handle.getTag().isEmpty()) {
|
||||
- handle.setTag(null);
|
||||
+ // Paper start - replace entire method, maintain backwards compat of returning previous level.
|
||||
+ final ItemMeta itemMeta = getItemMeta();
|
||||
+ final Iterator<Enchantment> iterator = itemMeta.getEnchants().keySet().iterator();
|
||||
+ for (int i = 0; iterator.hasNext(); i++) {
|
||||
+ if (iterator.next().equals(ench)) {
|
||||
+ itemMeta.removeEnchant(ench);
|
||||
+ setItemMeta(itemMeta);
|
||||
+ return i;
|
||||
}
|
||||
- }
|
||||
- return level;
|
||||
}
|
||||
- }
|
||||
-
|
||||
- // This is workaround for not having an index removal
|
||||
- listCopy = new NBTTagList();
|
||||
@ -199,9 +197,8 @@ index fb1dc542d..cdf16e15a 100644
|
||||
- }
|
||||
- handle.getTag().set(ENCHANTMENTS.NBT, listCopy);
|
||||
-
|
||||
- return level;
|
||||
return level;
|
||||
+ // Paper end
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -212,7 +209,7 @@ index fb1dc542d..cdf16e15a 100644
|
||||
|
||||
static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.ItemStack item) {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
index c743ae066..0cdc8007a 100644
|
||||
index c743ae066e..0cdc8007a4 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
@@ -6,13 +6,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -1,4 +1,4 @@
|
||||
From b2a0e9a92477aef7fad217ffc07a0bb21030249d Mon Sep 17 00:00:00 2001
|
||||
From 90513890f66b8cb80477f1ad750c5523edbda60a Mon Sep 17 00:00:00 2001
|
||||
From: Zach Brown <zach.brown@destroystokyo.com>
|
||||
Date: Sat, 27 Jan 2018 17:04:14 -0500
|
||||
Subject: [PATCH] Add ArmorStand Item Meta
|
||||
@ -13,7 +13,7 @@ starting point for future additions in this area.
|
||||
Fixes GH-559
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
index c2f26577c..851960afb 100644
|
||||
index c2f26577c7..851960afbb 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
||||
@@ -96,6 +96,8 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
@ -26,10 +26,10 @@ index c2f26577c..851960afb 100644
|
||||
case CHEST:
|
||||
case TRAPPED_CHEST:
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
index cdf16e15a..aa99254ff 100644
|
||||
index 8ffe18b092..49576e6653 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||
@@ -307,6 +307,8 @@ public final class CraftItemStack extends ItemStack {
|
||||
@@ -304,6 +304,8 @@ public final class CraftItemStack extends ItemStack {
|
||||
return new CraftMetaSpawnEgg(item.getTag());
|
||||
case KNOWLEDGE_BOOK:
|
||||
return new CraftMetaKnowledgeBook(item.getTag());
|
||||
@ -40,7 +40,7 @@ index cdf16e15a..aa99254ff 100644
|
||||
case TRAPPED_CHEST:
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java
|
||||
new file mode 100644
|
||||
index 000000000..dc372f6db
|
||||
index 0000000000..dc372f6db1
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java
|
||||
@@ -0,0 +1,305 @@
|
||||
@ -350,7 +350,7 @@ index 000000000..dc372f6db
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
index 0cdc8007a..2ab4a1cf4 100644
|
||||
index 0cdc8007a4..2ab4a1cf41 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
||||
@@ -129,6 +129,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
@ -379,7 +379,7 @@ index 0cdc8007a..2ab4a1cf4 100644
|
||||
}
|
||||
return HANDLED_TAGS;
|
||||
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
|
||||
index 1f537d584..a29731f1d 100644
|
||||
index 1f537d5844..a29731f1d1 100644
|
||||
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
|
||||
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
|
||||
@@ -5,6 +5,8 @@ import static org.hamcrest.Matchers.*;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren