Minecraft 23w43b support
This commit is contained in:
@@ -2,6 +2,7 @@ package net.md_5.bungee.protocol;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonElement;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
@@ -15,6 +16,8 @@ import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import se.llbit.nbt.ErrorTag;
|
||||
import se.llbit.nbt.NamedTag;
|
||||
import se.llbit.nbt.SpecificTag;
|
||||
@@ -70,6 +73,38 @@ public abstract class DefinedPacket
|
||||
return s;
|
||||
}
|
||||
|
||||
public static BaseComponent readBaseComponent(ByteBuf buf, int protocolVersion)
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 )
|
||||
{
|
||||
SpecificTag nbt = (SpecificTag) readTag( buf, protocolVersion );
|
||||
JsonElement json = TagUtil.toJson( nbt );
|
||||
|
||||
return ComponentSerializer.deserialize( json );
|
||||
} else
|
||||
{
|
||||
String string = readString( buf );
|
||||
|
||||
return ComponentSerializer.deserialize( string );
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeBaseComponent(BaseComponent message, ByteBuf buf, int protocolVersion)
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 )
|
||||
{
|
||||
JsonElement json = ComponentSerializer.toJson( message );
|
||||
SpecificTag nbt = TagUtil.fromJson( json );
|
||||
|
||||
writeTag( nbt, buf, protocolVersion );
|
||||
} else
|
||||
{
|
||||
String string = ComponentSerializer.toString( message );
|
||||
|
||||
writeString( string, buf );
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeArray(byte[] b, ByteBuf buf)
|
||||
{
|
||||
if ( b.length > Short.MAX_VALUE )
|
||||
@@ -395,6 +430,11 @@ public abstract class DefinedPacket
|
||||
throw new UnsupportedOperationException( "Packet must implement read method" );
|
||||
}
|
||||
|
||||
public void read(ByteBuf buf, Protocol protocol, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
read( buf, direction, protocolVersion );
|
||||
}
|
||||
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
read( buf );
|
||||
@@ -405,6 +445,11 @@ public abstract class DefinedPacket
|
||||
throw new UnsupportedOperationException( "Packet must implement write method" );
|
||||
}
|
||||
|
||||
public void write(ByteBuf buf, Protocol protocol, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
write( buf, direction, protocolVersion );
|
||||
}
|
||||
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
write( buf );
|
||||
|
@@ -39,7 +39,7 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
||||
DefinedPacket packet = prot.createPacket( packetId, protocolVersion );
|
||||
if ( packet != null )
|
||||
{
|
||||
packet.read( in, prot.getDirection(), protocolVersion );
|
||||
packet.read( in, protocol, prot.getDirection(), protocolVersion );
|
||||
|
||||
if ( in.isReadable() )
|
||||
{
|
||||
|
@@ -24,6 +24,6 @@ public class MinecraftEncoder extends MessageToByteEncoder<DefinedPacket>
|
||||
{
|
||||
Protocol.DirectionData prot = ( server ) ? protocol.TO_CLIENT : protocol.TO_SERVER;
|
||||
DefinedPacket.writeVarInt( prot.getId( msg.getClass(), protocolVersion ), out );
|
||||
msg.write( out, prot.getDirection(), protocolVersion );
|
||||
msg.write( out, protocol, prot.getDirection(), protocolVersion );
|
||||
}
|
||||
}
|
||||
|
@@ -451,7 +451,8 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_1, 0x12 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_3, 0x11 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x12 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x14 )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x14 ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x15 )
|
||||
);
|
||||
TO_SERVER.registerPacket( Chat.class,
|
||||
Chat::new,
|
||||
@@ -517,7 +518,8 @@ public enum Protocol
|
||||
map( ProtocolConstants.MINECRAFT_1_19_1, 0x0D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_3, 0x0C ),
|
||||
map( ProtocolConstants.MINECRAFT_1_19_4, 0x0D ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x0F )
|
||||
map( ProtocolConstants.MINECRAFT_1_20_2, 0x0F ),
|
||||
map( ProtocolConstants.MINECRAFT_1_20_3, 0x10 )
|
||||
);
|
||||
TO_SERVER.registerPacket(
|
||||
StartConfiguration.class,
|
||||
|
@@ -44,6 +44,7 @@ public class ProtocolConstants
|
||||
public static final int MINECRAFT_1_19_4 = 762;
|
||||
public static final int MINECRAFT_1_20 = 763;
|
||||
public static final int MINECRAFT_1_20_2 = 764;
|
||||
public static final int MINECRAFT_1_20_3 = 1073741984;
|
||||
public static final List<String> SUPPORTED_VERSIONS;
|
||||
public static final List<Integer> SUPPORTED_VERSION_IDS;
|
||||
|
||||
@@ -107,7 +108,7 @@ public class ProtocolConstants
|
||||
if ( SNAPSHOT_SUPPORT )
|
||||
{
|
||||
// supportedVersions.add( "1.20.x" );
|
||||
// supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_20_2 );
|
||||
supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_20_3 );
|
||||
}
|
||||
|
||||
SUPPORTED_VERSIONS = supportedVersions.build();
|
||||
|
218
protocol/src/main/java/net/md_5/bungee/protocol/TagUtil.java
Normal file
218
protocol/src/main/java/net/md_5/bungee/protocol/TagUtil.java
Normal file
@@ -0,0 +1,218 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import se.llbit.nbt.ByteArrayTag;
|
||||
import se.llbit.nbt.ByteTag;
|
||||
import se.llbit.nbt.CompoundTag;
|
||||
import se.llbit.nbt.DoubleTag;
|
||||
import se.llbit.nbt.FloatTag;
|
||||
import se.llbit.nbt.IntArrayTag;
|
||||
import se.llbit.nbt.IntTag;
|
||||
import se.llbit.nbt.ListTag;
|
||||
import se.llbit.nbt.LongArrayTag;
|
||||
import se.llbit.nbt.LongTag;
|
||||
import se.llbit.nbt.NamedTag;
|
||||
import se.llbit.nbt.ShortTag;
|
||||
import se.llbit.nbt.SpecificTag;
|
||||
import se.llbit.nbt.StringTag;
|
||||
import se.llbit.nbt.Tag;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class TagUtil
|
||||
{
|
||||
|
||||
public static SpecificTag fromJson(JsonElement json)
|
||||
{
|
||||
if ( json instanceof JsonPrimitive )
|
||||
{
|
||||
JsonPrimitive jsonPrimitive = (JsonPrimitive) json;
|
||||
if ( jsonPrimitive.isNumber() )
|
||||
{
|
||||
Number number = json.getAsNumber();
|
||||
|
||||
if ( number instanceof Byte )
|
||||
{
|
||||
return new ByteTag( (Byte) number );
|
||||
} else if ( number instanceof Short )
|
||||
{
|
||||
return new ShortTag( (Short) number );
|
||||
} else if ( number instanceof Integer )
|
||||
{
|
||||
return new IntTag( (Integer) number );
|
||||
} else if ( number instanceof Long )
|
||||
{
|
||||
return new LongTag( (Long) number );
|
||||
} else if ( number instanceof Float )
|
||||
{
|
||||
return new FloatTag( (Float) number );
|
||||
} else if ( number instanceof Double )
|
||||
{
|
||||
return new DoubleTag( (Double) number );
|
||||
}
|
||||
} else if ( jsonPrimitive.isString() )
|
||||
{
|
||||
return new StringTag( jsonPrimitive.getAsString() );
|
||||
} else if ( jsonPrimitive.isBoolean() )
|
||||
{
|
||||
return new ByteTag( jsonPrimitive.getAsBoolean() ? 1 : 0 );
|
||||
} else
|
||||
{
|
||||
throw new IllegalArgumentException( "Unknown JSON primitive: " + jsonPrimitive );
|
||||
}
|
||||
} else if ( json instanceof JsonObject )
|
||||
{
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
for ( Map.Entry<String, JsonElement> property : ( (JsonObject) json ).entrySet() )
|
||||
{
|
||||
compoundTag.add( property.getKey(), fromJson( property.getValue() ) );
|
||||
}
|
||||
|
||||
return compoundTag;
|
||||
} else if ( json instanceof JsonArray )
|
||||
{
|
||||
List<JsonElement> jsonArray = ( (JsonArray) json ).asList();
|
||||
|
||||
if ( jsonArray.isEmpty() )
|
||||
{
|
||||
return new ListTag( Tag.TAG_END, Collections.emptyList() );
|
||||
}
|
||||
|
||||
SpecificTag listTag;
|
||||
int listType = fromJson( jsonArray.get( 0 ) ).tagType();
|
||||
switch ( listType )
|
||||
{
|
||||
case Tag.TAG_BYTE:
|
||||
byte[] bytes = new byte[ jsonArray.size() ];
|
||||
for ( int i = 0; i < bytes.length; i++ )
|
||||
{
|
||||
bytes[i] = (Byte) ( (JsonPrimitive) jsonArray.get( i ) ).getAsNumber();
|
||||
}
|
||||
|
||||
listTag = new ByteArrayTag( bytes );
|
||||
break;
|
||||
case Tag.TAG_INT:
|
||||
int[] ints = new int[ jsonArray.size() ];
|
||||
for ( int i = 0; i < ints.length; i++ )
|
||||
{
|
||||
ints[i] = (Integer) ( (JsonPrimitive) jsonArray.get( i ) ).getAsNumber();
|
||||
}
|
||||
|
||||
listTag = new IntArrayTag( ints );
|
||||
break;
|
||||
case Tag.TAG_LONG:
|
||||
long[] longs = new long[ jsonArray.size() ];
|
||||
for ( int i = 0; i < longs.length; i++ )
|
||||
{
|
||||
longs[i] = (Long) ( (JsonPrimitive) jsonArray.get( i ) ).getAsNumber();
|
||||
}
|
||||
|
||||
listTag = new LongArrayTag( longs );
|
||||
break;
|
||||
default:
|
||||
List<SpecificTag> tagItems = new ArrayList<>( jsonArray.size() );
|
||||
|
||||
for ( JsonElement jsonEl : jsonArray )
|
||||
{
|
||||
SpecificTag subTag = fromJson( jsonEl );
|
||||
if ( subTag.tagType() != listType )
|
||||
{
|
||||
throw new IllegalArgumentException( "Cannot convert mixed JsonArray to Tag" );
|
||||
}
|
||||
|
||||
tagItems.add( subTag );
|
||||
}
|
||||
|
||||
listTag = new ListTag( listType, tagItems );
|
||||
break;
|
||||
}
|
||||
|
||||
return listTag;
|
||||
} else if ( json instanceof JsonNull )
|
||||
{
|
||||
return Tag.END;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException( "Unknown JSON element: " + json );
|
||||
}
|
||||
|
||||
public static JsonElement toJson(SpecificTag tag)
|
||||
{
|
||||
switch ( tag.tagType() )
|
||||
{
|
||||
case Tag.TAG_BYTE:
|
||||
return new JsonPrimitive( (byte) ( (ByteTag) tag ).getData() );
|
||||
case Tag.TAG_SHORT:
|
||||
return new JsonPrimitive( ( (ShortTag) tag ).getData() );
|
||||
case Tag.TAG_INT:
|
||||
return new JsonPrimitive( ( (IntTag) tag ).getData() );
|
||||
case Tag.TAG_LONG:
|
||||
return new JsonPrimitive( ( (LongTag) tag ).getData() );
|
||||
case Tag.TAG_FLOAT:
|
||||
return new JsonPrimitive( ( (FloatTag) tag ).getData() );
|
||||
case Tag.TAG_DOUBLE:
|
||||
return new JsonPrimitive( ( (DoubleTag) tag ).getData() );
|
||||
case Tag.TAG_BYTE_ARRAY:
|
||||
byte[] byteArray = ( (ByteArrayTag) tag ).getData();
|
||||
|
||||
JsonArray jsonByteArray = new JsonArray( byteArray.length );
|
||||
for ( byte b : byteArray )
|
||||
{
|
||||
jsonByteArray.add( new JsonPrimitive( b ) );
|
||||
}
|
||||
|
||||
return jsonByteArray;
|
||||
case Tag.TAG_STRING:
|
||||
return new JsonPrimitive( ( (StringTag) tag ).getData() );
|
||||
case Tag.TAG_LIST:
|
||||
List<SpecificTag> items = ( (ListTag) tag ).items;
|
||||
|
||||
JsonArray jsonList = new JsonArray( items.size() );
|
||||
for ( SpecificTag subTag : items )
|
||||
{
|
||||
jsonList.add( toJson( subTag ) );
|
||||
}
|
||||
|
||||
return jsonList;
|
||||
case Tag.TAG_COMPOUND:
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
for ( NamedTag subTag : (CompoundTag) tag )
|
||||
{
|
||||
jsonObject.add( subTag.name(), toJson( subTag.getTag() ) );
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
case Tag.TAG_INT_ARRAY:
|
||||
int[] intArray = ( (IntArrayTag) tag ).getData();
|
||||
|
||||
JsonArray jsonIntArray = new JsonArray( intArray.length );
|
||||
for ( int i : intArray )
|
||||
{
|
||||
jsonIntArray.add( new JsonPrimitive( i ) );
|
||||
}
|
||||
|
||||
return jsonIntArray;
|
||||
case Tag.TAG_LONG_ARRAY:
|
||||
long[] longArray = ( (LongArrayTag) tag ).getData();
|
||||
|
||||
JsonArray jsonLongArray = new JsonArray( longArray.length );
|
||||
for ( long l : longArray )
|
||||
{
|
||||
jsonLongArray.add( new JsonPrimitive( l ) );
|
||||
}
|
||||
|
||||
return jsonLongArray;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown NBT tag: " + tag );
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ import java.util.UUID;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -17,7 +18,7 @@ public class BossBar extends DefinedPacket
|
||||
|
||||
private UUID uuid;
|
||||
private int action;
|
||||
private String title;
|
||||
private BaseComponent title;
|
||||
private float health;
|
||||
private int color;
|
||||
private int division;
|
||||
@@ -39,7 +40,7 @@ public class BossBar extends DefinedPacket
|
||||
{
|
||||
// Add
|
||||
case 0:
|
||||
title = readString( buf );
|
||||
title = readBaseComponent( buf, protocolVersion );
|
||||
health = buf.readFloat();
|
||||
color = readVarInt( buf );
|
||||
division = readVarInt( buf );
|
||||
@@ -51,7 +52,7 @@ public class BossBar extends DefinedPacket
|
||||
break;
|
||||
// Title
|
||||
case 3:
|
||||
title = readString( buf );
|
||||
title = readBaseComponent( buf, protocolVersion );
|
||||
break;
|
||||
// Style
|
||||
case 4:
|
||||
@@ -75,7 +76,7 @@ public class BossBar extends DefinedPacket
|
||||
{
|
||||
// Add
|
||||
case 0:
|
||||
writeString( title, buf );
|
||||
writeBaseComponent( title, buf, protocolVersion );
|
||||
buf.writeFloat( health );
|
||||
writeVarInt( color, buf );
|
||||
writeVarInt( division, buf );
|
||||
@@ -87,7 +88,7 @@ public class BossBar extends DefinedPacket
|
||||
break;
|
||||
// Title
|
||||
case 3:
|
||||
writeString( title, buf );
|
||||
writeBaseComponent( title, buf, protocolVersion );
|
||||
break;
|
||||
// Style
|
||||
case 4:
|
||||
|
@@ -5,8 +5,12 @@ import lombok.AllArgsConstructor;
|
||||
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.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -15,18 +19,30 @@ import net.md_5.bungee.protocol.DefinedPacket;
|
||||
public class Kick extends DefinedPacket
|
||||
{
|
||||
|
||||
private String message;
|
||||
private BaseComponent message;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
public void read(ByteBuf buf, Protocol protocol, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
message = readString( buf );
|
||||
if ( protocol == Protocol.LOGIN )
|
||||
{
|
||||
message = ComponentSerializer.deserialize( readString( buf ) );
|
||||
} else
|
||||
{
|
||||
message = readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
public void write(ByteBuf buf, Protocol protocol, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( message, buf );
|
||||
if ( protocol == Protocol.LOGIN )
|
||||
{
|
||||
writeString( ComponentSerializer.toString( message ), buf );
|
||||
} else
|
||||
{
|
||||
writeBaseComponent( message, buf, protocolVersion );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -16,21 +17,21 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
public class PlayerListHeaderFooter extends DefinedPacket
|
||||
{
|
||||
|
||||
private String header;
|
||||
private String footer;
|
||||
private BaseComponent header;
|
||||
private BaseComponent footer;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
header = readString( buf );
|
||||
footer = readString( buf );
|
||||
header = readBaseComponent( buf, protocolVersion );
|
||||
footer = readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( header, buf );
|
||||
writeString( footer, buf );
|
||||
writeBaseComponent( header, buf, protocolVersion );
|
||||
writeBaseComponent( footer, buf, protocolVersion );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -5,6 +5,7 @@ import java.util.UUID;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.PlayerPublicKey;
|
||||
@@ -38,7 +39,7 @@ public class PlayerListItem extends DefinedPacket
|
||||
item.ping = DefinedPacket.readVarInt( buf );
|
||||
if ( buf.readBoolean() )
|
||||
{
|
||||
item.displayName = DefinedPacket.readString( buf );
|
||||
item.displayName = DefinedPacket.readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19 )
|
||||
{
|
||||
@@ -54,7 +55,7 @@ public class PlayerListItem extends DefinedPacket
|
||||
case UPDATE_DISPLAY_NAME:
|
||||
if ( buf.readBoolean() )
|
||||
{
|
||||
item.displayName = DefinedPacket.readString( buf );
|
||||
item.displayName = DefinedPacket.readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +79,7 @@ public class PlayerListItem extends DefinedPacket
|
||||
buf.writeBoolean( item.displayName != null );
|
||||
if ( item.displayName != null )
|
||||
{
|
||||
DefinedPacket.writeString( item.displayName, buf );
|
||||
DefinedPacket.writeBaseComponent( item.displayName, buf, protocolVersion );
|
||||
}
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19 )
|
||||
{
|
||||
@@ -95,7 +96,7 @@ public class PlayerListItem extends DefinedPacket
|
||||
buf.writeBoolean( item.displayName != null );
|
||||
if ( item.displayName != null )
|
||||
{
|
||||
DefinedPacket.writeString( item.displayName, buf );
|
||||
DefinedPacket.writeBaseComponent( item.displayName, buf, protocolVersion );
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -142,7 +143,7 @@ public class PlayerListItem extends DefinedPacket
|
||||
Integer ping;
|
||||
|
||||
// ADD_PLAYER & UPDATE_DISPLAY_NAME
|
||||
String displayName;
|
||||
BaseComponent displayName;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ public class PlayerListItemUpdate extends DefinedPacket
|
||||
case UPDATE_DISPLAY_NAME:
|
||||
if ( buf.readBoolean() )
|
||||
{
|
||||
item.displayName = DefinedPacket.readString( buf );
|
||||
item.displayName = DefinedPacket.readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class PlayerListItemUpdate extends DefinedPacket
|
||||
buf.writeBoolean( item.displayName != null );
|
||||
if ( item.displayName != null )
|
||||
{
|
||||
DefinedPacket.writeString( item.displayName, buf );
|
||||
DefinedPacket.writeBaseComponent( item.displayName, buf, protocolVersion );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -18,7 +19,7 @@ public class ScoreboardObjective extends DefinedPacket
|
||||
{
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
private BaseComponent value;
|
||||
private HealthDisplay type;
|
||||
/**
|
||||
* 0 to create, 1 to remove, 2 to update display text.
|
||||
@@ -32,7 +33,7 @@ public class ScoreboardObjective extends DefinedPacket
|
||||
action = buf.readByte();
|
||||
if ( action == 0 || action == 2 )
|
||||
{
|
||||
value = readString( buf );
|
||||
value = readBaseComponent( buf, protocolVersion );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
type = HealthDisplay.values()[readVarInt( buf )];
|
||||
@@ -50,7 +51,7 @@ public class ScoreboardObjective extends DefinedPacket
|
||||
buf.writeByte( action );
|
||||
if ( action == 0 || action == 2 )
|
||||
{
|
||||
writeString( value, buf );
|
||||
writeBaseComponent( value, buf, protocolVersion );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
writeVarInt( type.ordinal(), buf );
|
||||
|
@@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -16,7 +17,7 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
public class ServerData extends DefinedPacket
|
||||
{
|
||||
|
||||
private String motd;
|
||||
private BaseComponent motd;
|
||||
private Object icon;
|
||||
private boolean preview;
|
||||
private boolean enforceSecure;
|
||||
@@ -26,7 +27,7 @@ public class ServerData extends DefinedPacket
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_4 || buf.readBoolean() )
|
||||
{
|
||||
motd = readString( buf, 262144 );
|
||||
motd = readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
if ( buf.readBoolean() )
|
||||
{
|
||||
@@ -59,7 +60,7 @@ public class ServerData extends DefinedPacket
|
||||
{
|
||||
buf.writeBoolean( true );
|
||||
}
|
||||
writeString( motd, buf, 262144 );
|
||||
writeBaseComponent( motd, buf, protocolVersion );
|
||||
} else
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_4 )
|
||||
|
@@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -14,18 +15,18 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
public class Subtitle extends DefinedPacket
|
||||
{
|
||||
|
||||
private String text;
|
||||
private BaseComponent text;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
text = readString( buf );
|
||||
text = readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( text, buf );
|
||||
writeBaseComponent( text, buf, protocolVersion );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -6,6 +6,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -17,20 +18,20 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
public class SystemChat extends DefinedPacket
|
||||
{
|
||||
|
||||
private String message;
|
||||
private BaseComponent message;
|
||||
private int position;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
message = readString( buf, 262144 );
|
||||
message = readBaseComponent( buf, protocolVersion );
|
||||
position = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 ) ? ( ( buf.readBoolean() ) ? ChatMessageType.ACTION_BAR.ordinal() : 0 ) : readVarInt( buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( message, buf, 262144 );
|
||||
writeBaseComponent( message, buf, protocolVersion );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 )
|
||||
{
|
||||
buf.writeBoolean( position == ChatMessageType.ACTION_BAR.ordinal() );
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import com.mojang.brigadier.LiteralMessage;
|
||||
import com.mojang.brigadier.Message;
|
||||
import com.mojang.brigadier.context.StringRange;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
@@ -10,6 +10,7 @@ import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -51,9 +52,9 @@ public class TabCompleteResponse extends DefinedPacket
|
||||
for ( int i = 0; i < cnt; i++ )
|
||||
{
|
||||
String match = readString( buf );
|
||||
String tooltip = buf.readBoolean() ? readString( buf ) : null;
|
||||
BaseComponent tooltip = buf.readBoolean() ? readBaseComponent( buf, protocolVersion ) : null;
|
||||
|
||||
matches.add( new Suggestion( range, match, new LiteralMessage( tooltip ) ) );
|
||||
matches.add( new Suggestion( range, match, ( tooltip != null ) ? new ComponentMessage( tooltip ) : null ) );
|
||||
}
|
||||
|
||||
suggestions = new Suggestions( range, matches );
|
||||
@@ -76,10 +77,10 @@ public class TabCompleteResponse extends DefinedPacket
|
||||
for ( Suggestion suggestion : suggestions.getList() )
|
||||
{
|
||||
writeString( suggestion.getText(), buf );
|
||||
buf.writeBoolean( suggestion.getTooltip() != null && suggestion.getTooltip().getString() != null );
|
||||
if ( suggestion.getTooltip() != null && suggestion.getTooltip().getString() != null )
|
||||
buf.writeBoolean( suggestion.getTooltip() != null );
|
||||
if ( suggestion.getTooltip() != null )
|
||||
{
|
||||
writeString( suggestion.getTooltip().getString(), buf );
|
||||
writeBaseComponent( ( (ComponentMessage) suggestion.getTooltip() ).getComponent(), buf, protocolVersion );
|
||||
}
|
||||
}
|
||||
} else
|
||||
@@ -93,4 +94,17 @@ public class TabCompleteResponse extends DefinedPacket
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ComponentMessage implements Message
|
||||
{
|
||||
|
||||
private final BaseComponent component;
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
return component.toPlainText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -21,9 +22,9 @@ public class Team extends DefinedPacket
|
||||
* 0 - create, 1 remove, 2 info update, 3 player add, 4 player remove.
|
||||
*/
|
||||
private byte mode;
|
||||
private String displayName;
|
||||
private String prefix;
|
||||
private String suffix;
|
||||
private BaseComponent displayName;
|
||||
private BaseComponent prefix;
|
||||
private BaseComponent suffix;
|
||||
private String nameTagVisibility;
|
||||
private String collisionRule;
|
||||
private int color;
|
||||
@@ -48,11 +49,11 @@ public class Team extends DefinedPacket
|
||||
mode = buf.readByte();
|
||||
if ( mode == 0 || mode == 2 )
|
||||
{
|
||||
displayName = readString( buf );
|
||||
displayName = readBaseComponent( buf, protocolVersion );
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
prefix = readString( buf );
|
||||
suffix = readString( buf );
|
||||
prefix = readBaseComponent( buf, protocolVersion );
|
||||
suffix = readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
friendlyFire = buf.readByte();
|
||||
nameTagVisibility = readString( buf );
|
||||
@@ -63,8 +64,8 @@ public class Team extends DefinedPacket
|
||||
color = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? readVarInt( buf ) : buf.readByte();
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
prefix = readString( buf );
|
||||
suffix = readString( buf );
|
||||
prefix = readBaseComponent( buf, protocolVersion );
|
||||
suffix = readBaseComponent( buf, protocolVersion );
|
||||
}
|
||||
}
|
||||
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||
@@ -85,11 +86,11 @@ public class Team extends DefinedPacket
|
||||
buf.writeByte( mode );
|
||||
if ( mode == 0 || mode == 2 )
|
||||
{
|
||||
writeString( displayName, buf );
|
||||
writeBaseComponent( displayName, buf, protocolVersion );
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
writeString( prefix, buf );
|
||||
writeString( suffix, buf );
|
||||
writeBaseComponent( prefix, buf, protocolVersion );
|
||||
writeBaseComponent( suffix, buf, protocolVersion );
|
||||
}
|
||||
buf.writeByte( friendlyFire );
|
||||
writeString( nameTagVisibility, buf );
|
||||
@@ -101,8 +102,8 @@ public class Team extends DefinedPacket
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
writeVarInt( color, buf );
|
||||
writeString( prefix, buf );
|
||||
writeString( suffix, buf );
|
||||
writeBaseComponent( prefix, buf, protocolVersion );
|
||||
writeBaseComponent( suffix, buf, protocolVersion );
|
||||
} else
|
||||
{
|
||||
buf.writeByte( color );
|
||||
|
@@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -17,7 +18,7 @@ public class Title extends DefinedPacket
|
||||
private Action action;
|
||||
|
||||
// TITLE & SUBTITLE
|
||||
private String text;
|
||||
private BaseComponent text;
|
||||
|
||||
// TIMES
|
||||
private int fadeIn;
|
||||
@@ -34,7 +35,7 @@ public class Title extends DefinedPacket
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_17 )
|
||||
{
|
||||
text = readString( buf );
|
||||
text = readBaseComponent( buf, protocolVersion );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@ public class Title extends DefinedPacket
|
||||
case TITLE:
|
||||
case SUBTITLE:
|
||||
case ACTIONBAR:
|
||||
text = readString( buf );
|
||||
text = readBaseComponent( buf, protocolVersion );
|
||||
break;
|
||||
case TIMES:
|
||||
fadeIn = buf.readInt();
|
||||
@@ -67,7 +68,7 @@ public class Title extends DefinedPacket
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_17 )
|
||||
{
|
||||
writeString( text, buf );
|
||||
writeBaseComponent( text, buf, protocolVersion );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ public class Title extends DefinedPacket
|
||||
case TITLE:
|
||||
case SUBTITLE:
|
||||
case ACTIONBAR:
|
||||
writeString( text, buf );
|
||||
writeBaseComponent( text, buf, protocolVersion );
|
||||
break;
|
||||
case TIMES:
|
||||
buf.writeInt( fadeIn );
|
||||
|
Reference in New Issue
Block a user