From d433b0d3bc6b3e0da65fcceb4e3d15dc9de0e11e Mon Sep 17 00:00:00 2001 From: Kieran Wallbanks Date: Fri, 26 Mar 2021 19:42:04 +0000 Subject: [PATCH] Write scoreboard values using legacy strings --- .../server/play/ScoreboardObjectivePacket.java | 2 +- .../minestom/server/utils/binary/BinaryWriter.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java index ac8bd077d..3671b8503 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java @@ -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()); } } diff --git a/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java index b130feab2..b73adc2cb 100644 --- a/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java @@ -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. *