Skip to content

Commit 3af220d

Browse files
committed
feat: 26.1 changes
1 parent 403e896 commit 3af220d

File tree

20 files changed

+375
-67
lines changed

20 files changed

+375
-67
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: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public interface NBTComponent<C extends NBTComponent<C, B>, B extends NBTCompone
8181
/**
8282
* Sets if we should be interpreting.
8383
*
84+
* <p>Note that this cannot be {@code true} if {@link #plain()} is also {@code true}.</p>
85+
*
8486
* @param interpret if we should be interpreting.
8587
* @return an NBT component
8688
* @since 4.0.0
@@ -100,11 +102,34 @@ public interface NBTComponent<C extends NBTComponent<C, B>, B extends NBTCompone
100102
* Sets the separator.
101103
*
102104
* @param separator the separator
103-
* @return the separator
105+
* @return an NBT component
104106
* @since 4.8.0
105107
*/
108+
@Contract(pure = true)
106109
@NotNull C separator(final @Nullable ComponentLike separator);
107110

111+
/**
112+
* Gets if this component should be printed without any formatting if we are not interpreting.
113+
*
114+
* @return if this component should be printed without any formatting if we are not interpreting
115+
* @since 4.27.0
116+
* @sinceMinecraft 26.1
117+
*/
118+
boolean plain();
119+
120+
/**
121+
* Sets if this component should be printed without any formatting if we are not interpreting.
122+
*
123+
* <p>Note that this cannot be {@code true} if {@link #interpret()} is also {@code true}.</p>
124+
*
125+
* @param plain if this component should be printed without any formatting if we are not interpreting
126+
* @return an NBT component
127+
* @since 4.27.0
128+
* @sinceMinecraft 26.1
129+
*/
130+
@Contract(pure = true)
131+
@NotNull C plain(final boolean plain);
132+
108133
@Override
109134
default @NotNull Stream<? extends ExaminableProperty> examinableProperties() {
110135
return Stream.concat(

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public interface NBTComponentBuilder<C extends NBTComponent<C, B>, B extends NBT
5252
/**
5353
* Sets whether to interpret.
5454
*
55+
* <p>Note that this cannot be {@code true} if {@link #plain(boolean)} was set to {@code true}.</p>
56+
*
5557
* @param interpret if we should be interpreting
5658
* @return this builder
5759
* @since 4.0.0
@@ -68,4 +70,17 @@ public interface NBTComponentBuilder<C extends NBTComponent<C, B>, B extends NBT
6870
*/
6971
@Contract("_ -> this")
7072
@NotNull B separator(final @Nullable ComponentLike separator);
73+
74+
/**
75+
* Sets whether to display the NBT path with formatting or as plain text if we are not interpreting.
76+
*
77+
* <p>Note that this cannot be {@code true} if {@link #interpret(boolean)} was set to {@code true}.</p>
78+
*
79+
* @param plain whether to display the NBT path with formatting or as plain text if we are not interpreting.
80+
* @return this builder
81+
* @since 4.27.0
82+
* @sinceMinecraft 26.1
83+
*/
84+
@Contract("_ -> this")
85+
@NotNull B plain(final boolean plain);
7186
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131

3232
abstract class NBTComponentImpl<C extends NBTComponent<C, B>, B extends NBTComponentBuilder<C, B>> extends AbstractComponent implements NBTComponent<C, B> {
3333
static final boolean INTERPRET_DEFAULT = false;
34+
static final boolean PLAIN_DEFAULT = false;
3435
final String nbtPath;
3536
final boolean interpret;
3637
final @Nullable Component separator;
38+
final boolean plain;
3739

38-
NBTComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable Component separator) {
40+
NBTComponentImpl(final @NotNull List<Component> children, final @NotNull Style style, final String nbtPath, final boolean interpret, final @Nullable Component separator, final boolean plain) {
3941
super(children, style);
4042
this.nbtPath = nbtPath;
4143
this.interpret = interpret;
4244
this.separator = separator;
45+
this.plain = plain;
4346
}
4447

4548
@Override
@@ -52,6 +55,11 @@ public boolean interpret() {
5255
return this.interpret;
5356
}
5457

58+
@Override
59+
public boolean plain() {
60+
return this.plain;
61+
}
62+
5563
@Override
5664
public abstract @NotNull B toBuilder();
5765

@@ -61,7 +69,7 @@ public boolean equals(final @Nullable Object other) {
6169
if (!(other instanceof NBTComponent)) return false;
6270
if (!super.equals(other)) return false;
6371
final NBTComponent<?, ?> that = (NBTComponent<?, ?>) other;
64-
return Objects.equals(this.nbtPath, that.nbtPath()) && this.interpret == that.interpret() && Objects.equals(this.separator, that.separator());
72+
return Objects.equals(this.nbtPath, that.nbtPath()) && this.interpret == that.interpret() && Objects.equals(this.separator, that.separator()) && this.plain == that.plain();
6573
}
6674

6775
@Override
@@ -70,6 +78,7 @@ public int hashCode() {
7078
result = (31 * result) + this.nbtPath.hashCode();
7179
result = (31 * result) + Boolean.hashCode(this.interpret);
7280
result = (31 * result) + Objects.hashCode(this.separator);
81+
result = (31 * result) + Boolean.hashCode(this.plain);
7382
return result;
7483
}
7584
}

0 commit comments

Comments
 (0)