From 8606e5d663c5e388e6ef3eabd042ad84a941116c Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Tue, 25 Jun 2024 15:21:34 +0200 Subject: [PATCH] Handle both json and plain text in CommonBoss (#3981) --- .../viaversion/legacy/bossbar/CommonBoss.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java b/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java index ea4f6abbd..5152d1340 100644 --- a/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java +++ b/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java @@ -19,6 +19,7 @@ package com.viaversion.viaversion.legacy.bossbar; import com.google.common.base.Preconditions; import com.google.common.collect.MapMaker; +import com.google.gson.JsonParser; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.legacy.bossbar.BossBar; @@ -26,7 +27,6 @@ import com.viaversion.viaversion.api.legacy.bossbar.BossColor; import com.viaversion.viaversion.api.legacy.bossbar.BossFlag; import com.viaversion.viaversion.api.legacy.bossbar.BossStyle; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9; import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9; @@ -247,7 +247,11 @@ public class CommonBoss implements BossBar { wrapper.write(Types.VAR_INT, action.getId()); switch (action) { case ADD: - wrapper.write(Types.COMPONENT, ComponentUtil.plainToJson(title)); + try { + wrapper.write(Types.COMPONENT, JsonParser.parseString(this.title)); + } catch (Exception e) { + wrapper.write(Types.COMPONENT, ComponentUtil.plainToJson(this.title)); + } wrapper.write(Types.FLOAT, health); wrapper.write(Types.VAR_INT, color.getId()); wrapper.write(Types.VAR_INT, style.getId()); @@ -259,7 +263,11 @@ public class CommonBoss implements BossBar { wrapper.write(Types.FLOAT, health); break; case UPDATE_TITLE: - wrapper.write(Types.COMPONENT, ComponentUtil.plainToJson(title)); + try { + wrapper.write(Types.COMPONENT, JsonParser.parseString(this.title)); + } catch (Exception e) { + wrapper.write(Types.COMPONENT, ComponentUtil.plainToJson(this.title)); + } break; case UPDATE_STYLE: wrapper.write(Types.VAR_INT, color.getId());