Skip to content

Commit 7026eab

Browse files
committed
Fix Bedrock colors - they don't reset the style
1 parent 44320b1 commit 7026eab

File tree

9 files changed

+123
-87
lines changed

9 files changed

+123
-87
lines changed

inkymessage/src/main/java/ink/glowing/text/InkyMessage.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public sealed interface InkyMessage extends ComponentSerializer<Component, Compo
3333
* @see StandardModifiers#standardModifiers()
3434
* @see StandardPlaceholders#standardPlaceholders()
3535
* @see StandardSymbolicStyles#notchianFormat()
36-
* @see StandardSymbolicStyles#notchianResetSymbol()
36+
* @see StandardSymbolicStyles#standardResetSymbol()
3737
* @see StandardReplacers#urlReplacer()
3838
*/
3939
@Contract(pure = true)
@@ -301,7 +301,7 @@ class Builder implements AbstractBuilder<InkyMessage> {
301301
case Modifier<?> mod -> addModifier(mod);
302302
case Replacer rp -> addReplacer(rp);
303303
case SymbolicStyle sym -> addSymbolic(sym);
304-
default -> throw new IllegalArgumentException("Unknown stable ink type: " + ink.getClass().getSimpleName());
304+
default -> throw new IllegalArgumentException("Unknown ink type: " + ink.getClass().getSimpleName());
305305
};
306306
}
307307

@@ -331,8 +331,7 @@ class Builder implements AbstractBuilder<InkyMessage> {
331331
@Contract("_ -> this")
332332
public @NotNull InkyMessage.Builder replacers(@NotNull Iterable<? extends @NotNull Replacer> replacers) {
333333
this.replacers = new HashSet<>();
334-
addReplacers(replacers);
335-
return this;
334+
return addReplacers(replacers);
336335
}
337336

338337
@Contract("_ -> this")
@@ -366,15 +365,13 @@ class Builder implements AbstractBuilder<InkyMessage> {
366365
@Contract("_ -> this")
367366
public @NotNull InkyMessage.Builder placeholders(@NotNull Collection<? extends @NotNull Placeholder> placeholders) {
368367
this.placeholders = new HashMap<>(placeholders.size());
369-
addPlaceholders(placeholders);
370-
return this;
368+
return addPlaceholders(placeholders);
371369
}
372370

373371
@Contract("_ -> this")
374372
public @NotNull InkyMessage.Builder placeholders(@NotNull Iterable<? extends @NotNull Placeholder> placeholders) {
375373
this.placeholders = new HashMap<>();
376-
addPlaceholders(placeholders);
377-
return this;
374+
return addPlaceholders(placeholders);
378375
}
379376

380377
@Contract("_ -> this")
@@ -414,15 +411,13 @@ class Builder implements AbstractBuilder<InkyMessage> {
414411
@Contract("_ -> this")
415412
public @NotNull InkyMessage.Builder modifiers(@NotNull Collection<? extends @NotNull Modifier<?>> modifiers) {
416413
this.modifiers = new HashMap<>(modifiers.size());
417-
addModifiers(modifiers);
418-
return this;
414+
return addModifiers(modifiers);
419415
}
420416

421417
@Contract("_ -> this")
422418
public @NotNull InkyMessage.Builder modifiers(@NotNull Iterable<? extends @NotNull Modifier<?>> modifiers) {
423419
this.modifiers = new HashMap<>();
424-
addModifiers(modifiers);
425-
return this;
420+
return addModifiers(modifiers);
426421
}
427422

428423
@Contract("_ -> this")
@@ -468,8 +463,7 @@ class Builder implements AbstractBuilder<InkyMessage> {
468463
@Contract("_ -> this")
469464
public @NotNull InkyMessage.Builder symbolics(@NotNull Collection<? extends @NotNull SymbolicStyle> symbolics) {
470465
this.symbolics = new HashMap<>(symbolics.size());
471-
addSymbolics(symbolics);
472-
return this;
466+
return addSymbolics(symbolics);
473467
}
474468

475469
@Contract("_ -> this")

inkymessage/src/main/java/ink/glowing/text/InkyMessageImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
import static ink.glowing.text.replace.ReplacementMatcher.replacementMatcher;
2222
import static ink.glowing.text.replace.StandardReplacers.urlReplacer;
2323
import static ink.glowing.text.symbolic.StandardSymbolicStyles.notchianFormat;
24-
import static ink.glowing.text.symbolic.StandardSymbolicStyles.notchianResetSymbol;
24+
import static ink.glowing.text.symbolic.StandardSymbolicStyles.standardResetSymbol;
2525
import static java.util.Collections.unmodifiableCollection;
2626
import static java.util.Collections.unmodifiableMap;
2727

2828
final class InkyMessageImpl implements InkyMessage {
2929
static final InkyMessage STANDARD = InkyMessage.builder()
3030
.addModifiers(standardModifiers())
3131
.addSymbolics(notchianFormat())
32-
.symbolicReset(notchianResetSymbol())
32+
.symbolicReset(standardResetSymbol())
3333
.addReplacer(urlReplacer())
3434
.build();
3535

inkymessage/src/main/java/ink/glowing/text/Stringifier.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,23 +184,12 @@ public boolean isApplied(@NotNull Style at) {
184184
@Override
185185
public boolean equals(Object obj) {
186186
if (obj == this) return true;
187-
if (obj == null || obj.getClass() != this.getClass()) return false;
188-
var that = (HexSymbolicStyle) obj;
189-
return Objects.equals(this.color, that.color) &&
190-
Objects.equals(this.cleanStyle, that.cleanStyle);
187+
return obj instanceof HexSymbolicStyle other && other.color.equals(color);
191188
}
192189

193190
@Override
194191
public int hashCode() {
195192
return Objects.hash(color, cleanStyle);
196193
}
197-
198-
@Override
199-
public String toString() {
200-
return "HexSymbolicStyle[" +
201-
"color=" + color + ", " +
202-
"cleanStyle=" + cleanStyle +
203-
']';
204-
}
205194
}
206195
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package ink.glowing.text.symbolic;
2+
3+
import net.kyori.adventure.text.format.Style;
4+
import net.kyori.adventure.text.format.TextColor;
5+
import org.jetbrains.annotations.ApiStatus;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.util.Objects;
9+
10+
@ApiStatus.Internal
11+
final class ChainedSymbolicColor implements SymbolicStyle {
12+
private final char symbol;
13+
private final TextColor color;
14+
private final Style cleanStyle;
15+
16+
ChainedSymbolicColor(char symbol, @NotNull TextColor color) {
17+
this.symbol = symbol;
18+
this.color = color;
19+
this.cleanStyle = Style.style(color);
20+
}
21+
22+
@Override
23+
public char symbol() {
24+
return symbol;
25+
}
26+
27+
@Override
28+
public boolean resets() {
29+
return false;
30+
}
31+
32+
@Override
33+
public boolean isApplied(@NotNull Style at) {
34+
return color.equals(at.color());
35+
}
36+
37+
@Override
38+
public @NotNull Style base() {
39+
return cleanStyle;
40+
}
41+
42+
@Override
43+
public @NotNull Style merge(@NotNull Style other) {
44+
return other.color(color);
45+
}
46+
47+
@Override
48+
public @NotNull Style unmerge(@NotNull Style other) {
49+
return other.color(null);
50+
}
51+
52+
@Override
53+
public boolean equals(Object obj) {
54+
if (obj == this) return true;
55+
return obj instanceof ChainedSymbolicColor other && other.color.equals(color);
56+
}
57+
58+
@Override
59+
public int hashCode() {
60+
return Objects.hash(symbol, color);
61+
}
62+
}

inkymessage/src/main/java/ink/glowing/text/symbolic/ChainedSymbolicDecoration.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,13 @@ public boolean isApplied(@NotNull Style at) {
5252
}
5353

5454
@Override
55-
public boolean equals(Object o) {
56-
if (this == o) return true;
57-
if (!(o instanceof ChainedSymbolicDecoration that)) return false;
58-
return symbol == that.symbol && decoration == that.decoration;
55+
public boolean equals(Object obj) {
56+
if (obj == this) return true;
57+
return obj instanceof ChainedSymbolicDecoration other && other.decoration == decoration;
5958
}
6059

6160
@Override
6261
public int hashCode() {
6362
return Objects.hash(symbol, decoration);
6463
}
65-
66-
@Override
67-
public String toString() {
68-
return "ChainedSymbolicDecoration[" +
69-
"symbol=" + symbol + ", " +
70-
"decoration=" + decoration +
71-
']';
72-
}
7364
}

inkymessage/src/main/java/ink/glowing/text/symbolic/ResettingSymbolicColor.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,13 @@ public boolean isApplied(@NotNull Style at) {
5050
}
5151

5252
@Override
53-
public boolean equals(Object o) {
54-
if (this == o) return true;
55-
if (!(o instanceof ResettingSymbolicColor that)) return false;
56-
return symbol == that.symbol && color.equals(that.color);
53+
public boolean equals(Object obj) {
54+
if (obj == this) return true;
55+
return obj instanceof ResettingSymbolicColor other && other.color.equals(color);
5756
}
5857

5958
@Override
6059
public int hashCode() {
6160
return Objects.hash(symbol, color);
6261
}
63-
64-
@Override
65-
public String toString() {
66-
return "ResettingSymbolicColor[" +
67-
"symbol=" + symbol + ", " +
68-
"color=" + color +
69-
']';
70-
}
7162
}

inkymessage/src/main/java/ink/glowing/text/symbolic/SimpleSymbolicReset.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ public boolean isApplied(@NotNull Style at) {
2323
return Style.empty();
2424
}
2525

26-
@Override
27-
public boolean equals(Object obj) {
28-
return obj instanceof SimpleSymbolicReset(char otherSymbol) && otherSymbol == symbol;
29-
}
30-
3126
@Override
3227
public @NotNull Style merge(@NotNull Style other) {
3328
return Style.empty();
@@ -39,15 +34,12 @@ public boolean equals(Object obj) {
3934
}
4035

4136
@Override
42-
public int hashCode() {
43-
return Objects.hash(symbol);
37+
public boolean equals(Object obj) {
38+
return obj instanceof SimpleSymbolicReset(char otherSymbol) && otherSymbol == symbol;
4439
}
4540

4641
@Override
47-
public String toString() {
48-
return "SimpleSymbolicReset[" +
49-
"symbol=" + symbol + ", " +
50-
"decoration=reset" +
51-
']';
42+
public int hashCode() {
43+
return Objects.hash(symbol);
5244
}
5345
}

inkymessage/src/main/java/ink/glowing/text/symbolic/StandardSymbolicStyles.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,35 @@ public final class StandardSymbolicStyles { private StandardSymbolicStyles() {}
4848
NOTCHIAN_COLORS, NOTCHIAN_DECORATIONS
4949
);
5050

51-
private static final List<SymbolicStyle> BEDROCK_COLORS = GeneralUtils.concat(
52-
ArrayList::new, Collections::unmodifiableList,
53-
NOTCHIAN_COLORS,
54-
List.of(
55-
resettingColor('g', color(0xDDD605)),
56-
resettingColor('h', color(0xE3D4D1)),
57-
resettingColor('i', color(0xCECACA)),
58-
resettingColor('j', color(0x443A3B)),
59-
resettingColor('m', color(0x971607)),
60-
resettingColor('n', color(0xB4684D)),
61-
resettingColor('p', color(0xDEB12D)),
62-
resettingColor('q', color(0x47A036)),
63-
resettingColor('s', color(0x2CBAA8)),
64-
resettingColor('t', color(0x21497B)),
65-
resettingColor('u', color(0x9A5CC6))
66-
)
51+
private static final List<SymbolicStyle> BEDROCK_COLORS = List.of(
52+
chainedColor('0', BLACK),
53+
chainedColor('1', DARK_BLUE),
54+
chainedColor('2', DARK_GREEN),
55+
chainedColor('3', DARK_AQUA),
56+
chainedColor('4', DARK_RED),
57+
chainedColor('5', DARK_PURPLE),
58+
chainedColor('6', GOLD),
59+
chainedColor('7', color(0xC6C6C6)),
60+
chainedColor('8', DARK_GRAY),
61+
chainedColor('9', BLUE),
62+
chainedColor('a', GREEN),
63+
chainedColor('b', AQUA),
64+
chainedColor('c', RED),
65+
chainedColor('d', LIGHT_PURPLE),
66+
chainedColor('e', YELLOW),
67+
chainedColor('f', WHITE),
68+
chainedColor('g', color(0xDDD605)),
69+
chainedColor('h', color(0xE3D4D1)),
70+
chainedColor('i', color(0xCECACA)),
71+
chainedColor('j', color(0x443A3B)),
72+
chainedColor('m', color(0x971607)),
73+
chainedColor('n', color(0xB4684D)),
74+
chainedColor('p', color(0xDEB12D)),
75+
chainedColor('q', color(0x47A036)),
76+
chainedColor('s', color(0x2CBAA8)),
77+
chainedColor('t', color(0x21497B)),
78+
chainedColor('u', color(0x9A5CC6)),
79+
chainedColor('v', color(0xEB7114))
6780
);
6881

6982
private static final List<SymbolicStyle> BEDROCK_DECORATIONS = List.of(
@@ -77,7 +90,7 @@ public final class StandardSymbolicStyles { private StandardSymbolicStyles() {}
7790
BEDROCK_COLORS, BEDROCK_DECORATIONS
7891
);
7992

80-
public static char notchianResetSymbol() {
93+
public static char standardResetSymbol() {
8194
return 'r';
8295
}
8396

@@ -122,6 +135,10 @@ public static char notchianResetSymbol() {
122135
public static @NotNull SymbolicStyle resettingColor(char symbol, @NotNull TextColor color) {
123136
return new ResettingSymbolicColor(symbol, color);
124137
}
138+
139+
public static @NotNull SymbolicStyle chainedColor(char symbol, @NotNull TextColor color) {
140+
return new ChainedSymbolicColor(symbol, color);
141+
}
125142

126143
public static @NotNull SymbolicStyle simpleReset(char symbol) {
127144
return new SimpleSymbolicReset(symbol);

inkymessage/src/test/java/ink/glowing/text/InkyMessageTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,19 +421,19 @@ public void performanceTest(String inky, String mini) {
421421

422422
long start, end;
423423

424-
start = System.currentTimeMillis();
424+
start = System.nanoTime();
425425
for (int i = 0; i < test; i++) {
426426
inkyMessage.deserialize(inky);
427427
}
428-
end = System.currentTimeMillis();
429-
System.out.println(end - start);
428+
end = System.nanoTime();
429+
System.out.println((double) (end - start) / test);
430430

431-
start = System.currentTimeMillis();
431+
start = System.nanoTime();
432432
for (int i = 0; i < test; i++) {
433433
miniMessage.deserialize(mini);
434434
}
435-
end = System.currentTimeMillis();
436-
System.out.println(end - start);
435+
end = System.nanoTime();
436+
System.out.println((double) (end - start) / test);
437437

438438
System.out.println("Inky: " + miniMessage.serialize(inkyMessage.deserialize(inky)));
439439
System.out.println("<reset>");

0 commit comments

Comments
 (0)