@@ -0,0 +1,19 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import net.md_5.bungee.chat.ChatVersion;
|
||||
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
||||
|
||||
public class ChatSerializer
|
||||
{
|
||||
|
||||
public static VersionedComponentSerializer forVersion(int protocolVersion)
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
|
||||
{
|
||||
return VersionedComponentSerializer.forVersion( ChatVersion.V1_21_5 );
|
||||
} else
|
||||
{
|
||||
return VersionedComponentSerializer.forVersion( ChatVersion.V1_16 );
|
||||
}
|
||||
}
|
||||
}
|
@@ -21,7 +21,6 @@ import java.util.function.BiConsumer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import se.llbit.nbt.ErrorTag;
|
||||
import se.llbit.nbt.NamedTag;
|
||||
import se.llbit.nbt.SpecificTag;
|
||||
@@ -120,12 +119,12 @@ public abstract class DefinedPacket
|
||||
SpecificTag nbt = (SpecificTag) readTag( buf, protocolVersion );
|
||||
JsonElement json = TagUtil.toJson( nbt );
|
||||
|
||||
return ComponentSerializer.deserialize( json );
|
||||
return ChatSerializer.forVersion( protocolVersion ).deserialize( json );
|
||||
} else
|
||||
{
|
||||
String string = readString( buf, maxStringLength );
|
||||
|
||||
return ComponentSerializer.deserialize( string );
|
||||
return ChatSerializer.forVersion( protocolVersion ).deserialize( string );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +133,7 @@ public abstract class DefinedPacket
|
||||
SpecificTag nbt = (SpecificTag) readTag( buf, protocolVersion );
|
||||
JsonElement json = TagUtil.toJson( nbt );
|
||||
|
||||
return ComponentSerializer.deserializeStyle( json );
|
||||
return ChatSerializer.forVersion( protocolVersion ).deserializeStyle( json );
|
||||
}
|
||||
|
||||
public static void writeEitherBaseComponent(Either<String, BaseComponent> message, ByteBuf buf, int protocolVersion)
|
||||
@@ -152,13 +151,13 @@ public abstract class DefinedPacket
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 )
|
||||
{
|
||||
JsonElement json = ComponentSerializer.toJson( message );
|
||||
JsonElement json = ChatSerializer.forVersion( protocolVersion ).toJson( message );
|
||||
SpecificTag nbt = TagUtil.fromJson( json );
|
||||
|
||||
writeTag( nbt, buf, protocolVersion );
|
||||
} else
|
||||
{
|
||||
String string = ComponentSerializer.toString( message );
|
||||
String string = ChatSerializer.forVersion( protocolVersion ).toString( message );
|
||||
|
||||
writeString( string, buf );
|
||||
}
|
||||
@@ -166,7 +165,7 @@ public abstract class DefinedPacket
|
||||
|
||||
public static void writeComponentStyle(ComponentStyle style, ByteBuf buf, int protocolVersion)
|
||||
{
|
||||
JsonElement json = ComponentSerializer.toJson( style );
|
||||
JsonElement json = ChatSerializer.forVersion( protocolVersion ).toJson( style );
|
||||
SpecificTag nbt = TagUtil.fromJson( json );
|
||||
|
||||
writeTag( nbt, buf, protocolVersion );
|
||||
|
@@ -6,8 +6,8 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.ChatSerializer;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -26,7 +26,7 @@ public class Kick extends DefinedPacket
|
||||
{
|
||||
if ( protocol == Protocol.LOGIN )
|
||||
{
|
||||
message = ComponentSerializer.deserialize( readString( buf ) );
|
||||
message = ChatSerializer.forVersion( protocolVersion ).deserialize( readString( buf ) );
|
||||
} else
|
||||
{
|
||||
message = readBaseComponent( buf, protocolVersion );
|
||||
@@ -38,7 +38,7 @@ public class Kick extends DefinedPacket
|
||||
{
|
||||
if ( protocol == Protocol.LOGIN )
|
||||
{
|
||||
writeString( ComponentSerializer.toString( message ), buf );
|
||||
writeString( ChatSerializer.forVersion( protocolVersion ).toString( message ), buf );
|
||||
} else
|
||||
{
|
||||
writeBaseComponent( message, buf, protocolVersion );
|
||||
|
Reference in New Issue
Block a user