mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Fix NamespacedKey#equals not accepting other Key types (#8919)
This commit is contained in:
parent
47f0fe739b
commit
f042d06125
1 changed files with 69 additions and 0 deletions
|
@ -1061,6 +1061,38 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
/**
|
||||
* The namespace representing all inbuilt keys.
|
||||
@@ -0,0 +0,0 @@ public final class NamespacedKey {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
- int hash = 5;
|
||||
- hash = 47 * hash + this.namespace.hashCode();
|
||||
- hash = 47 * hash + this.key.hashCode();
|
||||
- return hash;
|
||||
+ // Paper start
|
||||
+ int result = this.namespace.hashCode();
|
||||
+ result = (31 * result) + this.key.hashCode();
|
||||
+ return result;
|
||||
+ // Paper end
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +0,0 @@ public final class NamespacedKey {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
- if (getClass() != obj.getClass()) {
|
||||
- return false;
|
||||
- }
|
||||
- final NamespacedKey other = (NamespacedKey) obj;
|
||||
- return this.namespace.equals(other.namespace) && this.key.equals(other.key);
|
||||
+ // Paper start
|
||||
+ if (!(obj instanceof net.kyori.adventure.key.Key key)) return false;
|
||||
+ return this.namespace.equals(key.namespace()) && this.key.equals(key.value());
|
||||
+ // Paper end
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +0,0 @@ public final class NamespacedKey {
|
||||
public static NamespacedKey fromString(@NotNull String key) {
|
||||
return fromString(key, null);
|
||||
}
|
||||
|
@ -4675,6 +4707,43 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
void setColor(@NotNull ChatColor color);
|
||||
|
||||
/**
|
||||
diff --git a/src/test/java/io/papermc/paper/adventure/KeyTest.java b/src/test/java/io/papermc/paper/adventure/KeyTest.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/test/java/io/papermc/paper/adventure/KeyTest.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import java.util.HashSet;
|
||||
+import java.util.Set;
|
||||
+import net.kyori.adventure.key.Key;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.junit.Test;
|
||||
+
|
||||
+import static org.junit.Assert.assertEquals;
|
||||
+import static org.junit.Assert.assertTrue;
|
||||
+
|
||||
+public class KeyTest {
|
||||
+
|
||||
+ @Test
|
||||
+ public void equalsTest() {
|
||||
+ Key key = new NamespacedKey("test", "key");
|
||||
+ Key key1 = Key.key("test", "key");
|
||||
+ assertEquals(key, key1);
|
||||
+ assertEquals(key1, key);
|
||||
+ }
|
||||
+
|
||||
+ @Test
|
||||
+ public void setTest() {
|
||||
+ Key key = new NamespacedKey("test", "key");
|
||||
+ Key key1 = Key.key("test", "key");
|
||||
+ Set<Key> set = new HashSet<>(Set.of(key));
|
||||
+ Set<Key> set1 = new HashSet<>(Set.of(key1));
|
||||
+ assertTrue(set.contains(key1));
|
||||
+ assertTrue(set1.contains(key));
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/test/java/org/bukkit/AnnotationTest.java
|
||||
|
|
Loading…
Reference in a new issue