mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-01 21:11:33 +01:00
Add dedicated method to ignore string/component size
This commit is contained in:
parent
9fed96abe2
commit
0200788b22
@ -108,7 +108,7 @@ public abstract class SerializableData extends Data {
|
|||||||
{
|
{
|
||||||
final int dataIndexSize = binaryReader.readVarInt();
|
final int dataIndexSize = binaryReader.readVarInt();
|
||||||
for (int i = 0; i < dataIndexSize; i++) {
|
for (int i = 0; i < dataIndexSize; i++) {
|
||||||
final String className = binaryReader.readSizedString(Integer.MAX_VALUE);
|
final String className = binaryReader.readSizedString();
|
||||||
final short classIndex = binaryReader.readShort();
|
final short classIndex = binaryReader.readShort();
|
||||||
typeToIndexMap.put(className, classIndex);
|
typeToIndexMap.put(className, classIndex);
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ public class SerializableDataImpl extends SerializableData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the key
|
// Get the key
|
||||||
final String name = reader.readSizedString(Integer.MAX_VALUE);
|
final String name = reader.readSizedString();
|
||||||
|
|
||||||
// Get the data
|
// Get the data
|
||||||
final Object value;
|
final Object value;
|
||||||
|
@ -28,8 +28,8 @@ public class InventoryData extends DataType<Inventory> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Inventory decode(@NotNull BinaryReader reader) {
|
public Inventory decode(@NotNull BinaryReader reader) {
|
||||||
final Component title = reader.readComponent(Integer.MAX_VALUE);
|
final Component title = reader.readComponent();
|
||||||
final InventoryType inventoryType = InventoryType.valueOf(reader.readSizedString(Integer.MAX_VALUE));
|
final InventoryType inventoryType = InventoryType.valueOf(reader.readSizedString());
|
||||||
final int size = inventoryType.getSize();
|
final int size = inventoryType.getSize();
|
||||||
|
|
||||||
Inventory inventory = new Inventory(inventoryType, title);
|
Inventory inventory = new Inventory(inventoryType, title);
|
||||||
|
@ -15,6 +15,6 @@ public class StringData extends DataType<String> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String decode(@NotNull BinaryReader reader) {
|
public String decode(@NotNull BinaryReader reader) {
|
||||||
return reader.readSizedString(Integer.MAX_VALUE);
|
return reader.readSizedString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Value<String> String(@NotNull String value) {
|
public static Value<String> String(@NotNull String value) {
|
||||||
return new Value<>(TYPE_STRING, value, writer -> writer.writeSizedString(value), reader -> reader.readSizedString(Integer.MAX_VALUE));
|
return new Value<>(TYPE_STRING, value, writer -> writer.writeSizedString(value), BinaryReader::readSizedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -71,7 +71,7 @@ public class Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Value<Component> Chat(@NotNull Component value) {
|
public static Value<Component> Chat(@NotNull Component value) {
|
||||||
return new Value<>(TYPE_CHAT, value, writer -> writer.writeSizedString(AdventureSerializer.serialize(value)), reader -> reader.readComponent(Integer.MAX_VALUE));
|
return new Value<>(TYPE_CHAT, value, writer -> writer.writeComponent(value), BinaryReader::readComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Value<Component> OptChat(@Nullable Component value) {
|
public static Value<Component> OptChat(@Nullable Component value) {
|
||||||
@ -84,7 +84,7 @@ public class Metadata {
|
|||||||
}, reader -> {
|
}, reader -> {
|
||||||
boolean present = reader.readBoolean();
|
boolean present = reader.readBoolean();
|
||||||
if (present) {
|
if (present) {
|
||||||
return reader.readComponent(Integer.MAX_VALUE);
|
return reader.readComponent();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
@ -73,7 +73,7 @@ public final class VelocityProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static InetAddress readAddress(@NotNull BinaryReader reader) {
|
public static InetAddress readAddress(@NotNull BinaryReader reader) {
|
||||||
return InetAddresses.forString(reader.readSizedString(Integer.MAX_VALUE));
|
return InetAddresses.forString(reader.readSizedString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerSkin readSkin(@NotNull BinaryReader reader) {
|
public static PlayerSkin readSkin(@NotNull BinaryReader reader) {
|
||||||
|
@ -16,7 +16,7 @@ public class ResponsePacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
jsonResponse = reader.readSizedString(Integer.MAX_VALUE);
|
jsonResponse = reader.readSizedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,7 +39,7 @@ public class EncryptionRequestPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
reader.readSizedString(Integer.MAX_VALUE); // server id, apparently empty
|
reader.readSizedString(); // server id, apparently empty
|
||||||
|
|
||||||
publicKey = ByteArrayData.decodeByteArray(reader);
|
publicKey = ByteArrayData.decodeByteArray(reader);
|
||||||
nonce = ByteArrayData.decodeByteArray(reader);
|
nonce = ByteArrayData.decodeByteArray(reader);
|
||||||
|
@ -38,7 +38,7 @@ public class LoginDisconnectPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
kickMessage = reader.readComponent(Integer.MAX_VALUE);
|
kickMessage = reader.readComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,7 +24,7 @@ public class LoginPluginRequestPacket implements ServerPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
messageId = reader.readVarInt();
|
messageId = reader.readVarInt();
|
||||||
channel = reader.readSizedString(Integer.MAX_VALUE);
|
channel = reader.readSizedString();
|
||||||
data = reader.readRemainingBytes();
|
data = reader.readRemainingBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class LoginSuccessPacket implements ServerPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
uuid = reader.readUuid();
|
uuid = reader.readUuid();
|
||||||
username = reader.readSizedString(Integer.MAX_VALUE);
|
username = reader.readSizedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,7 +112,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
key = reader.readSizedString(Integer.MAX_VALUE);
|
key = reader.readSizedString();
|
||||||
value = new Advancement();
|
value = new Advancement();
|
||||||
value.read(reader);
|
value.read(reader);
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
|||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
boolean hasParent = reader.readBoolean();
|
boolean hasParent = reader.readBoolean();
|
||||||
if (hasParent) {
|
if (hasParent) {
|
||||||
parentIdentifier = reader.readSizedString(Integer.MAX_VALUE);
|
parentIdentifier = reader.readSizedString();
|
||||||
} else {
|
} else {
|
||||||
parentIdentifier = null;
|
parentIdentifier = null;
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
|||||||
displayData = null;
|
displayData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
criterions = reader.readSizedStringArray(Integer.MAX_VALUE);
|
criterions = reader.readSizedStringArray();
|
||||||
|
|
||||||
int requirementCount = reader.readVarInt();
|
int requirementCount = reader.readVarInt();
|
||||||
requirements = new Requirement[requirementCount];
|
requirements = new Requirement[requirementCount];
|
||||||
@ -201,13 +201,13 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
title = reader.readComponent(Integer.MAX_VALUE);
|
title = reader.readComponent();
|
||||||
description = reader.readComponent(Integer.MAX_VALUE);
|
description = reader.readComponent();
|
||||||
icon = reader.readItemStack();
|
icon = reader.readItemStack();
|
||||||
frameType = FrameType.values()[reader.readVarInt()];
|
frameType = FrameType.values()[reader.readVarInt()];
|
||||||
flags = reader.readInt();
|
flags = reader.readInt();
|
||||||
if ((flags & 0x1) != 0) {
|
if ((flags & 0x1) != 0) {
|
||||||
backgroundTexture = reader.readSizedString(Integer.MAX_VALUE);
|
backgroundTexture = reader.readSizedString();
|
||||||
} else {
|
} else {
|
||||||
backgroundTexture = null;
|
backgroundTexture = null;
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
key = reader.readSizedString(Integer.MAX_VALUE);
|
key = reader.readSizedString();
|
||||||
value = new AdvancementProgress();
|
value = new AdvancementProgress();
|
||||||
value.read(reader);
|
value.read(reader);
|
||||||
}
|
}
|
||||||
@ -283,7 +283,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
criterionIdentifier = reader.readSizedString(Integer.MAX_VALUE);
|
criterionIdentifier = reader.readSizedString();
|
||||||
criterionProgress = new CriterionProgress();
|
criterionProgress = new CriterionProgress();
|
||||||
criterionProgress.read(reader);
|
criterionProgress.read(reader);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,8 @@ public class BossBarPacket implements ComponentHoldingServerPacket {
|
|||||||
public BossBar.Overlay overlay = BossBar.Overlay.PROGRESS;
|
public BossBar.Overlay overlay = BossBar.Overlay.PROGRESS;
|
||||||
public byte flags;
|
public byte flags;
|
||||||
|
|
||||||
public BossBarPacket() {}
|
public BossBarPacket() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
@ -67,7 +68,7 @@ public class BossBarPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ADD:
|
case ADD:
|
||||||
title = reader.readComponent(Integer.MAX_VALUE);
|
title = reader.readComponent();
|
||||||
health = reader.readFloat();
|
health = reader.readFloat();
|
||||||
color = BossBar.Color.values()[reader.readVarInt()];
|
color = BossBar.Color.values()[reader.readVarInt()];
|
||||||
overlay = BossBar.Overlay.values()[reader.readVarInt()];
|
overlay = BossBar.Overlay.values()[reader.readVarInt()];
|
||||||
@ -80,7 +81,7 @@ public class BossBarPacket implements ComponentHoldingServerPacket {
|
|||||||
health = reader.readFloat();
|
health = reader.readFloat();
|
||||||
break;
|
break;
|
||||||
case UPDATE_TITLE:
|
case UPDATE_TITLE:
|
||||||
title = reader.readComponent(Integer.MAX_VALUE);
|
title = reader.readComponent();
|
||||||
break;
|
break;
|
||||||
case UPDATE_STYLE:
|
case UPDATE_STYLE:
|
||||||
color = BossBar.Color.values()[reader.readVarInt()];
|
color = BossBar.Color.values()[reader.readVarInt()];
|
||||||
@ -127,7 +128,8 @@ public class BossBarPacket implements ComponentHoldingServerPacket {
|
|||||||
packet.flags = flags;
|
packet.flags = flags;
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
default: return this;
|
default:
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class ChatMessagePacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
message = reader.readComponent(Integer.MAX_VALUE);
|
message = reader.readComponent();
|
||||||
position = ChatPosition.fromPacketID(reader.readByte());
|
position = ChatPosition.fromPacketID(reader.readByte());
|
||||||
uuid = reader.readUuid();
|
uuid = reader.readUuid();
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public class CraftRecipeResponse implements ServerPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
windowId = reader.readByte();
|
windowId = reader.readByte();
|
||||||
recipe = reader.readSizedString(Integer.MAX_VALUE);
|
recipe = reader.readSizedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,7 @@ public class DeathCombatEventPacket implements ServerPacket {
|
|||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
this.playerId = reader.readVarInt();
|
this.playerId = reader.readVarInt();
|
||||||
this.entityId = reader.readInt();
|
this.entityId = reader.readInt();
|
||||||
this.message = reader.readComponent(Integer.MAX_VALUE);
|
this.message = reader.readComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,16 +83,16 @@ public class DeclareCommandsPacket implements ServerPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isLiteral() || isArgument()) {
|
if (isLiteral() || isArgument()) {
|
||||||
name = reader.readSizedString(Integer.MAX_VALUE);
|
name = reader.readSizedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isArgument()) {
|
if (isArgument()) {
|
||||||
parser = reader.readSizedString(Integer.MAX_VALUE);
|
parser = reader.readSizedString();
|
||||||
properties = getProperties(reader, parser);
|
properties = getProperties(reader, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & 0x10) != 0) {
|
if ((flags & 0x10) != 0) {
|
||||||
suggestionsType = reader.readSizedString(Integer.MAX_VALUE);
|
suggestionsType = reader.readSizedString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ public class DeclareRecipesPacket implements ServerPacket {
|
|||||||
int recipeCount = reader.readVarInt();
|
int recipeCount = reader.readVarInt();
|
||||||
recipes = new DeclaredRecipe[recipeCount];
|
recipes = new DeclaredRecipe[recipeCount];
|
||||||
for (int i = 0; i < recipeCount; i++) {
|
for (int i = 0; i < recipeCount; i++) {
|
||||||
String type = reader.readSizedString(Integer.MAX_VALUE);
|
String type = reader.readSizedString();
|
||||||
String id = reader.readSizedString(Integer.MAX_VALUE);
|
String id = reader.readSizedString();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "crafting_shapeless":
|
case "crafting_shapeless":
|
||||||
@ -136,7 +136,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
group = reader.readSizedString();
|
||||||
int count = reader.readVarInt();
|
int count = reader.readVarInt();
|
||||||
ingredients = new Ingredient[count];
|
ingredients = new Ingredient[count];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
@ -193,7 +193,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
|||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
width = reader.readVarInt();
|
width = reader.readVarInt();
|
||||||
height = reader.readVarInt();
|
height = reader.readVarInt();
|
||||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
group = reader.readSizedString();
|
||||||
ingredients = new Ingredient[width * height];
|
ingredients = new Ingredient[width * height];
|
||||||
for (int i = 0; i < width * height; i++) {
|
for (int i = 0; i < width * height; i++) {
|
||||||
ingredients[i] = new Ingredient();
|
ingredients[i] = new Ingredient();
|
||||||
@ -245,7 +245,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
group = reader.readSizedString();
|
||||||
ingredient = new Ingredient();
|
ingredient = new Ingredient();
|
||||||
ingredient.read(reader);
|
ingredient.read(reader);
|
||||||
result = reader.readItemStack();
|
result = reader.readItemStack();
|
||||||
@ -296,7 +296,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
group = reader.readSizedString();
|
||||||
ingredient = new Ingredient();
|
ingredient = new Ingredient();
|
||||||
ingredient.read(reader);
|
ingredient.read(reader);
|
||||||
result = reader.readItemStack();
|
result = reader.readItemStack();
|
||||||
@ -347,7 +347,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
group = reader.readSizedString();
|
||||||
ingredient = new Ingredient();
|
ingredient = new Ingredient();
|
||||||
ingredient.read(reader);
|
ingredient.read(reader);
|
||||||
result = reader.readItemStack();
|
result = reader.readItemStack();
|
||||||
@ -398,7 +398,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
group = reader.readSizedString();
|
||||||
ingredient = new Ingredient();
|
ingredient = new Ingredient();
|
||||||
ingredient.read(reader);
|
ingredient.read(reader);
|
||||||
result = reader.readItemStack();
|
result = reader.readItemStack();
|
||||||
@ -441,7 +441,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
group = reader.readSizedString();
|
||||||
ingredient = new Ingredient();
|
ingredient = new Ingredient();
|
||||||
ingredient.read(reader);
|
ingredient.read(reader);
|
||||||
result = reader.readItemStack();
|
result = reader.readItemStack();
|
||||||
|
@ -17,6 +17,7 @@ public class DisconnectPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new disconnect packet with a given message.
|
* Creates a new disconnect packet with a given message.
|
||||||
|
*
|
||||||
* @param message the message
|
* @param message the message
|
||||||
*/
|
*/
|
||||||
public DisconnectPacket(@NotNull Component message) {
|
public DisconnectPacket(@NotNull Component message) {
|
||||||
@ -34,7 +35,7 @@ public class DisconnectPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
message = reader.readComponent(Integer.MAX_VALUE);
|
message = reader.readComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,7 +24,7 @@ public class DisplayScoreboardPacket implements ServerPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
position = reader.readByte();
|
position = reader.readByte();
|
||||||
scoreName = reader.readSizedString(Integer.MAX_VALUE);
|
scoreName = reader.readSizedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,7 +76,7 @@ public class EntityPropertiesPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
String key = reader.readSizedString(Integer.MAX_VALUE);
|
String key = reader.readSizedString();
|
||||||
attribute = Attribute.fromKey(key);
|
attribute = Attribute.fromKey(key);
|
||||||
|
|
||||||
value = reader.readDouble();
|
value = reader.readDouble();
|
||||||
|
@ -80,12 +80,12 @@ public class JoinGamePacket implements ServerPacket {
|
|||||||
int worldCount = reader.readVarInt();
|
int worldCount = reader.readVarInt();
|
||||||
Check.stateCondition(worldCount != 1, "Only 1 world is supported per JoinGamePacket by Minestom for the moment.");
|
Check.stateCondition(worldCount != 1, "Only 1 world is supported per JoinGamePacket by Minestom for the moment.");
|
||||||
//for (int i = 0; i < worldCount; i++) {
|
//for (int i = 0; i < worldCount; i++) {
|
||||||
String worldName = reader.readSizedString(Integer.MAX_VALUE);
|
String worldName = reader.readSizedString();
|
||||||
try {
|
try {
|
||||||
NBTCompound dimensionCodec = (NBTCompound) reader.readTag();
|
NBTCompound dimensionCodec = (NBTCompound) reader.readTag();
|
||||||
dimensionType = DimensionType.fromNBT((NBTCompound) reader.readTag());
|
dimensionType = DimensionType.fromNBT((NBTCompound) reader.readTag());
|
||||||
|
|
||||||
String dimensionName = reader.readSizedString(Integer.MAX_VALUE);
|
String dimensionName = reader.readSizedString();
|
||||||
hashedSeed = reader.readLong();
|
hashedSeed = reader.readLong();
|
||||||
maxPlayers = reader.readVarInt();
|
maxPlayers = reader.readVarInt();
|
||||||
viewDistance = reader.readVarInt();
|
viewDistance = reader.readVarInt();
|
||||||
|
@ -161,7 +161,7 @@ public class MapDataPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
boolean hasDisplayName = reader.readBoolean();
|
boolean hasDisplayName = reader.readBoolean();
|
||||||
if (hasDisplayName) {
|
if (hasDisplayName) {
|
||||||
displayName = reader.readComponent(Integer.MAX_VALUE);
|
displayName = reader.readComponent();
|
||||||
} else {
|
} else {
|
||||||
displayName = null;
|
displayName = null;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class NamedSoundEffectPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
soundName = reader.readSizedString(Integer.MAX_VALUE);
|
soundName = reader.readSizedString();
|
||||||
soundSource = Source.values()[reader.readVarInt()];
|
soundSource = Source.values()[reader.readVarInt()];
|
||||||
x = reader.readInt() / 8;
|
x = reader.readInt() / 8;
|
||||||
y = reader.readInt() / 8;
|
y = reader.readInt() / 8;
|
||||||
|
@ -31,7 +31,7 @@ public class OpenWindowPacket implements ServerPacket {
|
|||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
windowId = reader.readVarInt();
|
windowId = reader.readVarInt();
|
||||||
windowType = reader.readVarInt();
|
windowType = reader.readVarInt();
|
||||||
title = reader.readComponent(Integer.MAX_VALUE);
|
title = reader.readComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,7 +92,8 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return components;
|
return components;
|
||||||
default: return Collections.emptyList();
|
default:
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,8 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
|||||||
playerInfos.add(playerInfo);
|
playerInfos.add(playerInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: return this;
|
default:
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +165,7 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
AddPlayer(UUID uuid, BinaryReader reader) {
|
AddPlayer(UUID uuid, BinaryReader reader) {
|
||||||
super(uuid);
|
super(uuid);
|
||||||
name = reader.readSizedString(Integer.MAX_VALUE);
|
name = reader.readSizedString();
|
||||||
int propertyCount = reader.readVarInt();
|
int propertyCount = reader.readVarInt();
|
||||||
|
|
||||||
properties = new ArrayList<>(propertyCount);
|
properties = new ArrayList<>(propertyCount);
|
||||||
@ -176,7 +178,7 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
|||||||
boolean hasDisplayName = reader.readBoolean();
|
boolean hasDisplayName = reader.readBoolean();
|
||||||
|
|
||||||
if (hasDisplayName) {
|
if (hasDisplayName) {
|
||||||
displayName = reader.readComponent(Integer.MAX_VALUE);
|
displayName = reader.readComponent();
|
||||||
} else {
|
} else {
|
||||||
displayName = null;
|
displayName = null;
|
||||||
}
|
}
|
||||||
@ -235,12 +237,12 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Property(BinaryReader reader) {
|
Property(BinaryReader reader) {
|
||||||
name = reader.readSizedString(Integer.MAX_VALUE);
|
name = reader.readSizedString();
|
||||||
value = reader.readSizedString(Integer.MAX_VALUE);
|
value = reader.readSizedString();
|
||||||
boolean hasSignature = reader.readBoolean();
|
boolean hasSignature = reader.readBoolean();
|
||||||
|
|
||||||
if (hasSignature) {
|
if (hasSignature) {
|
||||||
signature = reader.readSizedString(Integer.MAX_VALUE);
|
signature = reader.readSizedString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +311,7 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
|||||||
super(uuid);
|
super(uuid);
|
||||||
boolean hasDisplayName = reader.readBoolean();
|
boolean hasDisplayName = reader.readBoolean();
|
||||||
if (hasDisplayName) {
|
if (hasDisplayName) {
|
||||||
displayName = reader.readComponent(Integer.MAX_VALUE);
|
displayName = reader.readComponent();
|
||||||
} else {
|
} else {
|
||||||
displayName = null;
|
displayName = null;
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ public class PlayerListHeaderAndFooterPacket implements ComponentHoldingServerPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
header = reader.readComponent(Integer.MAX_VALUE);
|
header = reader.readComponent();
|
||||||
footer = reader.readComponent(Integer.MAX_VALUE);
|
footer = reader.readComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,8 +20,8 @@ public class PluginMessagePacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
channel = reader.readSizedString(Integer.MAX_VALUE);
|
channel = reader.readSizedString();
|
||||||
data = reader.getRemainingBytes();
|
data = reader.readRemainingBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,8 +37,8 @@ public class ResourcePackSendPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
this.url = reader.readSizedString(Integer.MAX_VALUE);
|
this.url = reader.readSizedString();
|
||||||
this.hash = reader.readSizedString(Integer.MAX_VALUE);
|
this.hash = reader.readSizedString();
|
||||||
this.forced = reader.readBoolean();
|
this.forced = reader.readBoolean();
|
||||||
if (forced) {
|
if (forced) {
|
||||||
this.forcedMessage = reader.readComponent();
|
this.forcedMessage = reader.readComponent();
|
||||||
|
@ -47,7 +47,7 @@ public class RespawnPacket implements ServerPacket {
|
|||||||
dimensionType = DimensionType.fromNBT((NBTCompound) reader.readTag());
|
dimensionType = DimensionType.fromNBT((NBTCompound) reader.readTag());
|
||||||
|
|
||||||
// dimension type name
|
// dimension type name
|
||||||
reader.readSizedString(Integer.MAX_VALUE);
|
reader.readSizedString();
|
||||||
|
|
||||||
hashedSeed = reader.readLong();
|
hashedSeed = reader.readLong();
|
||||||
gameMode = GameMode.values()[reader.readByte()];
|
gameMode = GameMode.values()[reader.readByte()];
|
||||||
|
@ -52,11 +52,11 @@ public class ScoreboardObjectivePacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
objectiveName = reader.readSizedString(Integer.MAX_VALUE);
|
objectiveName = reader.readSizedString();
|
||||||
mode = reader.readByte();
|
mode = reader.readByte();
|
||||||
|
|
||||||
if (mode == 0 || mode == 2) {
|
if (mode == 0 || mode == 2) {
|
||||||
objectiveValue = reader.readComponent(Integer.MAX_VALUE);
|
objectiveValue = reader.readComponent();
|
||||||
type = Type.values()[reader.readVarInt()];
|
type = Type.values()[reader.readVarInt()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,8 @@ public class SelectAdvancementTabPacket implements ServerPacket {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public String identifier;
|
public String identifier;
|
||||||
|
|
||||||
public SelectAdvancementTabPacket() {}
|
public SelectAdvancementTabPacket() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
@ -28,7 +29,7 @@ public class SelectAdvancementTabPacket implements ServerPacket {
|
|||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
boolean hasID = reader.readBoolean();
|
boolean hasID = reader.readBoolean();
|
||||||
if (hasID) {
|
if (hasID) {
|
||||||
identifier = reader.readSizedString(Integer.MAX_VALUE);
|
identifier = reader.readSizedString();
|
||||||
} else {
|
} else {
|
||||||
identifier = null;
|
identifier = null;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public class StopSoundPacket implements ServerPacket {
|
|||||||
source = reader.readVarInt();
|
source = reader.readVarInt();
|
||||||
}
|
}
|
||||||
if (flags == 2 || flags == 3) {
|
if (flags == 2 || flags == 3) {
|
||||||
sound = reader.readSizedString(Integer.MAX_VALUE);
|
sound = reader.readSizedString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,11 +50,11 @@ public class TabCompletePacket implements ComponentHoldingServerPacket {
|
|||||||
int matchCount = reader.readVarInt();
|
int matchCount = reader.readVarInt();
|
||||||
matches = new Match[matchCount];
|
matches = new Match[matchCount];
|
||||||
for (int i = 0; i < matchCount; i++) {
|
for (int i = 0; i < matchCount; i++) {
|
||||||
String match = reader.readSizedString(Integer.MAX_VALUE);
|
String match = reader.readSizedString();
|
||||||
boolean hasTooltip = reader.readBoolean();
|
boolean hasTooltip = reader.readBoolean();
|
||||||
Component tooltip = null;
|
Component tooltip = null;
|
||||||
if (hasTooltip) {
|
if (hasTooltip) {
|
||||||
tooltip = reader.readComponent(Integer.MAX_VALUE);
|
tooltip = reader.readComponent();
|
||||||
}
|
}
|
||||||
Match newMatch = new Match();
|
Match newMatch = new Match();
|
||||||
newMatch.match = match;
|
newMatch.match = match;
|
||||||
|
@ -147,14 +147,14 @@ public class TagsPacket implements ServerPacket {
|
|||||||
final int typeCount = reader.readVarInt();
|
final int typeCount = reader.readVarInt();
|
||||||
for (int i = 0; i < typeCount; i++) {
|
for (int i = 0; i < typeCount; i++) {
|
||||||
// Read tag type
|
// Read tag type
|
||||||
final Tag.BasicTypes tagType = Tag.BasicTypes.fromIdentifer(reader.readSizedString(Integer.MAX_VALUE));
|
final Tag.BasicTypes tagType = Tag.BasicTypes.fromIdentifer(reader.readSizedString());
|
||||||
if (tagType == null) {
|
if (tagType == null) {
|
||||||
throw new IllegalArgumentException("Tag type could not be resolved");
|
throw new IllegalArgumentException("Tag type could not be resolved");
|
||||||
}
|
}
|
||||||
|
|
||||||
final int tagCount = reader.readVarInt();
|
final int tagCount = reader.readVarInt();
|
||||||
for (int j = 0; j < tagCount; j++) {
|
for (int j = 0; j < tagCount; j++) {
|
||||||
final String tagName = reader.readSizedString(Integer.MAX_VALUE);
|
final String tagName = reader.readSizedString();
|
||||||
final int[] entries = reader.readVarIntArray();
|
final int[] entries = reader.readVarIntArray();
|
||||||
// TODO convert
|
// TODO convert
|
||||||
}
|
}
|
||||||
|
@ -106,19 +106,19 @@ public class TeamsPacket implements ComponentHoldingServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
teamName = reader.readSizedString(Integer.MAX_VALUE);
|
teamName = reader.readSizedString();
|
||||||
action = Action.values()[reader.readByte()];
|
action = Action.values()[reader.readByte()];
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case CREATE_TEAM:
|
case CREATE_TEAM:
|
||||||
case UPDATE_TEAM_INFO:
|
case UPDATE_TEAM_INFO:
|
||||||
this.teamDisplayName = reader.readComponent(Integer.MAX_VALUE);
|
this.teamDisplayName = reader.readComponent();
|
||||||
this.friendlyFlags = reader.readByte();
|
this.friendlyFlags = reader.readByte();
|
||||||
nameTagVisibility = NameTagVisibility.fromIdentifier(reader.readSizedString(Integer.MAX_VALUE));
|
nameTagVisibility = NameTagVisibility.fromIdentifier(reader.readSizedString());
|
||||||
collisionRule = CollisionRule.fromIdentifier(reader.readSizedString(Integer.MAX_VALUE));
|
collisionRule = CollisionRule.fromIdentifier(reader.readSizedString());
|
||||||
this.teamColor = NamedTextColor.ofExact(reader.readVarInt());
|
this.teamColor = NamedTextColor.ofExact(reader.readVarInt());
|
||||||
this.teamPrefix = reader.readComponent(Integer.MAX_VALUE);
|
this.teamPrefix = reader.readComponent();
|
||||||
this.teamSuffix = reader.readComponent(Integer.MAX_VALUE);
|
this.teamSuffix = reader.readComponent();
|
||||||
break;
|
break;
|
||||||
case REMOVE_TEAM:
|
case REMOVE_TEAM:
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class TeamsPacket implements ComponentHoldingServerPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (action == Action.CREATE_TEAM || action == Action.ADD_PLAYERS_TEAM || action == Action.REMOVE_PLAYERS_TEAM) {
|
if (action == Action.CREATE_TEAM || action == Action.ADD_PLAYERS_TEAM || action == Action.REMOVE_PLAYERS_TEAM) {
|
||||||
entities = reader.readSizedStringArray(Integer.MAX_VALUE);
|
entities = reader.readSizedStringArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ public class UnlockRecipesPacket implements ServerPacket {
|
|||||||
int length = reader.readVarInt();
|
int length = reader.readVarInt();
|
||||||
recipesId = new String[length];
|
recipesId = new String[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
recipesId[i] = reader.readSizedString(Integer.MAX_VALUE);
|
recipesId[i] = reader.readSizedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == 0) {
|
if (mode == 0) {
|
||||||
int initRecipesLength = reader.readVarInt();
|
int initRecipesLength = reader.readVarInt();
|
||||||
initRecipesId = new String[initRecipesLength];
|
initRecipesId = new String[initRecipesLength];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
initRecipesId[i] = reader.readSizedString(Integer.MAX_VALUE);
|
initRecipesId[i] = reader.readSizedString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ public class UpdateScorePacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull BinaryReader reader) {
|
public void read(@NotNull BinaryReader reader) {
|
||||||
entityName = reader.readSizedString(Integer.MAX_VALUE);
|
entityName = reader.readSizedString();
|
||||||
action = reader.readByte();
|
action = reader.readByte();
|
||||||
objectiveName = reader.readSizedString(Integer.MAX_VALUE);
|
objectiveName = reader.readSizedString();
|
||||||
if (action != 1) {
|
if (action != 1) {
|
||||||
value = reader.readVarInt();
|
value = reader.readVarInt();
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,10 @@ public class BinaryReader extends InputStream {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String readSizedString() {
|
||||||
|
return readSizedString(Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] readBytes(int length) {
|
public byte[] readBytes(int length) {
|
||||||
ByteBuf buf = buffer.readBytes(length);
|
ByteBuf buf = buffer.readBytes(length);
|
||||||
byte[] bytes = new byte[buf.readableBytes()];
|
byte[] bytes = new byte[buf.readableBytes()];
|
||||||
@ -134,6 +138,10 @@ public class BinaryReader extends InputStream {
|
|||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] readSizedStringArray() {
|
||||||
|
return readSizedStringArray(Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
public int[] readVarIntArray() {
|
public int[] readVarIntArray() {
|
||||||
final int size = readVarInt();
|
final int size = readVarInt();
|
||||||
int[] array = new int[size];
|
int[] array = new int[size];
|
||||||
@ -152,14 +160,6 @@ public class BinaryReader extends InputStream {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #readRemainingBytes()} (same semantics, but more consistent naming)
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public byte[] getRemainingBytes() {
|
|
||||||
return readRemainingBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] readRemainingBytes() {
|
public byte[] readRemainingBytes() {
|
||||||
return readBytes(available());
|
return readBytes(available());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user