diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/AbstractComponent.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/AbstractComponent.java
deleted file mode 100644
index 95173502..00000000
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/AbstractComponent.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Distributor, a feature-rich framework for Mindustry plugins.
- *
- * Copyright (C) 2024 Xpdustry
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.xpdustry.distributor.api.component;
-
-import com.xpdustry.distributor.api.component.style.ComponentColor;
-import com.xpdustry.distributor.api.component.style.ComponentStyle;
-import com.xpdustry.distributor.api.component.style.TextDecoration;
-import com.xpdustry.distributor.api.permission.TriState;
-import java.util.Map;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-abstract class AbstractComponent, B extends BuildableComponent.Builder>
- implements BuildableComponent {
-
- private final ComponentStyle style;
-
- protected AbstractComponent(final ComponentStyle style) {
- this.style = style;
- }
-
- @Override
- public ComponentStyle getStyle() {
- return style;
- }
-
- public abstract static class Builder, B extends BuildableComponent.Builder>
- implements BuildableComponent.Builder {
-
- protected ComponentStyle.Builder style;
-
- public Builder(final C component) {
- this.style = component.getStyle().toBuilder();
- }
-
- public Builder() {
- this.style = ComponentStyle.builder();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public B setTextColor(final @Nullable ComponentColor textColor) {
- style.setTextColor(textColor);
- return (B) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public B setBackColor(final @Nullable ComponentColor backColor) {
- style.setBackColor(backColor);
- return (B) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public B setDecorations(final Map decorations) {
- style.setDecorations(decorations);
- return (B) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public B setDecoration(final TextDecoration decoration, final TriState state) {
- style.setDecoration(decoration, state);
- return (B) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public B setStyle(final ComponentStyle style) {
- this.style = style.toBuilder();
- return (B) this;
- }
- }
-}
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/AbstractComponentBuilder.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/AbstractComponentBuilder.java
new file mode 100644
index 00000000..efcc0f17
--- /dev/null
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/AbstractComponentBuilder.java
@@ -0,0 +1,75 @@
+/*
+ * Distributor, a feature-rich framework for Mindustry plugins.
+ *
+ * Copyright (C) 2024 Xpdustry
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.xpdustry.distributor.api.component;
+
+import com.xpdustry.distributor.api.component.style.ComponentColor;
+import com.xpdustry.distributor.api.component.style.ComponentStyle;
+import com.xpdustry.distributor.api.component.style.TextDecoration;
+import com.xpdustry.distributor.api.permission.TriState;
+import java.util.Map;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+abstract class AbstractComponentBuilder, B extends BuildableComponent.Builder>
+ implements BuildableComponent.Builder {
+
+ protected ComponentStyle.Builder style;
+
+ public AbstractComponentBuilder(final C component) {
+ this.style = component.getStyle().toBuilder();
+ }
+
+ public AbstractComponentBuilder() {
+ this.style = ComponentStyle.builder();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public B setTextColor(final @Nullable ComponentColor textColor) {
+ style.setTextColor(textColor);
+ return (B) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public B setBackColor(final @Nullable ComponentColor backColor) {
+ style.setBackColor(backColor);
+ return (B) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public B setDecorations(final Map decorations) {
+ style.setDecorations(decorations);
+ return (B) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public B setDecoration(final TextDecoration decoration, final TriState state) {
+ style.setDecoration(decoration, state);
+ return (B) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public B setStyle(final ComponentStyle style) {
+ this.style = style.toBuilder();
+ return (B) this;
+ }
+}
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ListComponentImpl.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ListComponentImpl.java
index 6dffde69..d821a151 100644
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ListComponentImpl.java
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ListComponentImpl.java
@@ -21,14 +21,11 @@
import com.xpdustry.distributor.api.component.style.ComponentStyle;
import java.util.ArrayList;
import java.util.List;
-import java.util.Objects;
-final class ListComponentImpl extends AbstractComponent implements ListComponent {
-
- private final List components;
+record ListComponentImpl(ComponentStyle style, List components) implements ListComponent {
ListComponentImpl(final ComponentStyle style, final List components) {
- super(style);
+ this.style = style;
this.components = List.copyOf(components);
}
@@ -38,28 +35,16 @@ public List getComponents() {
}
@Override
- public ListComponent.Builder toBuilder() {
- return new Builder(this);
- }
-
- @Override
- public String toString() {
- return "ListComponent{style=" + getStyle() + ", components=" + components + "}";
+ public ComponentStyle getStyle() {
+ return this.style;
}
@Override
- public int hashCode() {
- return Objects.hash(getStyle(), components);
- }
-
- @Override
- public boolean equals(final Object o) {
- return (o instanceof ListComponentImpl other)
- && getStyle().equals(other.getStyle())
- && components.equals(other.components);
+ public Builder toBuilder() {
+ return new Builder(this);
}
- static final class Builder extends AbstractComponent.Builder
+ static final class Builder extends AbstractComponentBuilder
implements ListComponent.Builder {
private final List components;
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/NumberComponent.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/NumberComponent.java
deleted file mode 100644
index 8d30041b..00000000
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/NumberComponent.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Distributor, a feature-rich framework for Mindustry plugins.
- *
- * Copyright (C) 2024 Xpdustry
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.xpdustry.distributor.api.component;
-
-import com.xpdustry.distributor.api.component.style.ComponentColor;
-import com.xpdustry.distributor.api.component.style.ComponentStyle;
-
-public interface NumberComponent
- extends BuildableComponent, ValueComponent {
-
- static NumberComponent.Builder number() {
- return new NumberComponentImpl.Builder();
- }
-
- static NumberComponent number(final Number number, final ComponentColor textColor) {
- return new NumberComponentImpl(ComponentStyle.style(textColor), number);
- }
-
- static NumberComponent number(final Number number) {
- return new NumberComponentImpl(ComponentStyle.empty(), number);
- }
-
- Number getNumber();
-
- @Override
- default Number getValue() {
- return getNumber();
- }
-
- interface Builder extends BuildableComponent.Builder {
-
- Builder setNumber(final Number number);
- }
-}
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TemporalComponent.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TemporalComponent.java
index 841ae9bb..ad4bdb68 100644
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TemporalComponent.java
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TemporalComponent.java
@@ -23,20 +23,19 @@
import java.time.format.FormatStyle;
import java.time.temporal.Temporal;
-public interface TemporalComponent
- extends BuildableComponent, ValueComponent {
+public interface TemporalComponent extends BuildableComponent {
static TemporalComponent.Builder temporal() {
return new TemporalComponentImpl.Builder();
}
- static TemporalComponent temporal(final Temporal temporal, final TemporalFormat fallbackFormat) {
- return new TemporalComponentImpl(ComponentStyle.empty(), temporal, fallbackFormat);
+ static TemporalComponent temporal(final Temporal temporal, final TemporalFormat format) {
+ return new TemporalComponentImpl(ComponentStyle.empty(), temporal, format);
}
static TemporalComponent temporal(
- final Temporal temporal, final TemporalFormat fallbackFormat, final ComponentColor textColor) {
- return new TemporalComponentImpl(ComponentStyle.style(textColor), temporal, fallbackFormat);
+ final Temporal temporal, final TemporalFormat format, final ComponentColor textColor) {
+ return new TemporalComponentImpl(ComponentStyle.style(textColor), temporal, format);
}
static TemporalComponent temporal(final Temporal temporal) {
@@ -51,17 +50,12 @@ static TemporalComponent temporal(final Temporal temporal, final ComponentColor
Temporal getTemporal();
- TemporalFormat getFallbackFormat();
-
- @Override
- default Temporal getValue() {
- return getTemporal();
- }
+ TemporalFormat getFormat();
interface Builder extends BuildableComponent.Builder {
Builder setTemporal(final Temporal temporal);
- Builder setFallbackFormat(final TemporalFormat fallbackFormat);
+ Builder setFormat(final TemporalFormat format);
}
}
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TemporalComponentImpl.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TemporalComponentImpl.java
index a68ac1c6..8713fe35 100644
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TemporalComponentImpl.java
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TemporalComponentImpl.java
@@ -23,38 +23,34 @@
import java.time.format.FormatStyle;
import java.time.temporal.Temporal;
-final class TemporalComponentImpl extends AbstractComponent
+record TemporalComponentImpl(ComponentStyle style, Temporal temporal, TemporalFormat format)
implements TemporalComponent {
- private final Temporal temporal;
- private final TemporalFormat fallbackStyle;
-
- TemporalComponentImpl(final ComponentStyle style, final Temporal temporal, final TemporalFormat fallbackStyle) {
- super(style);
- this.temporal = temporal;
- this.fallbackStyle = fallbackStyle;
- }
-
@Override
public Temporal getTemporal() {
return this.temporal;
}
@Override
- public TemporalFormat getFallbackFormat() {
- return fallbackStyle;
+ public TemporalFormat getFormat() {
+ return format;
+ }
+
+ @Override
+ public ComponentStyle getStyle() {
+ return style;
}
@Override
- public TemporalComponent.Builder toBuilder() {
+ public Builder toBuilder() {
return new Builder(this);
}
- static final class Builder extends AbstractComponent.Builder
+ static final class Builder extends AbstractComponentBuilder
implements TemporalComponent.Builder {
private Temporal temporal;
- private TemporalFormat fallbackFormat = TemporalFormat.ofDateTime(FormatStyle.SHORT);
+ private TemporalFormat format = TemporalFormat.ofDateTime(FormatStyle.SHORT);
public Builder() {
this.temporal = Instant.now();
@@ -72,14 +68,14 @@ public Builder setTemporal(final Temporal temporal) {
}
@Override
- public Builder setFallbackFormat(final TemporalFormat fallbackFormat) {
- this.fallbackFormat = fallbackFormat;
+ public Builder setFormat(final TemporalFormat format) {
+ this.format = format;
return this;
}
@Override
public TemporalComponent build() {
- return new TemporalComponentImpl(style.build(), temporal, fallbackFormat);
+ return new TemporalComponentImpl(style.build(), temporal, format);
}
}
}
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TextComponent.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TextComponent.java
index 86a1ec03..b7168764 100644
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TextComponent.java
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TextComponent.java
@@ -21,8 +21,7 @@
import com.xpdustry.distributor.api.component.style.ComponentColor;
import com.xpdustry.distributor.api.component.style.ComponentStyle;
-public interface TextComponent
- extends BuildableComponent, ValueComponent {
+public interface TextComponent extends BuildableComponent {
static TextComponent.Builder text() {
return new TextComponentImpl.Builder();
@@ -54,11 +53,6 @@ static TextComponent newline() {
String getContent();
- @Override
- default String getValue() {
- return getContent();
- }
-
@Override
default Builder toBuilder() {
return new TextComponentImpl.Builder(this);
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TextComponentImpl.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TextComponentImpl.java
index 28351687..ed834f7e 100644
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TextComponentImpl.java
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TextComponentImpl.java
@@ -19,49 +19,29 @@
package com.xpdustry.distributor.api.component;
import com.xpdustry.distributor.api.component.style.ComponentStyle;
-import java.util.Objects;
-final class TextComponentImpl extends AbstractComponent implements TextComponent {
+record TextComponentImpl(ComponentStyle style, String content) implements TextComponent {
static final TextComponent EMPTY = new TextComponentImpl(ComponentStyle.empty(), "");
static final TextComponent SPACE = new TextComponentImpl(ComponentStyle.empty(), " ");
static final TextComponent NEWLINE = new TextComponentImpl(ComponentStyle.empty(), "\n");
- private final String content;
-
- TextComponentImpl(final ComponentStyle style, final String content) {
- super(style);
- this.content = content;
- }
-
@Override
public String getContent() {
return content;
}
@Override
- public TextComponent.Builder toBuilder() {
- return new Builder(this);
+ public ComponentStyle getStyle() {
+ return this.style;
}
@Override
- public String toString() {
- return "TextComponent{style=" + getStyle() + ", content='" + content + "'}";
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getStyle(), content);
- }
-
- @Override
- public boolean equals(final Object o) {
- return (o instanceof TextComponentImpl other)
- && getStyle().equals(other.getStyle())
- && content.equals(other.getContent());
+ public Builder toBuilder() {
+ return new Builder(this);
}
- static final class Builder extends AbstractComponent.Builder
+ static final class Builder extends AbstractComponentBuilder
implements TextComponent.Builder {
private String content = "";
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TranslatableComponentImpl.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TranslatableComponentImpl.java
index 652460ea..94ed507d 100644
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TranslatableComponentImpl.java
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/TranslatableComponentImpl.java
@@ -24,11 +24,6 @@
record TranslatableComponentImpl(ComponentStyle style, String key, TranslationArguments parameters)
implements BuildableComponent, TranslatableComponent {
- @Override
- public TranslatableComponent.Builder toBuilder() {
- return new Builder(this);
- }
-
@Override
public String getKey() {
return this.key;
@@ -44,7 +39,12 @@ public ComponentStyle getStyle() {
return this.style;
}
- static final class Builder extends AbstractComponent.Builder
+ @Override
+ public Builder toBuilder() {
+ return new Builder(this);
+ }
+
+ static final class Builder extends AbstractComponentBuilder
implements TranslatableComponent.Builder {
private String key;
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ValueComponent.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ValueComponent.java
index 253200ce..a28c6784 100644
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ValueComponent.java
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ValueComponent.java
@@ -18,7 +18,31 @@
*/
package com.xpdustry.distributor.api.component;
-public interface ValueComponent extends Component {
+import com.xpdustry.distributor.api.component.style.ComponentColor;
+import com.xpdustry.distributor.api.component.style.ComponentStyle;
+
+public interface ValueComponent extends BuildableComponent, ValueComponent.Builder> {
+
+ static ValueComponent.Builder value() {
+ return new ValueComponentImpl.Builder<>();
+ }
+
+ static ValueComponent value(final V value) {
+ return new ValueComponentImpl<>(ComponentStyle.empty(), value);
+ }
+
+ static ValueComponent value(final V value, final ComponentColor textColor) {
+ return new ValueComponentImpl<>(ComponentStyle.style(textColor), value);
+ }
+
+ static ValueComponent value(final V value, final ComponentStyle style) {
+ return new ValueComponentImpl<>(style, value);
+ }
V getValue();
+
+ interface Builder extends BuildableComponent.Builder, ValueComponent.Builder> {
+
+ Builder setValue(final V value);
+ }
}
diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/NumberComponentImpl.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ValueComponentImpl.java
similarity index 51%
rename from distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/NumberComponentImpl.java
rename to distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ValueComponentImpl.java
index 7affe203..df505a6e 100644
--- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/NumberComponentImpl.java
+++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/component/ValueComponentImpl.java
@@ -19,50 +19,47 @@
package com.xpdustry.distributor.api.component;
import com.xpdustry.distributor.api.component.style.ComponentStyle;
+import java.util.Objects;
+import org.checkerframework.checker.nullness.qual.Nullable;
-final class NumberComponentImpl extends AbstractComponent
- implements NumberComponent {
+record ValueComponentImpl(ComponentStyle style, V value) implements ValueComponent {
- private final Number number;
-
- NumberComponentImpl(final ComponentStyle style, final Number number) {
- super(style);
- this.number = number;
+ @Override
+ public V getValue() {
+ return value;
}
@Override
- public Number getNumber() {
- return number;
+ public ComponentStyle getStyle() {
+ return style;
}
@Override
- public NumberComponent.Builder toBuilder() {
- return new Builder(this);
+ public Builder toBuilder() {
+ return new Builder<>(this);
}
- static final class Builder extends AbstractComponent.Builder
- implements NumberComponent.Builder {
+ static final class Builder extends AbstractComponentBuilder, ValueComponent.Builder>
+ implements ValueComponent.Builder {
- private Number number;
+ private @Nullable V value = null;
- public Builder() {
- this.number = 0;
- }
-
- public Builder(final NumberComponent component) {
+ Builder(final ValueComponent component) {
super(component);
- this.number = component.getNumber();
+ this.value = component.getValue();
}
+ Builder() {}
+
@Override
- public NumberComponent.Builder setNumber(final Number number) {
- this.number = number;
+ public Builder setValue(final V value) {
+ this.value = value;
return this;
}
@Override
- public NumberComponent build() {
- return new NumberComponentImpl(style.build(), number);
+ public ValueComponent build() {
+ return new ValueComponentImpl<>(style.build(), Objects.requireNonNull(value));
}
}
}
diff --git a/distributor-common-api/src/test/java/com/xpdustry/distributor/api/component/render/MindustryComponentAppendableTest.java b/distributor-common-api/src/test/java/com/xpdustry/distributor/api/component/render/MindustryComponentAppendableTest.java
index 6d24e541..889a4717 100644
--- a/distributor-common-api/src/test/java/com/xpdustry/distributor/api/component/render/MindustryComponentAppendableTest.java
+++ b/distributor-common-api/src/test/java/com/xpdustry/distributor/api/component/render/MindustryComponentAppendableTest.java
@@ -35,9 +35,9 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import static com.xpdustry.distributor.api.component.NumberComponent.number;
import static com.xpdustry.distributor.api.component.TextComponent.text;
import static com.xpdustry.distributor.api.component.TranslatableComponent.translatable;
+import static com.xpdustry.distributor.api.component.ValueComponent.value;
import static org.junit.jupiter.api.Assertions.assertEquals;
public final class MindustryComponentAppendableTest {
@@ -129,7 +129,7 @@ void test_append_translatable_simple() {
@Test
void test_translatable_arguments() {
final var component1 = translatable(
- "describe-number", TranslationArguments.array(number(0, ComponentColor.YELLOW)), ComponentColor.RED);
+ "describe-number", TranslationArguments.array(value(0, ComponentColor.YELLOW)), ComponentColor.RED);
assertEquals(
"[#FF0000]The [[number] is [#FFFF00]zero[][]",
createAppendable().append(component1).toString());
diff --git a/distributor-common/src/main/java/com/xpdustry/distributor/common/component/render/StandardComponentRendererProvider.java b/distributor-common/src/main/java/com/xpdustry/distributor/common/component/render/StandardComponentRendererProvider.java
index 05487cca..f404faf1 100644
--- a/distributor-common/src/main/java/com/xpdustry/distributor/common/component/render/StandardComponentRendererProvider.java
+++ b/distributor-common/src/main/java/com/xpdustry/distributor/common/component/render/StandardComponentRendererProvider.java
@@ -22,10 +22,10 @@
import com.xpdustry.distributor.api.audience.Audience;
import com.xpdustry.distributor.api.component.Component;
import com.xpdustry.distributor.api.component.ListComponent;
-import com.xpdustry.distributor.api.component.NumberComponent;
import com.xpdustry.distributor.api.component.TemporalComponent;
import com.xpdustry.distributor.api.component.TextComponent;
import com.xpdustry.distributor.api.component.TranslatableComponent;
+import com.xpdustry.distributor.api.component.ValueComponent;
import com.xpdustry.distributor.api.component.render.ComponentAppendable;
import com.xpdustry.distributor.api.component.render.ComponentRenderer;
import com.xpdustry.distributor.api.component.render.ComponentRendererProvider;
@@ -44,12 +44,12 @@ public final class StandardComponentRendererProvider implements ComponentRendere
return (ComponentRenderer) TextComponentRenderer.INSTANCE;
} else if (component instanceof ListComponent) {
return (ComponentRenderer) ListComponentRenderer.INSTANCE;
- } else if (component instanceof NumberComponent) {
- return (ComponentRenderer) NumberComponentRenderer.INSTANCE;
} else if (component instanceof TemporalComponent) {
return (ComponentRenderer) TemporalComponentRenderer.INSTANCE;
} else if (component instanceof TranslatableComponent) {
return (ComponentRenderer) TranslatableComponentRenderer.INSTANCE;
+ } else if (component instanceof ValueComponent) {
+ return (ComponentRenderer) ValueComponentRenderer.INSTANCE;
} else {
return null;
}
@@ -79,19 +79,6 @@ public void render(
}
}
- private static final class NumberComponentRenderer implements ComponentRenderer {
-
- private static final NumberComponentRenderer INSTANCE = new NumberComponentRenderer();
-
- @Override
- public void render(
- final NumberComponent component,
- final ComponentAppendable appendable,
- final MetadataContainer metadata) {
- appendable.append(component.getNumber().toString());
- }
- }
-
private static final class TemporalComponentRenderer implements ComponentRenderer {
private static final TemporalComponentRenderer INSTANCE = new TemporalComponentRenderer();
@@ -102,7 +89,7 @@ public void render(
final ComponentAppendable appendable,
final MetadataContainer metadata) {
component
- .getFallbackFormat()
+ .getFormat()
.toFormatter()
.withZone(ZoneId.of("UTC"))
.withLocale(metadata.getMetadata(Audience.LOCALE).orElseGet(Locale::getDefault))
@@ -131,4 +118,17 @@ public void render(
}
}
}
+
+ private static final class ValueComponentRenderer implements ComponentRenderer> {
+
+ private static final ValueComponentRenderer INSTANCE = new ValueComponentRenderer();
+
+ @Override
+ public void render(
+ final ValueComponent> component,
+ final ComponentAppendable appendable,
+ final MetadataContainer metadata) {
+ appendable.append(component.getValue().toString());
+ }
+ }
}