Skip to content

Commit

Permalink
Fix "Can not set java.lang.String field" with legacy adventure
Browse files Browse the repository at this point in the history
  • Loading branch information
xism4 committed Oct 15, 2023
1 parent 5c9d893 commit da8519b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/src/main/java/com/xism4/sternalboard/SternalBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ public void delete() {

protected abstract void sendLineChange(int score) throws Throwable;

protected abstract String serializeLine(T value);

protected abstract Object toMinecraftComponent(T value) throws Throwable;

protected abstract T emptyLine();
Expand Down Expand Up @@ -584,7 +586,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
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,22 @@ protected Object toMinecraftComponent(Component component) throws Throwable {
return EMPTY_COMPONENT;
}

// 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 da8519b

Please sign in to comment.