Merge pull request #186 from kezz/fix-scorebord-value

Write scoreboard values using legacy strings
This commit is contained in:
TheMode 2021-03-26 20:47:31 +01:00 committed by GitHub
commit d41402c2e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -38,7 +38,7 @@ public class ScoreboardObjectivePacket implements ComponentHoldingServerPacket {
writer.writeByte(mode);
if (mode == 0 || mode == 2) {
writer.writeComponent(objectiveValue);
writer.writeComponentAsLegacy(objectiveValue);
writer.writeVarInt(type.ordinal());
}
}

View File

@ -3,6 +3,7 @@ package net.minestom.server.utils.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.minestom.server.MinecraftServer;
import net.minestom.server.adventure.AdventureSerializer;
import net.minestom.server.item.ItemStack;
@ -73,6 +74,17 @@ public class BinaryWriter extends OutputStream {
this.writeSizedString(AdventureSerializer.serialize(component));
}
/**
* Writes a component to the buffer as a sized string. This method uses
* {@link LegacyComponentSerializer} to convert the component into a string
* containing the legacy section signs.
*
* @param component the component
*/
public void writeComponentAsLegacy(@NotNull Component component) {
this.writeSizedString(LegacyComponentSerializer.legacySection().serialize(component));
}
/**
* Writes a single boolean to the buffer.
*