Skip to content

Commit a9b5019

Browse files
committed
Add Adventure support on legacy servers (closes #38)
1 parent 56a6518 commit a9b5019

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# FastBoard
22

33
[![Java CI](https://github.com/MrMicky-FR/FastBoard/actions/workflows/build.yml/badge.svg)](https://github.com/MrMicky-FR/FastBoard/actions/workflows/build.yml)
4-
[![Maven Central](https://img.shields.io/maven-central/v/fr.mrmicky/fastboard.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22fr.mrmicky%22%20AND%20a:%22fastboard%22)
4+
[![Maven Central](https://img.shields.io/maven-central/v/fr.mrmicky/fastboard.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/fr.mrmicky/fastboard)
55
[![Discord](https://img.shields.io/discord/390919659874156560.svg?colorB=5865f2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/q9UwaBT)
66

77
Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20 support.
@@ -57,12 +57,12 @@ Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20
5757
<dependency>
5858
<groupId>fr.mrmicky</groupId>
5959
<artifactId>fastboard</artifactId>
60-
<version>2.0.0</version>
60+
<version>2.0.1</version>
6161
</dependency>
6262
</dependencies>
6363
```
6464

65-
When using Maven, make sure to build directly with Maven and not with your IDE configuration. (on IntelliJ IDEA: in the `Maven` tab on the right, in `Lifecycle`, use `package`).
65+
When using Maven, make sure to build directly with Maven and not with your IDE configuration (on IntelliJ IDEA: in the `Maven` tab on the right, in `Lifecycle`, use `package`).
6666

6767
### Gradle
6868

@@ -76,7 +76,7 @@ repositories {
7676
}
7777
7878
dependencies {
79-
implementation 'fr.mrmicky:fastboard:2.0.0'
79+
implementation 'fr.mrmicky:fastboard:2.0.1'
8080
}
8181
8282
shadowJar {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>fr.mrmicky</groupId>
88
<artifactId>fastboard</artifactId>
9-
<version>2.0.0</version>
9+
<version>2.0.1</version>
1010

1111
<name>FastBoard</name>
1212
<description>Lightweight packet-based scoreboard API for Bukkit plugins.</description>

src/main/java/fr/mrmicky/fastboard/FastBoard.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ protected Object toMinecraftComponent(String line) throws Throwable {
138138
return Array.get(MESSAGE_FROM_STRING.invoke(line), 0);
139139
}
140140

141+
@Override
142+
protected String serializeLine(String value) {
143+
return value;
144+
}
145+
141146
@Override
142147
protected String emptyLine() {
143148
return "";

src/main/java/fr/mrmicky/fastboard/FastBoardBase.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* The project is on <a href="https://github.com/MrMicky-FR/FastBoard">GitHub</a>.
5252
*
5353
* @author MrMicky
54-
* @version 2.0.0
54+
* @version 2.0.1
5555
*/
5656
public abstract class FastBoardBase<T> {
5757

@@ -411,6 +411,8 @@ public void delete() {
411411

412412
protected abstract Object toMinecraftComponent(T value) throws Throwable;
413413

414+
protected abstract String serializeLine(T value);
415+
414416
protected abstract T emptyLine();
415417

416418
private void checkLineNumber(int line, boolean checkInRange, boolean checkMax) {
@@ -561,7 +563,8 @@ private void setField(Object packet, Class<?> fieldType, Object value, int count
561563

562564
private void setComponentField(Object packet, T value, int count) throws Throwable {
563565
if (!VersionType.V1_13.isHigherOrEqual()) {
564-
setField(packet, String.class, value != null ? value : "", count);
566+
String line = value != null ? serializeLine(value) : "";
567+
setField(packet, String.class, line, count);
565568
return;
566569
}
567570

src/main/java/fr/mrmicky/fastboard/adventure/FastBoard.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,19 @@ protected Object toMinecraftComponent(Component component) throws Throwable {
9191
// If the server isn't running adventure natively, we convert the component to legacy text
9292
// and then to a Minecraft chat component
9393
if (!ADVENTURE_SUPPORT) {
94-
String legacy = LegacyComponentSerializer.legacySection().serialize(component);
94+
String legacy = serializeLine(component);
9595

9696
return Array.get(COMPONENT_METHOD.invoke(legacy), 0);
9797
}
9898

9999
return COMPONENT_METHOD.invoke(component);
100100
}
101101

102+
@Override
103+
protected String serializeLine(Component value) {
104+
return LegacyComponentSerializer.legacySection().serialize(value);
105+
}
106+
102107
@Override
103108
protected Component emptyLine() {
104109
return Component.empty();

0 commit comments

Comments
 (0)