Skip to content

Commit

Permalink
Add Adventure support on legacy servers (closes #38)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Oct 14, 2023
1 parent 56a6518 commit a9b5019
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# FastBoard

[![Java CI](https://github.com/MrMicky-FR/FastBoard/actions/workflows/build.yml/badge.svg)](https://github.com/MrMicky-FR/FastBoard/actions/workflows/build.yml)
[![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)
[![Maven Central](https://img.shields.io/maven-central/v/fr.mrmicky/fastboard.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/fr.mrmicky/fastboard)
[![Discord](https://img.shields.io/discord/390919659874156560.svg?colorB=5865f2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/q9UwaBT)

Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20 support.
Expand Down Expand Up @@ -57,12 +57,12 @@ Lightweight packet-based scoreboard API for Bukkit plugins, with 1.7.10 to 1.20
<dependency>
<groupId>fr.mrmicky</groupId>
<artifactId>fastboard</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
</dependency>
</dependencies>
```

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`).
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`).

### Gradle

Expand All @@ -76,7 +76,7 @@ repositories {
}
dependencies {
implementation 'fr.mrmicky:fastboard:2.0.0'
implementation 'fr.mrmicky:fastboard:2.0.1'
}
shadowJar {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.mrmicky</groupId>
<artifactId>fastboard</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>

<name>FastBoard</name>
<description>Lightweight packet-based scoreboard API for Bukkit plugins.</description>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/fr/mrmicky/fastboard/FastBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ protected Object toMinecraftComponent(String line) throws Throwable {
return Array.get(MESSAGE_FROM_STRING.invoke(line), 0);
}

@Override
protected String serializeLine(String value) {
return value;
}

@Override
protected String emptyLine() {
return "";
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/fr/mrmicky/fastboard/FastBoardBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* The project is on <a href="https://github.com/MrMicky-FR/FastBoard">GitHub</a>.
*
* @author MrMicky
* @version 2.0.0
* @version 2.0.1
*/
public abstract class FastBoardBase<T> {

Expand Down Expand Up @@ -411,6 +411,8 @@ public void delete() {

protected abstract Object toMinecraftComponent(T value) throws Throwable;

protected abstract String serializeLine(T value);

protected abstract T emptyLine();

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

private void setComponentField(Object packet, T value, int count) throws Throwable {
if (!VersionType.V1_13.isHigherOrEqual()) {
setField(packet, String.class, value != null ? value : "", count);
String line = value != null ? serializeLine(value) : "";
setField(packet, String.class, line, count);
return;
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/fr/mrmicky/fastboard/adventure/FastBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ protected Object toMinecraftComponent(Component component) throws Throwable {
// If the server isn't running adventure natively, we convert the component to legacy text
// and then to a Minecraft chat component
if (!ADVENTURE_SUPPORT) {
String legacy = LegacyComponentSerializer.legacySection().serialize(component);
String legacy = serializeLine(component);

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

return COMPONENT_METHOD.invoke(component);
}

@Override
protected String serializeLine(Component value) {
return LegacyComponentSerializer.legacySection().serialize(value);
}

@Override
protected Component emptyLine() {
return Component.empty();
Expand Down

0 comments on commit a9b5019

Please sign in to comment.