diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/CachingTagResolver.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/CachingTagResolver.java index 66a28501c..efcc12c13 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/CachingTagResolver.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/CachingTagResolver.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.internal.serializer.ClaimConsumer; import net.kyori.adventure.text.minimessage.internal.serializer.SerializableResolver; @@ -78,4 +79,21 @@ public void handle(final @NotNull Component serializable, final @NotNull ClaimCo ((SerializableResolver) this.resolver).handle(serializable, consumer); } } + + @Override + public boolean equals(final @Nullable Object other) { + if (this == other) { + return true; + } + if (!(other instanceof CachingTagResolver)) { + return false; + } + final CachingTagResolver that = (CachingTagResolver) other; + return Objects.equals(this.resolver, that.resolver); + } + + @Override + public int hashCode() { + return Objects.hash(this.cache, this.resolver); + } } diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/MapTagResolver.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/MapTagResolver.java index 2ec5a2dc0..32696d844 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/MapTagResolver.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/MapTagResolver.java @@ -24,6 +24,7 @@ package net.kyori.adventure.text.minimessage.tag.resolver; import java.util.Map; +import java.util.Objects; import net.kyori.adventure.text.minimessage.tag.Tag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,4 +46,21 @@ public boolean contributeToMap(final @NotNull Map map) { map.putAll(this.tagMap); return true; } + + @Override + public boolean equals(final @Nullable Object other) { + if (this == other) { + return true; + } + if (!(other instanceof MapTagResolver)) { + return false; + } + final MapTagResolver that = (MapTagResolver) other; + return Objects.equals(this.tagMap, that.tagMap); + } + + @Override + public int hashCode() { + return Objects.hash(this.tagMap); + } } diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/SequentialTagResolver.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/SequentialTagResolver.java index 714c93625..c62c39580 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/SequentialTagResolver.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/resolver/SequentialTagResolver.java @@ -23,6 +23,7 @@ */ package net.kyori.adventure.text.minimessage.tag.resolver; +import java.util.Arrays; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.Context; import net.kyori.adventure.text.minimessage.ParsingException; @@ -89,4 +90,21 @@ public void handle(final @NotNull Component serializable, final @NotNull ClaimCo } } } + + @Override + public boolean equals(final @Nullable Object other) { + if (other == this) { + return true; + } + if (!(other instanceof SequentialTagResolver)) { + return false; + } + final SequentialTagResolver that = (SequentialTagResolver) other; + return Arrays.equals(this.resolvers, that.resolvers); + } + + @Override + public int hashCode() { + return Arrays.hashCode(this.resolvers); + } } diff --git a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/TagResolverTest.java b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/TagResolverTest.java index ac10c4f65..c3238b5a4 100644 --- a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/TagResolverTest.java +++ b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/tag/TagResolverTest.java @@ -138,6 +138,27 @@ void testValidTagName() { assertDoesNotThrow(() -> TagResolver.resolver("v_9_v", Tag.preProcessParsed("something"))); } + @Test + void testTagResolverEquality() { + final TagResolver first = TagResolver.resolver( + Placeholder.unparsed("single", "replace"), + TagResolver.standard(), + TagResolver.empty(), + TagResolver.resolver("tag", Tag.selfClosingInserting(Component.empty())) + ); + final TagResolver second = TagResolver.resolver( + Placeholder.unparsed("single", "replace"), + TagResolver.standard(), + TagResolver.empty(), + TagResolver.resolver("tag", Tag.selfClosingInserting(Component.empty())) + ); + + AbstractTest.dummyContext("equality test") + .deserialize("", first, second); + + assertEquals(first, second); + } + private static @NotNull Tag resolveForTest(final TagResolver resolver, final String tag) { try { final Context ctx = AbstractTest.dummyContext("help i shouldn't be seen");