aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower-stripped/net/minecraft/world/LockCode.java.patch
blob: a5241b88c921e2cf49bd9e298fbbbb45da124eb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
--- a/net/minecraft/world/LockCode.java
+++ b/net/minecraft/world/LockCode.java
@@ -4,6 +4,11 @@
 import net.minecraft.nbt.CompoundTag;
 import net.minecraft.world.item.ItemStack;
 
+// CraftBukkit start
+import org.bukkit.ChatColor;
+import org.bukkit.craftbukkit.util.CraftChatMessage;
+// CraftBukkit end
+
 @Immutable
 public class LockCode {
     public static final LockCode NO_LOCK = new LockCode("");
@@ -15,7 +21,19 @@
     }
 
     public boolean unlocksWith(ItemStack stack) {
-        return this.key.isEmpty() || !stack.isEmpty() && stack.hasCustomHoverName() && this.key.equals(stack.getHoverName().getString());
+        // CraftBukkit start - SPIGOT-6307: Check for color codes if the lock contains color codes
+        if (this.key.isEmpty()) return true;
+        if (!stack.isEmpty() && stack.hasCustomHoverName()) {
+            if (this.key.indexOf(ChatColor.COLOR_CHAR) == -1) {
+                // The lock key contains no color codes, so let's ignore colors in the item display name (vanilla Minecraft behavior):
+                return this.key.equals(stack.getHoverName().getString());
+            } else {
+                // The lock key contains color codes, so let's take them into account:
+                return this.key.equals(CraftChatMessage.fromComponent(stack.getHoverName()));
+            }
+        }
+        return false;
+        // CraftBukkit end
     }
 
     public void addToTag(CompoundTag nbt) {