Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions api/src/main/java/net/kyori/adventure/text/BuildableComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of adventure, licensed under the MIT License.
*
* Copyright (c) 2017-2025 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.text;

import net.kyori.adventure.util.Buildable;
import org.jetbrains.annotations.ApiStatus;

/**
* A component which may be built.
*
* @param <C> the component type
* @param <B> the builder type
* @since 4.0.0
* @deprecated For removal in 6.0, since 4.26 with no replacement. See instead {@link Component#toBuilder()}.
*/
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "6.0.0")
public sealed interface BuildableComponent<C extends Component, B extends ComponentBuilder<C, ?>> extends Buildable<B>, Component permits KeybindComponent, NBTComponent, ObjectComponent, ScoreComponent, SelectorComponent, TextComponent, TranslatableComponent {
/**
* Create a builder from this component.
*
* @return the builder
*/
@Override
B toBuilder();
}
3 changes: 2 additions & 1 deletion api/src/main/java/net/kyori/adventure/text/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
* @see LinearComponents
* @since 4.0.0
*/
public sealed interface Component extends ComponentBuilderApplicable, ComponentLike, HoverEventSource<Component>, StyleGetter, StyleSetter<Component> permits NBTComponent, ScopedComponent {
@SuppressWarnings("removal")
public sealed interface Component extends ComponentBuilderApplicable, ComponentLike, HoverEventSource<Component>, StyleGetter, StyleSetter<Component> permits BuildableComponent, ScopedComponent {
/**
* A predicate that checks equality of two {@code Component}s using {@link Objects#equals(Object, Object)}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
* @since 4.0.0
* @sinceMinecraft 1.12
*/
public sealed interface KeybindComponent extends ScopedComponent<KeybindComponent> permits KeybindComponentImpl {
@SuppressWarnings("removal")
public sealed interface KeybindComponent extends ScopedComponent<KeybindComponent>, BuildableComponent<KeybindComponent, KeybindComponent.Builder> permits KeybindComponentImpl {
/**
* Gets the keybind.
*
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/net/kyori/adventure/text/NBTComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
* @since 4.0.0
* @sinceMinecraft 1.14
*/
public sealed interface NBTComponent<C extends NBTComponent<C>> extends Component permits BlockNBTComponent, EntityNBTComponent, StorageNBTComponent {
@SuppressWarnings("removal")
public sealed interface NBTComponent<C extends NBTComponent<C>> extends BuildableComponent<C, NBTComponentBuilder<C, ?>> permits BlockNBTComponent, EntityNBTComponent, StorageNBTComponent {
/**
* The default value for {@link #interpret()}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
* @since 4.25.0
* @sinceMinecraft 1.21.9
*/
public sealed interface ObjectComponent extends ScopedComponent<ObjectComponent>, ObjectContentsLike permits ObjectComponentImpl {
@SuppressWarnings("removal")
public sealed interface ObjectComponent extends ScopedComponent<ObjectComponent>, BuildableComponent<ObjectComponent, ObjectComponent.Builder>, ObjectContentsLike permits ObjectComponentImpl {
/**
* Gets the contents of this object component.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
*
* @since 4.0.0
*/
public sealed interface ScoreComponent extends ScopedComponent<ScoreComponent> permits ScoreComponentImpl {
@SuppressWarnings("removal")
public sealed interface ScoreComponent extends ScopedComponent<ScoreComponent>, BuildableComponent<ScoreComponent, ScoreComponent.Builder> permits ScoreComponentImpl {
/**
* Gets the score name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
*
* @since 4.0.0
*/
public sealed interface SelectorComponent extends ScopedComponent<SelectorComponent> permits SelectorComponentImpl {
@SuppressWarnings("removal")
public sealed interface SelectorComponent extends ScopedComponent<SelectorComponent>, BuildableComponent<SelectorComponent, SelectorComponent.Builder> permits SelectorComponentImpl {
/**
* Gets the selector pattern.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
*
* @since 4.0.0
*/
public sealed interface TextComponent extends ScopedComponent<TextComponent> permits TextComponentImpl, VirtualComponent {
@SuppressWarnings("removal")
public sealed interface TextComponent extends ScopedComponent<TextComponent>, BuildableComponent<TextComponent, TextComponent.Builder> permits TextComponentImpl, VirtualComponent {
/**
* Gets the plain text content.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
* @see TranslationStore
* @since 4.0.0
*/
public sealed interface TranslatableComponent extends ScopedComponent<TranslatableComponent> permits TranslatableComponentImpl {
@SuppressWarnings("removal")
public sealed interface TranslatableComponent extends ScopedComponent<TranslatableComponent>, BuildableComponent<TranslatableComponent, TranslatableComponent.Builder> permits TranslatableComponentImpl {
/**
* Gets the translation key.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes

// Remove in 6.x.
// In 5.x, ComponentBuilder#build erased from Object to Component, causing NoSuchMethodError for 4.x-compiled clients.
// This adds a build-time classfile bridge for build():Object while keeping the 5.x source API strongly typed.
// In 5.x, ComponentBuilder#build erased from Object/BuildableComponent to Component,
// causing NoSuchMethodError for 4.x-compiled clients.
// This adds build-time classfile bridges for the legacy return types while keeping the 5.x source API strongly typed.

abstract class PatchComponentBuilderAbi : DefaultTask() {
@get:InputFile
Expand All @@ -28,18 +29,44 @@ abstract class PatchComponentBuilderAbi : DefaultTask() {
val writer = ClassWriter(reader, 0)

var hasComponentBuild = false
var hasBuildableComponentBuild = false
var hasObjectBuild = false

reader.accept(object : ClassVisitor(Opcodes.ASM9, writer) {
override fun visitMethod(access: Int, name: String, desc: String, sig: String?, ex: Array<out String>?): MethodVisitor {
if (name == "build" && desc == "()Lnet/kyori/adventure/text/Component;") hasComponentBuild = true
if (name == "build" && desc == "()Lnet/kyori/adventure/text/BuildableComponent;") hasBuildableComponentBuild = true
if (name == "build" && desc == "()Ljava/lang/Object;") hasObjectBuild = true
return super.visitMethod(access, name, desc, sig, ex)
}

override fun visitEnd() {
check(hasComponentBuild) { "Missing ComponentBuilder.build():Component" }

if (!hasBuildableComponentBuild) {
super.visitMethod(
Opcodes.ACC_PUBLIC or Opcodes.ACC_BRIDGE or Opcodes.ACC_SYNTHETIC,
"build",
"()Lnet/kyori/adventure/text/BuildableComponent;",
null,
null
).apply {
visitCode()
visitVarInsn(Opcodes.ALOAD, 0)
visitMethodInsn(
Opcodes.INVOKEINTERFACE,
"net/kyori/adventure/text/ComponentBuilder",
"build",
"()Lnet/kyori/adventure/text/Component;",
true
)
visitTypeInsn(Opcodes.CHECKCAST, "net/kyori/adventure/text/BuildableComponent")
visitInsn(Opcodes.ARETURN)
visitMaxs(1, 1)
visitEnd()
}
}

if (!hasObjectBuild) {
super.visitMethod(
Opcodes.ACC_PUBLIC or Opcodes.ACC_BRIDGE or Opcodes.ACC_SYNTHETIC,
Expand Down