Handle both json and plain text in CommonBoss (#3981)

This commit is contained in:
EnZaXD 2024-06-25 15:21:34 +02:00 committed by GitHub
parent 5a0ca55b97
commit 8606e5d663
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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());