Skip to content

Commit 5c51dc3

Browse files
committed
feat: 26.1 changes
1 parent 403e896 commit 5c51dc3

File tree

22 files changed

+457
-80
lines changed

22 files changed

+457
-80
lines changed

api/src/main/java/net/kyori/adventure/text/AbstractNBTComponentBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class AbstractNBTComponentBuilder<C extends NBTComponent<C, B>, B exten
3232
protected @Nullable String nbtPath;
3333
protected boolean interpret = NBTComponentImpl.INTERPRET_DEFAULT;
3434
protected @Nullable Component separator;
35+
protected boolean plain = NBTComponentImpl.PLAIN_DEFAULT;
3536

3637
AbstractNBTComponentBuilder() {
3738
}
@@ -41,6 +42,7 @@ abstract class AbstractNBTComponentBuilder<C extends NBTComponent<C, B>, B exten
4142
this.nbtPath = component.nbtPath();
4243
this.interpret = component.interpret();
4344
this.separator = component.separator();
45+
this.plain = component.plain();
4446
}
4547

4648
@Override
@@ -63,4 +65,11 @@ abstract class AbstractNBTComponentBuilder<C extends NBTComponent<C, B>, B exten
6365
this.separator = ComponentLike.unbox(separator);
6466
return (B) this;
6567
}
68+
69+
@Override
70+
@SuppressWarnings("unchecked")
71+
public @NotNull B plain(final boolean plain) {
72+
this.plain = plain;
73+
return (B) this;
74+
}
6675
}

api/src/main/java/net/kyori/adventure/text/BlockNBTComponentImpl.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,33 @@
3939
final class BlockNBTComponentImpl extends NBTComponentImpl<BlockNBTComponent, BlockNBTComponent.Builder> implements BlockNBTComponent {
4040
private final Pos pos;
4141

42-
static BlockNBTComponent create(final @NotNull List<? extends ComponentLike> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable ComponentLike separator, final @NotNull Pos pos) {
42+
static BlockNBTComponent create(final @NotNull List<? extends ComponentLike> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable ComponentLike separator, final boolean plain, final @NotNull Pos pos) {
4343
return new BlockNBTComponentImpl(
4444
ComponentLike.asComponents(children, IS_NOT_EMPTY),
4545
requireNonNull(style, "style"),
4646
requireNonNull(nbtPath, "nbtPath"),
4747
interpret,
4848
ComponentLike.unbox(separator),
49+
plain,
4950
requireNonNull(pos, "pos")
5051
);
5152
}
5253

53-
BlockNBTComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable Component separator, final @NotNull Pos pos) {
54-
super(children, style, nbtPath, interpret, separator);
54+
BlockNBTComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable Component separator, final boolean plain, final @NotNull Pos pos) {
55+
super(children, style, nbtPath, interpret, separator, plain);
5556
this.pos = pos;
5657
}
5758

5859
@Override
5960
public @NotNull BlockNBTComponent nbtPath(final @NotNull String nbtPath) {
6061
if (Objects.equals(this.nbtPath, nbtPath)) return this;
61-
return create(this.children, this.style, nbtPath, this.interpret, this.separator, this.pos);
62+
return create(this.children, this.style, nbtPath, this.interpret, this.separator, this.plain, this.pos);
6263
}
6364

6465
@Override
6566
public @NotNull BlockNBTComponent interpret(final boolean interpret) {
6667
if (this.interpret == interpret) return this;
67-
return create(this.children, this.style, this.nbtPath, interpret, this.separator, this.pos);
68+
return create(this.children, this.style, this.nbtPath, interpret, this.separator, this.plain, this.pos);
6869
}
6970

7071
@Override
@@ -74,7 +75,13 @@ static BlockNBTComponent create(final @NotNull List<? extends ComponentLike> chi
7475

7576
@Override
7677
public @NotNull BlockNBTComponent separator(final @Nullable ComponentLike separator) {
77-
return create(this.children, this.style, this.nbtPath, this.interpret, separator, this.pos);
78+
return create(this.children, this.style, this.nbtPath, this.interpret, separator, this.plain, this.pos);
79+
}
80+
81+
@Override
82+
public @NotNull BlockNBTComponent plain(final boolean plain) {
83+
if (this.plain == plain) return this;
84+
return create(this.children, this.style, this.nbtPath, this.interpret, this.separator, plain, this.pos);
7885
}
7986

8087
@Override
@@ -84,17 +91,17 @@ static BlockNBTComponent create(final @NotNull List<? extends ComponentLike> chi
8491

8592
@Override
8693
public @NotNull BlockNBTComponent pos(final @NotNull Pos pos) {
87-
return create(this.children, this.style, this.nbtPath, this.interpret, this.separator, pos);
94+
return create(this.children, this.style, this.nbtPath, this.interpret, this.separator, this.plain, pos);
8895
}
8996

9097
@Override
9198
public @NotNull BlockNBTComponent children(final @NotNull List<? extends ComponentLike> children) {
92-
return create(children, this.style, this.nbtPath, this.interpret, this.separator, this.pos);
99+
return create(children, this.style, this.nbtPath, this.interpret, this.separator, this.plain, this.pos);
93100
}
94101

95102
@Override
96103
public @NotNull BlockNBTComponent style(final @NotNull Style style) {
97-
return create(this.children, style, this.nbtPath, this.interpret, this.separator, this.pos);
104+
return create(this.children, style, this.nbtPath, this.interpret, this.separator, this.plain, this.pos);
98105
}
99106

100107
@Override
@@ -144,7 +151,7 @@ static final class BuilderImpl extends AbstractNBTComponentBuilder<BlockNBTCompo
144151
public @NotNull BlockNBTComponent build() {
145152
if (this.nbtPath == null) throw new IllegalStateException("nbt path must be set");
146153
if (this.pos == null) throw new IllegalStateException("pos must be set");
147-
return create(this.children, this.buildStyle(), this.nbtPath, this.interpret, this.separator, this.pos);
154+
return create(this.children, this.buildStyle(), this.nbtPath, this.interpret, this.separator, this.plain, this.pos);
148155
}
149156
}
150157

api/src/main/java/net/kyori/adventure/text/Component.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public interface Component extends ComponentBuilderApplicable, ComponentLike, Ex
366366
*/
367367
@Contract(value = "_, _, _, _ -> new", pure = true)
368368
static @NotNull BlockNBTComponent blockNBT(final @NotNull String nbtPath, final boolean interpret, final @Nullable ComponentLike separator, final BlockNBTComponent.@NotNull Pos pos) {
369-
return BlockNBTComponentImpl.create(Collections.emptyList(), Style.empty(), nbtPath, interpret, separator, pos);
369+
return BlockNBTComponentImpl.create(Collections.emptyList(), Style.empty(), nbtPath, interpret, separator, NBTComponentImpl.PLAIN_DEFAULT, pos);
370370
}
371371

372372
/*
@@ -610,7 +610,21 @@ public interface Component extends ComponentBuilderApplicable, ComponentLike, Ex
610610
*/
611611
@Contract(value = "_ -> new", pure = true)
612612
static @NotNull ObjectComponent object(final @NotNull ObjectContents objectContents) {
613-
return ObjectComponentImpl.create(Collections.emptyList(), Style.empty(), objectContents);
613+
return object(objectContents, null);
614+
}
615+
616+
/**
617+
* Creates an object component with the given contents and optional fallback component.
618+
*
619+
* @param objectContents the contents
620+
* @param fallback the fallback
621+
* @return an object component
622+
* @since 4.27.0
623+
* @sinceMinecraft 26.1
624+
*/
625+
@Contract(value = "_, _ -> new", pure = true)
626+
static @NotNull ObjectComponent object(final @NotNull ObjectContents objectContents, final @Nullable ComponentLike fallback) {
627+
return ObjectComponentImpl.create(Collections.emptyList(), Style.empty(), objectContents, ComponentLike.unbox(fallback));
614628
}
615629

616630
/*
@@ -793,7 +807,7 @@ public interface Component extends ComponentBuilderApplicable, ComponentLike, Ex
793807
*/
794808
@Contract(value = "_, _, _, _ -> new", pure = true)
795809
static @NotNull StorageNBTComponent storageNBT(final @NotNull String nbtPath, final boolean interpret, final @Nullable ComponentLike separator, final @NotNull Key storage) {
796-
return StorageNBTComponentImpl.create(Collections.emptyList(), Style.empty(), nbtPath, interpret, separator, storage);
810+
return StorageNBTComponentImpl.create(Collections.emptyList(), Style.empty(), nbtPath, interpret, separator, NBTComponentImpl.PLAIN_DEFAULT, storage);
797811
}
798812

799813
/*

api/src/main/java/net/kyori/adventure/text/EntityNBTComponentImpl.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,33 @@
3535
final class EntityNBTComponentImpl extends NBTComponentImpl<EntityNBTComponent, EntityNBTComponent.Builder> implements EntityNBTComponent {
3636
private final String selector;
3737

38-
static EntityNBTComponent create(final @NotNull List<? extends ComponentLike> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable ComponentLike separator, final String selector) {
38+
static EntityNBTComponent create(final @NotNull List<? extends ComponentLike> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable ComponentLike separator, final boolean plain, final String selector) {
3939
return new EntityNBTComponentImpl(
4040
ComponentLike.asComponents(children, IS_NOT_EMPTY),
4141
requireNonNull(style, "style"),
4242
requireNonNull(nbtPath, "nbtPath"),
4343
interpret,
4444
ComponentLike.unbox(separator),
45+
plain,
4546
requireNonNull(selector, "selector")
4647
);
4748
}
4849

49-
EntityNBTComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable Component separator, final String selector) {
50-
super(children, style, nbtPath, interpret, separator);
50+
EntityNBTComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable Component separator, final boolean plain, final String selector) {
51+
super(children, style, nbtPath, interpret, separator, plain);
5152
this.selector = selector;
5253
}
5354

5455
@Override
5556
public @NotNull EntityNBTComponent nbtPath(final @NotNull String nbtPath) {
5657
if (Objects.equals(this.nbtPath, nbtPath)) return this;
57-
return create(this.children, this.style, nbtPath, this.interpret, this.separator, this.selector);
58+
return create(this.children, this.style, nbtPath, this.interpret, this.separator, this.plain, this.selector);
5859
}
5960

6061
@Override
6162
public @NotNull EntityNBTComponent interpret(final boolean interpret) {
6263
if (this.interpret == interpret) return this;
63-
return create(this.children, this.style, this.nbtPath, interpret, this.separator, this.selector);
64+
return create(this.children, this.style, this.nbtPath, interpret, this.separator, this.plain, this.selector);
6465
}
6566

6667
@Override
@@ -70,7 +71,7 @@ static EntityNBTComponent create(final @NotNull List<? extends ComponentLike> ch
7071

7172
@Override
7273
public @NotNull EntityNBTComponent separator(final @Nullable ComponentLike separator) {
73-
return create(this.children, this.style, this.nbtPath, this.interpret, separator, this.selector);
74+
return create(this.children, this.style, this.nbtPath, this.interpret, separator, this.plain, this.selector);
7475
}
7576

7677
@Override
@@ -81,17 +82,23 @@ static EntityNBTComponent create(final @NotNull List<? extends ComponentLike> ch
8182
@Override
8283
public @NotNull EntityNBTComponent selector(final @NotNull String selector) {
8384
if (Objects.equals(this.selector, selector)) return this;
84-
return create(this.children, this.style, this.nbtPath, this.interpret, this.separator, selector);
85+
return create(this.children, this.style, this.nbtPath, this.interpret, this.separator, this.plain, selector);
86+
}
87+
88+
@Override
89+
public @NotNull EntityNBTComponent plain(final boolean plain) {
90+
if (this.plain == plain) return this;
91+
return create(this.children, this.style, this.nbtPath, this.interpret, this.separator, plain, this.selector);
8592
}
8693

8794
@Override
8895
public @NotNull EntityNBTComponent children(final @NotNull List<? extends ComponentLike> children) {
89-
return create(children, this.style, this.nbtPath, this.interpret, this.separator, this.selector);
96+
return create(children, this.style, this.nbtPath, this.interpret, this.separator, this.plain, this.selector);
9097
}
9198

9299
@Override
93100
public @NotNull EntityNBTComponent style(final @NotNull Style style) {
94-
return create(this.children, style, this.nbtPath, this.interpret, this.separator, this.selector);
101+
return create(this.children, style, this.nbtPath, this.interpret, this.separator, this.plain, this.selector);
95102
}
96103

97104
@Override
@@ -141,7 +148,7 @@ static final class BuilderImpl extends AbstractNBTComponentBuilder<EntityNBTComp
141148
public @NotNull EntityNBTComponent build() {
142149
if (this.nbtPath == null) throw new IllegalStateException("nbt path must be set");
143150
if (this.selector == null) throw new IllegalStateException("selector must be set");
144-
return create(this.children, this.buildStyle(), this.nbtPath, this.interpret, this.separator, this.selector);
151+
return create(this.children, this.buildStyle(), this.nbtPath, this.interpret, this.separator, this.plain, this.selector);
145152
}
146153
}
147154
}

api/src/main/java/net/kyori/adventure/text/NBTComponent.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public interface NBTComponent<C extends NBTComponent<C, B>, B extends NBTCompone
8181
/**
8282
* Sets if we should be interpreting.
8383
*
84+
* <p>Note that since <em>Minecraft: Java Edition</em> 26.1 this cannot be {@code true} if
85+
* {@link #plain()} is also {@code true}.</p>
86+
*
8487
* @param interpret if we should be interpreting.
8588
* @return an NBT component
8689
* @since 4.0.0
@@ -100,18 +103,43 @@ public interface NBTComponent<C extends NBTComponent<C, B>, B extends NBTCompone
100103
* Sets the separator.
101104
*
102105
* @param separator the separator
103-
* @return the separator
106+
* @return an NBT component
104107
* @since 4.8.0
105108
*/
109+
@Contract(pure = true)
106110
@NotNull C separator(final @Nullable ComponentLike separator);
107111

112+
/**
113+
* Gets if this component should be printed without any formatting if we are not interpreting.
114+
*
115+
* @return if this component should be printed without any formatting if we are not interpreting
116+
* @since 4.27.0
117+
* @sinceMinecraft 26.1
118+
*/
119+
boolean plain();
120+
121+
/**
122+
* Sets if this component should be printed without any formatting if we are not interpreting.
123+
*
124+
* <p>Note that since <em>Minecraft: Java Edition</em> 26.1 this cannot be {@code true} if
125+
* {@link #interpret()} is also {@code true}.</p>
126+
*
127+
* @param plain if this component should be printed without any formatting if we are not interpreting
128+
* @return an NBT component
129+
* @since 4.27.0
130+
* @sinceMinecraft 26.1
131+
*/
132+
@Contract(pure = true)
133+
@NotNull C plain(final boolean plain);
134+
108135
@Override
109136
default @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
110137
return Stream.concat(
111138
Stream.of(
112139
ExaminableProperty.of("nbtPath", this.nbtPath()),
113140
ExaminableProperty.of("interpret", this.interpret()),
114-
ExaminableProperty.of("separator", this.separator())
141+
ExaminableProperty.of("separator", this.separator()),
142+
ExaminableProperty.of("plain", this.plain())
115143
),
116144
BuildableComponent.super.examinableProperties()
117145
);

api/src/main/java/net/kyori/adventure/text/NBTComponentBuilder.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public interface NBTComponentBuilder<C extends NBTComponent<C, B>, B extends NBT
5252
/**
5353
* Sets whether to interpret.
5454
*
55+
* <p>Note that since <em>Minecraft: Java Edition</em> 26.1 this cannot be {@code true} if
56+
* {@link #plain(boolean)} was set to {@code true}.</p>
57+
*
5558
* @param interpret if we should be interpreting
5659
* @return this builder
5760
* @since 4.0.0
@@ -68,4 +71,18 @@ public interface NBTComponentBuilder<C extends NBTComponent<C, B>, B extends NBT
6871
*/
6972
@Contract("_ -> this")
7073
@NotNull B separator(final @Nullable ComponentLike separator);
74+
75+
/**
76+
* Sets whether to display the NBT path with formatting or as plain text if we are not interpreting.
77+
*
78+
* <p>Note that since <em>Minecraft: Java Edition</em> 26.1 this cannot be {@code true} if
79+
* {@link #interpret(boolean)} was set to {@code true}.</p>
80+
*
81+
* @param plain whether to display the NBT path with formatting or as plain text if we are not interpreting.
82+
* @return this builder
83+
* @since 4.27.0
84+
* @sinceMinecraft 26.1
85+
*/
86+
@Contract("_ -> this")
87+
@NotNull B plain(final boolean plain);
7188
}

api/src/main/java/net/kyori/adventure/text/NBTComponentImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,25 @@
2525

2626
import java.util.List;
2727
import java.util.Objects;
28+
import net.kyori.adventure.internal.Internals;
2829
import net.kyori.adventure.text.format.Style;
2930
import org.jetbrains.annotations.NotNull;
3031
import org.jetbrains.annotations.Nullable;
3132

3233
abstract class NBTComponentImpl<C extends NBTComponent<C, B>, B extends NBTComponentBuilder<C, B>> extends AbstractComponent implements NBTComponent<C, B> {
3334
static final boolean INTERPRET_DEFAULT = false;
35+
static final boolean PLAIN_DEFAULT = false;
3436
final String nbtPath;
3537
final boolean interpret;
3638
final @Nullable Component separator;
39+
final boolean plain;
3740

38-
NBTComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable Component separator) {
41+
NBTComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable Component separator, final boolean plain) {
3942
super(children, style);
4043
this.nbtPath = nbtPath;
4144
this.interpret = interpret;
4245
this.separator = separator;
46+
this.plain = plain;
4347
}
4448

4549
@Override
@@ -52,6 +56,11 @@ public boolean interpret() {
5256
return this.interpret;
5357
}
5458

59+
@Override
60+
public boolean plain() {
61+
return this.plain;
62+
}
63+
5564
@Override
5665
public abstract @NotNull B toBuilder();
5766

@@ -61,7 +70,7 @@ public boolean equals(final @Nullable Object other) {
6170
if (!(other instanceof NBTComponent)) return false;
6271
if (!super.equals(other)) return false;
6372
final NBTComponent<?, ?> that = (NBTComponent<?, ?>) other;
64-
return Objects.equals(this.nbtPath, that.nbtPath()) && this.interpret == that.interpret() && Objects.equals(this.separator, that.separator());
73+
return Objects.equals(this.nbtPath, that.nbtPath()) && this.interpret == that.interpret() && Objects.equals(this.separator, that.separator()) && this.plain == that.plain();
6574
}
6675

6776
@Override
@@ -70,6 +79,12 @@ public int hashCode() {
7079
result = (31 * result) + this.nbtPath.hashCode();
7180
result = (31 * result) + Boolean.hashCode(this.interpret);
7281
result = (31 * result) + Objects.hashCode(this.separator);
82+
result = (31 * result) + Boolean.hashCode(this.plain);
7383
return result;
7484
}
85+
86+
@Override
87+
public String toString() {
88+
return Internals.toString(this);
89+
}
7590
}

0 commit comments

Comments
 (0)