diff --git a/api/src/main/java/net/kyori/adventure/text/ComponentIteratorType.java b/api/src/main/java/net/kyori/adventure/text/ComponentIteratorType.java
index 404d5bbb6..07170ed4e 100644
--- a/api/src/main/java/net/kyori/adventure/text/ComponentIteratorType.java
+++ b/api/src/main/java/net/kyori/adventure/text/ComponentIteratorType.java
@@ -49,10 +49,10 @@ public interface ComponentIteratorType {
ComponentIteratorType DEPTH_FIRST = (component, deque, flags) -> {
if (flags.contains(ComponentIteratorFlag.INCLUDE_TRANSLATABLE_COMPONENT_ARGUMENTS) && component instanceof TranslatableComponent) {
final TranslatableComponent translatable = (TranslatableComponent) component;
- final List args = translatable.args();
+ final List extends ComponentLike> args = translatable.arguments();
for (int i = args.size() - 1; i >= 0; i--) {
- deque.addFirst(args.get(i));
+ deque.addFirst(args.get(i).asComponent());
}
}
@@ -79,7 +79,9 @@ public interface ComponentIteratorType {
*/
ComponentIteratorType BREADTH_FIRST = (component, deque, flags) -> {
if (flags.contains(ComponentIteratorFlag.INCLUDE_TRANSLATABLE_COMPONENT_ARGUMENTS) && component instanceof TranslatableComponent) {
- deque.addAll(((TranslatableComponent) component).args());
+ for (final TranslationArgument argument : ((TranslatableComponent) component).arguments()) {
+ deque.add(argument.asComponent());
+ }
}
final HoverEvent> hoverEvent = component.hoverEvent();
diff --git a/api/src/main/java/net/kyori/adventure/text/TextReplacementRenderer.java b/api/src/main/java/net/kyori/adventure/text/TextReplacementRenderer.java
index 9034a6131..9fd580b73 100644
--- a/api/src/main/java/net/kyori/adventure/text/TextReplacementRenderer.java
+++ b/api/src/main/java/net/kyori/adventure/text/TextReplacementRenderer.java
@@ -131,12 +131,12 @@ private TextReplacementRenderer() {
// otherwise, we haven't modified the component, so nothing to change
}
} else if (modified instanceof TranslatableComponent) { // get TranslatableComponent with() args
- final List args = ((TranslatableComponent) modified).args();
- List newArgs = null;
+ final List args = ((TranslatableComponent) modified).arguments();
+ List newArgs = null;
for (int i = 0, size = args.size(); i < size; i++) {
- final Component original = args.get(i);
- final Component replaced = this.render(original, state);
- if (replaced != component) {
+ final TranslationArgument original = args.get(i);
+ final TranslationArgument replaced = original.value() instanceof Component ? TranslationArgument.component(this.render((Component) original.value(), state)) : original;
+ if (replaced != original) {
if (newArgs == null) {
newArgs = new ArrayList<>(size);
if (i > 0) {
diff --git a/api/src/main/java/net/kyori/adventure/text/TranslatableComponent.java b/api/src/main/java/net/kyori/adventure/text/TranslatableComponent.java
index 809fd728d..21f1b6e42 100644
--- a/api/src/main/java/net/kyori/adventure/text/TranslatableComponent.java
+++ b/api/src/main/java/net/kyori/adventure/text/TranslatableComponent.java
@@ -97,14 +97,19 @@ public interface TranslatableComponent extends BuildableComponent args();
/**
* Sets the translation arguments for this component.
*
+ * Non-{@link Component} arguments can be wrapped in {@link TranslationArgument}.
+ *
* @param args the translation arguments
* @return a translatable component
+ * @see TranslationArgument
* @since 4.0.0
*/
@Contract(pure = true)
@@ -113,6 +118,8 @@ public interface TranslatableComponent extends BuildableComponentNon-{@link Component} arguments can be wrapped in {@link TranslationArgument}.
+ *
* @param args the translation arguments
* @return a translatable component
* @since 4.0.0
@@ -120,6 +127,14 @@ public interface TranslatableComponent extends BuildableComponent args);
+ /**
+ * Gets the unmodifiable list of translation arguments.
+ *
+ * @return the unmodifiable list of translation arguments
+ * @since 4.0.0
+ */
+ @NotNull List arguments();
+
/**
* Gets the translation fallback text for this component.
* The fallback text will be shown when the client doesn't know the
@@ -149,7 +164,7 @@ public interface TranslatableComponent extends BuildableComponent {
/**
* Sets the translation args.
*
+ * Non-{@link Component} arguments can be wrapped in {@link TranslationArgument}.
+ *
* @param args the translation args
* @return this builder
* @since 4.0.0
@@ -228,6 +245,8 @@ interface Builder extends ComponentBuilder {
/**
* Sets the translation args.
*
+ * Non-{@link Component} arguments can be wrapped in {@link TranslationArgument}.
+ *
* @param args the translation args
* @return this builder
* @since 4.0.0
diff --git a/api/src/main/java/net/kyori/adventure/text/TranslatableComponentImpl.java b/api/src/main/java/net/kyori/adventure/text/TranslatableComponentImpl.java
index df7f1c735..1b440320d 100644
--- a/api/src/main/java/net/kyori/adventure/text/TranslatableComponentImpl.java
+++ b/api/src/main/java/net/kyori/adventure/text/TranslatableComponentImpl.java
@@ -23,6 +23,7 @@
*/
package net.kyori.adventure.text;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -48,15 +49,15 @@ static TranslatableComponent create(final @NotNull List extends ComponentLike>
requireNonNull(style, "style"),
requireNonNull(key, "key"),
fallback,
- ComponentLike.asComponents(args) // Since translation arguments can be indexed, empty components are also included.
+ asArguments(args) // Since translation arguments can be indexed, empty components are also included.
);
}
private final String key;
private final @Nullable String fallback;
- private final List args;
+ private final List args;
- TranslatableComponentImpl(final @NotNull List children, final @NotNull Style style, final @NotNull String key, final @Nullable String fallback, final @NotNull List args) {
+ TranslatableComponentImpl(final @NotNull List children, final @NotNull Style style, final @NotNull String key, final @Nullable String fallback, final @NotNull List args) {
super(children, style);
this.key = key;
this.fallback = fallback;
@@ -75,7 +76,13 @@ static TranslatableComponent create(final @NotNull List extends ComponentLike>
}
@Override
+ @Deprecated
public @NotNull List args() {
+ return ComponentLike.asComponents(this.args); // eww
+ }
+
+ @Override
+ public @NotNull List arguments() {
return this.args;
}
@@ -115,7 +122,7 @@ public boolean equals(final @Nullable Object other) {
if (!(other instanceof TranslatableComponent)) return false;
if (!super.equals(other)) return false;
final TranslatableComponent that = (TranslatableComponent) other;
- return Objects.equals(this.key, that.key()) && Objects.equals(this.fallback, that.fallback()) && Objects.equals(this.args, that.args());
+ return Objects.equals(this.key, that.key()) && Objects.equals(this.fallback, that.fallback()) && Objects.equals(this.args, that.arguments());
}
@Override
@@ -140,7 +147,7 @@ public String toString() {
static final class BuilderImpl extends AbstractComponentBuilder implements TranslatableComponent.Builder {
private @Nullable String key;
private @Nullable String fallback;
- private List extends Component> args = Collections.emptyList();
+ private List args = Collections.emptyList();
BuilderImpl() {
}
@@ -148,7 +155,7 @@ static final class BuilderImpl extends AbstractComponentBuilder args) {
- this.args = ComponentLike.asComponents(requireNonNull(args, "args"));
+ this.args = asArguments(requireNonNull(args, "args"));
return this;
}
@@ -201,4 +208,25 @@ static final class BuilderImpl extends AbstractComponentBuilder asArguments(final @NotNull List extends ComponentLike> likes) {
+ if (likes.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ final List ret = new ArrayList<>(likes.size());
+ for (int i = 0; i < likes.size(); i++) {
+ final ComponentLike like = likes.get(i);
+ if (like == null) {
+ throw new NullPointerException("likes[" + i + "]");
+ }
+ if (like instanceof TranslationArgument) {
+ ret.add((TranslationArgument) like);
+ } else {
+ ret.add(TranslationArgument.component(like));
+ }
+ }
+
+ return Collections.unmodifiableList(ret);
+ }
}
diff --git a/api/src/main/java/net/kyori/adventure/text/TranslationArgument.java b/api/src/main/java/net/kyori/adventure/text/TranslationArgument.java
new file mode 100644
index 000000000..e4fe35645
--- /dev/null
+++ b/api/src/main/java/net/kyori/adventure/text/TranslationArgument.java
@@ -0,0 +1,130 @@
+/*
+ * This file is part of adventure, licensed under the MIT License.
+ *
+ * Copyright (c) 2017-2023 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.examination.Examinable;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * An argument that can be part of a {@link TranslatableComponent}.
+ *
+ * @since 4.15.0
+ */
+@ApiStatus.NonExtendable
+public interface TranslationArgument extends ComponentLike, Examinable {
+
+ /**
+ * The argument's value.
+ *
+ * @return the argument value
+ * @since 4.15.0
+ */
+ @NotNull Object value();
+
+ /**
+ * Create a boolean argument.
+ *
+ * @param value the value
+ * @return the argument
+ * @since 4.15.0
+ * @sinceMinecraft 1.20.3
+ */
+ static @NotNull TranslationArgument bool(final boolean value) {
+ return new TranslationArgumentImpl.BooleanImpl(value);
+ }
+
+ /**
+ * Create a numeric argument.
+ *
+ * @param value the value
+ * @return the argument
+ * @since 4.15.0
+ * @sinceMinecraft 1.20.3
+ */
+ static @NotNull TranslationArgument numeric(final @NotNull Number value) {
+ return new TranslationArgumentImpl.NumericImpl(requireNonNull(value, "value"));
+ }
+
+ /**
+ * Create a component argument.
+ *
+ * @param value the value
+ * @return the argument
+ * @since 4.15.0
+ * @sinceMinecraft 1.20.3
+ */
+ static @NotNull TranslationArgument component(final @NotNull ComponentLike value) {
+ return new TranslationArgumentImpl.ComponentImpl(requireNonNull(requireNonNull(value, "value").asComponent(), "value.asComponent()"));
+ }
+
+ /**
+ * A boolean argument to translations.
+ *
+ * @since 4.15.0
+ * @sinceMinecraft 1.20.3
+ */
+ interface Boolean extends TranslationArgument {
+ /**
+ * The value of the argument.
+ *
+ * @return the raw argument value
+ * @since 4.15.0
+ */
+ java.lang.@NotNull Boolean value();
+ }
+
+ /**
+ * A numeric argument to translations.
+ *
+ * @since 4.15.0
+ * @sinceMinecraft 1.20.3
+ */
+ interface Numeric extends TranslationArgument {
+ /**
+ * The value of the argument.
+ *
+ * @return the raw argument value
+ * @since 4.15.0
+ */
+ @NotNull Number value();
+ }
+
+ /**
+ * A component argument to translations.
+ *
+ * @since 4.15.0
+ */
+ interface Component extends TranslationArgument {
+ /**
+ * The value of the argument.
+ *
+ * @return the raw argument value
+ * @since 4.15.0
+ */
+ net.kyori.adventure.text.@NotNull Component value();
+ }
+}
diff --git a/api/src/main/java/net/kyori/adventure/text/TranslationArgumentImpl.java b/api/src/main/java/net/kyori/adventure/text/TranslationArgumentImpl.java
new file mode 100644
index 000000000..cb974efa5
--- /dev/null
+++ b/api/src/main/java/net/kyori/adventure/text/TranslationArgumentImpl.java
@@ -0,0 +1,168 @@
+/*
+ * This file is part of adventure, licensed under the MIT License.
+ *
+ * Copyright (c) 2017-2023 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 java.util.Objects;
+import java.util.stream.Stream;
+import net.kyori.adventure.internal.Internals;
+import net.kyori.examination.ExaminableProperty;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+final class TranslationArgumentImpl {
+ private static final Component TRUE = Component.text("true");
+ private static final Component FALSE = Component.text("false");
+
+ private TranslationArgumentImpl() {
+ }
+
+ static final class BooleanImpl implements TranslationArgument.Boolean {
+ private final boolean value;
+
+ BooleanImpl(final boolean value) {
+ this.value = value;
+ }
+
+ @Override
+ public java.lang.@NotNull Boolean value() {
+ return this.value;
+ }
+
+ @Override
+ public net.kyori.adventure.text.@NotNull Component asComponent() {
+ return this.value ? TRUE : FALSE;
+ }
+
+ @Override
+ public boolean equals(final @Nullable Object other) {
+ if (this == other) return true;
+ if (other == null || getClass() != other.getClass()) return false;
+ final BooleanImpl that = (BooleanImpl) other;
+ return this.value == that.value;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.value);
+ }
+
+ @Override
+ public String toString() {
+ return Internals.toString(this);
+ }
+
+ @Override
+ public @NotNull Stream extends ExaminableProperty> examinableProperties() {
+ return Stream.of(
+ ExaminableProperty.of("value", this.value)
+ );
+ }
+ }
+
+ static final class NumericImpl implements TranslationArgument.Numeric {
+ private final Number value;
+
+ NumericImpl(final Number value) {
+ this.value = value;
+ }
+
+ @Override
+ public @NotNull Number value() {
+ return this.value;
+ }
+
+ @Override
+ public net.kyori.adventure.text.@NotNull Component asComponent() {
+ return net.kyori.adventure.text.Component.text(String.valueOf(this.value));
+ }
+
+ @Override
+ public boolean equals(final @Nullable Object other) {
+ if (this == other) return true;
+ if (other == null || getClass() != other.getClass()) return false;
+ final NumericImpl that = (NumericImpl) other;
+ return this.value.equals(that.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.value);
+ }
+
+ @Override
+ public String toString() {
+ return Internals.toString(this);
+ }
+
+ @Override
+ public @NotNull Stream extends ExaminableProperty> examinableProperties() {
+ return Stream.of(
+ ExaminableProperty.of("value", this.value)
+ );
+ }
+ }
+
+ static final class ComponentImpl implements TranslationArgument.Component {
+ private final net.kyori.adventure.text.Component value;
+
+ ComponentImpl(final net.kyori.adventure.text.Component value) {
+ this.value = value;
+ }
+
+ @Override
+ public net.kyori.adventure.text.@NotNull Component value() {
+ return this.value;
+ }
+
+ @Override
+ public net.kyori.adventure.text.@NotNull Component asComponent() {
+ return this.value;
+ }
+
+ @Override
+ public boolean equals(final @Nullable Object other) {
+ if (this == other) return true;
+ if (other == null || getClass() != other.getClass()) return false;
+ final ComponentImpl that = (ComponentImpl) other;
+ return this.value.equals(that.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.value);
+ }
+
+ @Override
+ public String toString() {
+ return Internals.toString(this);
+ }
+
+ @Override
+ public @NotNull Stream extends ExaminableProperty> examinableProperties() {
+ return Stream.of(
+ ExaminableProperty.of("value", this.value)
+ );
+ }
+ }
+}
diff --git a/api/src/main/java/net/kyori/adventure/text/renderer/TranslatableComponentRenderer.java b/api/src/main/java/net/kyori/adventure/text/renderer/TranslatableComponentRenderer.java
index fc8a82d2f..89e6380a2 100644
--- a/api/src/main/java/net/kyori/adventure/text/renderer/TranslatableComponentRenderer.java
+++ b/api/src/main/java/net/kyori/adventure/text/renderer/TranslatableComponentRenderer.java
@@ -42,6 +42,7 @@
import net.kyori.adventure.text.StorageNBTComponent;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
+import net.kyori.adventure.text.TranslationArgument;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.translation.Translator;
@@ -184,17 +185,20 @@ protected , B extends NBTComponentBuilder> B
final TranslatableComponent.Builder builder = Component.translatable()
.key(component.key()).fallback(component.fallback());
- if (!component.args().isEmpty()) {
- final List args = new ArrayList<>(component.args());
+ if (!component.arguments().isEmpty()) {
+ final List args = new ArrayList<>(component.arguments());
for (int i = 0, size = args.size(); i < size; i++) {
- args.set(i, this.render(args.get(i), context));
+ final TranslationArgument arg = args.get(i);
+ if (arg instanceof TranslationArgument.Component) {
+ args.set(i, TranslationArgument.component(this.render(((TranslationArgument.Component) arg).value(), context)));
+ }
}
builder.args(args);
}
return this.mergeStyleAndOptionallyDeepRender(component, builder, context);
}
- final List args = component.args();
+ final List args = component.arguments();
final TextComponent.Builder builder = Component.text();
this.mergeStyle(component, builder, context);
@@ -213,7 +217,12 @@ protected , B extends NBTComponentBuilder> B
final int end = it.getRunLimit();
final Integer index = (Integer) it.getAttribute(MessageFormat.Field.ARGUMENT);
if (index != null) {
- builder.append(this.render(args.get(index), context));
+ final TranslationArgument arg = args.get(index);
+ if (arg instanceof TranslationArgument.Component) {
+ builder.append(this.render(arg.asComponent(), context));
+ } else {
+ builder.append(arg.asComponent()); // todo: number rendering?
+ }
} else {
builder.append(Component.text(sb.substring(it.getIndex(), end)));
}
diff --git a/api/src/test/java/net/kyori/adventure/text/TranslatableComponentTest.java b/api/src/test/java/net/kyori/adventure/text/TranslatableComponentTest.java
index 40b12e331..f0cd60951 100644
--- a/api/src/test/java/net/kyori/adventure/text/TranslatableComponentTest.java
+++ b/api/src/test/java/net/kyori/adventure/text/TranslatableComponentTest.java
@@ -108,8 +108,8 @@ void testArgs_array() {
final TranslatableComponent c0 = Component.translatable("multiplayer.player.left");
final Component a0 = Component.text("foo");
final TranslatableComponent c1 = c0.args(a0);
- assertThat(c0.args()).isEmpty();
- assertThat(c1.args()).containsExactly(a0).inOrder();
+ assertThat(c0.arguments()).isEmpty();
+ assertThat(c1.arguments()).containsExactly(TranslationArgument.component(a0)).inOrder();
}
@Test
@@ -117,8 +117,8 @@ void testArgs_list() {
final TranslatableComponent c0 = Component.translatable("multiplayer.player.left");
final Component a0 = Component.text("foo");
final TranslatableComponent c1 = c0.args(Collections.singletonList(a0));
- assertThat(c0.args()).isEmpty();
- assertThat(c1.args()).containsExactly(a0).inOrder();
+ assertThat(c0.arguments()).isEmpty();
+ assertThat(c1.arguments()).containsExactly(TranslationArgument.component(a0)).inOrder();
}
@Test
@@ -127,8 +127,8 @@ void testBuilderArgs_singleBuilder() {
.key("multiplayer.player.left")
.args(Component.text().content("kashike"))
.build();
- assertThat(c0.args()).hasSize(1);
- assertThat(c0.args()).containsExactly(Component.text("kashike")).inOrder();
+ assertThat(c0.arguments()).hasSize(1);
+ assertThat(c0.arguments()).containsExactly(TranslationArgument.component(Component.text("kashike"))).inOrder();
}
@Test
@@ -137,8 +137,8 @@ void testBuilderArgs_singleComponent() {
.key("multiplayer.player.left")
.args(Component.text("kashike"))
.build();
- assertThat(c0.args()).hasSize(1);
- assertThat(c0.args()).containsExactly(Component.text("kashike")).inOrder();
+ assertThat(c0.arguments()).hasSize(1);
+ assertThat(c0.arguments()).containsExactly(TranslationArgument.component(Component.text("kashike"))).inOrder();
}
@Test
@@ -150,10 +150,10 @@ void testBuilderArgs_multiple() {
Component.text().content("lucko")
)
.build();
- assertThat(c0.args()).hasSize(2);
- assertThat(c0.args()).containsExactly(
- Component.text("kashike"),
- Component.text("lucko")
+ assertThat(c0.arguments()).hasSize(2);
+ assertThat(c0.arguments()).containsExactly(
+ TranslationArgument.component(Component.text("kashike")),
+ TranslationArgument.component(Component.text("lucko"))
).inOrder();
}
@@ -167,10 +167,41 @@ void testBuilderArgs_multipleWithEmpty() {
Component.text().content("kashike")
)
.build();
- assertThat(c0.args()).hasSize(2);
- assertThat(c0.args()).containsExactly(
- Component.empty(),
- Component.text("kashike")
+ assertThat(c0.arguments()).hasSize(2);
+ assertThat(c0.arguments()).containsExactly(
+ TranslationArgument.component(Component.empty()),
+ TranslationArgument.component(Component.text("kashike"))
).inOrder();
}
+
+ @Test
+ void testArgs_nonComponent() {
+ final TranslatableComponent c0 = Component.translatable(
+ "some.key",
+ TranslationArgument.numeric(4),
+ TranslationArgument.bool(true)
+ );
+ assertThat(c0.arguments()).hasSize(2);
+ assertThat(c0.arguments()).containsExactly(
+ TranslationArgument.numeric(4),
+ TranslationArgument.bool(true)
+ ).inOrder();
+ }
+
+ @Test
+ void testBuilderArgs_nonComponent() {
+ final TranslatableComponent c0 = Component.translatable()
+ .key("some.key")
+ .args(
+ TranslationArgument.numeric(4.0f),
+ TranslationArgument.bool(true)
+ )
+ .build();
+ assertThat(c0.arguments()).hasSize(2);
+ assertThat(c0.arguments()).containsExactly(
+ TranslationArgument.numeric(4.0f),
+ TranslationArgument.bool(true)
+ ).inOrder();
+ }
+
}
diff --git a/api/src/test/java/net/kyori/adventure/translation/GlobalTranslatorTest.java b/api/src/test/java/net/kyori/adventure/translation/GlobalTranslatorTest.java
index 88cd92cf2..56a414f1f 100644
--- a/api/src/test/java/net/kyori/adventure/translation/GlobalTranslatorTest.java
+++ b/api/src/test/java/net/kyori/adventure/translation/GlobalTranslatorTest.java
@@ -123,7 +123,7 @@ static class DummyTranslator implements Translator {
return (component.key().equals("otherDummy") && locale.equals(Locale.US))
? Component.text()
.append(Component.text("Hello "))
- .append(component.args().isEmpty() ? Component.text("{0}") : component.args().get(0))
+ .append(component.arguments().isEmpty() ? Component.text("{0}") : component.arguments().get(0))
.append(Component.text("!"))
.build()
: null;
diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/TranslatableFallbackTag.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/TranslatableFallbackTag.java
index 42bf0faa9..8d5fe5d19 100644
--- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/TranslatableFallbackTag.java
+++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/TranslatableFallbackTag.java
@@ -28,6 +28,7 @@
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TranslatableComponent;
+import net.kyori.adventure.text.TranslationArgument;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.ParsingException;
import net.kyori.adventure.text.minimessage.internal.serializer.Emitable;
@@ -81,8 +82,8 @@ static Tag create(final ArgumentQueue args, final Context ctx) throws ParsingExc
emit.tag(LANG_OR);
emit.argument(tr.key());
emit.argument(tr.fallback());
- for (final Component with : tr.args()) {
- emit.argument(with);
+ for (final TranslationArgument with : tr.arguments()) {
+ emit.argument(with.asComponent());
}
};
}
diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/TranslatableTag.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/TranslatableTag.java
index 7dd4b654d..fee9b6117 100644
--- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/TranslatableTag.java
+++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/TranslatableTag.java
@@ -28,6 +28,7 @@
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TranslatableComponent;
+import net.kyori.adventure.text.TranslationArgument;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.ParsingException;
import net.kyori.adventure.text.minimessage.internal.serializer.Emitable;
@@ -78,8 +79,8 @@ static Tag create(final ArgumentQueue args, final Context ctx) throws ParsingExc
return emit -> {
emit.tag(LANG);
emit.argument(tr.key());
- for (final Component with : tr.args()) {
- emit.argument(with);
+ for (final TranslationArgument with : tr.arguments()) {
+ emit.argument(with.asComponent());
}
};
}
diff --git a/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/ComponentSerializerImpl.java b/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/ComponentSerializerImpl.java
index d5eb8c161..73b61fa28 100644
--- a/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/ComponentSerializerImpl.java
+++ b/text-serializer-gson/src/main/java/net/kyori/adventure/text/serializer/gson/ComponentSerializerImpl.java
@@ -259,9 +259,9 @@ public void write(final JsonWriter out, final Component value) throws IOExceptio
out.name(TRANSLATE_FALLBACK);
out.value(fallback);
}
- if (!translatable.args().isEmpty()) {
+ if (!translatable.arguments().isEmpty()) {
out.name(TRANSLATE_WITH);
- this.gson.toJson(translatable.args(), COMPONENT_LIST_TYPE, out);
+ this.gson.toJson(translatable.arguments(), COMPONENT_LIST_TYPE, out);
}
} else if (value instanceof ScoreComponent) {
final ScoreComponent score = (ScoreComponent) value;