diff --git a/api/src/main/java/net/kyori/adventure/text/Component.java b/api/src/main/java/net/kyori/adventure/text/Component.java index 48caeee6f..2008d57e9 100644 --- a/api/src/main/java/net/kyori/adventure/text/Component.java +++ b/api/src/main/java/net/kyori/adventure/text/Component.java @@ -1297,8 +1297,10 @@ default boolean contains(final @NonNull Component that) { * Prevents a cycle between this component and the provided component. * * @param that the other component + * @deprecated for removal since 4.7.0, with no replacement - this method is not necessary due to the fact {@code Component}s are immutable * @since 4.0.0 */ + @Deprecated default void detectCycle(final @NonNull Component that) { if(that.contains(this)) { throw new IllegalStateException("Component cycle detected between " + this + " and " + that); @@ -1598,13 +1600,7 @@ default boolean hasDecoration(final @NonNull TextDecoration decoration) { */ @Contract(pure = true) default @NonNull Component hoverEvent(final @Nullable HoverEventSource source) { - final HoverEvent event = HoverEventSource.unbox(source); - if(event != null) { - if(event.action().type().isAssignableFrom(Component.class)) { - this.detectCycle((Component) event.value()); // detect cycle before modifying - } - } - return this.style(this.style().hoverEvent(event)); + return this.style(this.style().hoverEvent(source)); } /** diff --git a/api/src/main/java/net/kyori/adventure/text/ScopedComponent.java b/api/src/main/java/net/kyori/adventure/text/ScopedComponent.java index ec1a416c2..79890b2f0 100644 --- a/api/src/main/java/net/kyori/adventure/text/ScopedComponent.java +++ b/api/src/main/java/net/kyori/adventure/text/ScopedComponent.java @@ -75,7 +75,6 @@ public interface ScopedComponent extends Component { @SuppressWarnings("unchecked") default @NonNull C append(final @NonNull Component component) { if(component == Component.empty()) return (C) this; - this.detectCycle(component); // detect cycle before modifying final List oldChildren = this.children(); return this.children(AbstractComponent.addOne(oldChildren, component)); } diff --git a/api/src/test/java/net/kyori/adventure/text/AbstractComponentTest.java b/api/src/test/java/net/kyori/adventure/text/AbstractComponentTest.java index e8e65f113..3df50d9bd 100644 --- a/api/src/test/java/net/kyori/adventure/text/AbstractComponentTest.java +++ b/api/src/test/java/net/kyori/adventure/text/AbstractComponentTest.java @@ -46,9 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; abstract class AbstractComponentTest & ScopedComponent, B extends ComponentBuilder> { abstract B builder(); @@ -72,15 +70,6 @@ void testChildren() { assertThat(c1.children()).containsExactly(child).inOrder(); } - @Test - void testCycleSelf() { - assertThrows(IllegalStateException.class, () -> { - final Component component = this.buildOne(); - component.append(component); - fail("A component was added to itself"); - }); - } - @Test void testDecorations() { Component component = this.buildOne(); @@ -336,32 +325,6 @@ void testBasicEquals() { .testEquals(); } - @Test - void testCycleHoverRoot() { - assertThrows(IllegalStateException.class, () -> { - final Component hoverComponent = Component.text("hover"); - final Component component = this.builder() - .hoverEvent(HoverEvent.showText(hoverComponent)) - .build(); - // component's hover event value is hoverComponent, we should not be able to add it - hoverComponent.append(component); - fail("A component was added to itself"); - }); - } - - @Test - void testCycleHoverChild() { - assertThrows(IllegalStateException.class, () -> { - final Component hoverComponent = Component.text("hover child"); - final Component component = this.builder() - .hoverEvent(HoverEvent.showText(Component.text("hover").append(hoverComponent))) - .build(); - // component's hover event value contains hoverComponent, we should not be able to add it - hoverComponent.append(component); - fail("A component was added to itself"); - }); - } - // ----------------- // ---- Builder ---- // -----------------