mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +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();
|
||||
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();
|
||||
typeToIndexMap.put(className, classIndex);
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ public class SerializableDataImpl extends SerializableData {
|
||||
}
|
||||
|
||||
// Get the key
|
||||
final String name = reader.readSizedString(Integer.MAX_VALUE);
|
||||
final String name = reader.readSizedString();
|
||||
|
||||
// Get the data
|
||||
final Object value;
|
||||
|
@ -28,8 +28,8 @@ public class InventoryData extends DataType<Inventory> {
|
||||
@NotNull
|
||||
@Override
|
||||
public Inventory decode(@NotNull BinaryReader reader) {
|
||||
final Component title = reader.readComponent(Integer.MAX_VALUE);
|
||||
final InventoryType inventoryType = InventoryType.valueOf(reader.readSizedString(Integer.MAX_VALUE));
|
||||
final Component title = reader.readComponent();
|
||||
final InventoryType inventoryType = InventoryType.valueOf(reader.readSizedString());
|
||||
final int size = inventoryType.getSize();
|
||||
|
||||
Inventory inventory = new Inventory(inventoryType, title);
|
||||
|
@ -15,6 +15,6 @@ public class StringData extends DataType<String> {
|
||||
@NotNull
|
||||
@Override
|
||||
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) {
|
||||
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
|
||||
@ -71,7 +71,7 @@ public class Metadata {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -84,7 +84,7 @@ public class Metadata {
|
||||
}, reader -> {
|
||||
boolean present = reader.readBoolean();
|
||||
if (present) {
|
||||
return reader.readComponent(Integer.MAX_VALUE);
|
||||
return reader.readComponent();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
@ -73,7 +73,7 @@ public final class VelocityProxy {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -16,7 +16,7 @@ public class ResponsePacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
jsonResponse = reader.readSizedString(Integer.MAX_VALUE);
|
||||
jsonResponse = reader.readSizedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +39,7 @@ public class EncryptionRequestPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
nonce = ByteArrayData.decodeByteArray(reader);
|
||||
|
@ -38,7 +38,7 @@ public class LoginDisconnectPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
kickMessage = reader.readComponent(Integer.MAX_VALUE);
|
||||
kickMessage = reader.readComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ public class LoginPluginRequestPacket implements ServerPacket {
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
messageId = reader.readVarInt();
|
||||
channel = reader.readSizedString(Integer.MAX_VALUE);
|
||||
channel = reader.readSizedString();
|
||||
data = reader.readRemainingBytes();
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class LoginSuccessPacket implements ServerPacket {
|
||||
* DO NOT USE.
|
||||
*/
|
||||
private LoginSuccessPacket() {
|
||||
this(new UUID(0,0), "");
|
||||
this(new UUID(0, 0), "");
|
||||
}
|
||||
|
||||
public LoginSuccessPacket(@NotNull UUID uuid, @NotNull String username) {
|
||||
@ -34,7 +34,7 @@ public class LoginSuccessPacket implements ServerPacket {
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
uuid = reader.readUuid();
|
||||
username = reader.readSizedString(Integer.MAX_VALUE);
|
||||
username = reader.readSizedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,7 +112,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
key = reader.readSizedString(Integer.MAX_VALUE);
|
||||
key = reader.readSizedString();
|
||||
value = new Advancement();
|
||||
value.read(reader);
|
||||
}
|
||||
@ -151,7 +151,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
boolean hasParent = reader.readBoolean();
|
||||
if (hasParent) {
|
||||
parentIdentifier = reader.readSizedString(Integer.MAX_VALUE);
|
||||
parentIdentifier = reader.readSizedString();
|
||||
} else {
|
||||
parentIdentifier = null;
|
||||
}
|
||||
@ -164,7 +164,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
||||
displayData = null;
|
||||
}
|
||||
|
||||
criterions = reader.readSizedStringArray(Integer.MAX_VALUE);
|
||||
criterions = reader.readSizedStringArray();
|
||||
|
||||
int requirementCount = reader.readVarInt();
|
||||
requirements = new Requirement[requirementCount];
|
||||
@ -201,13 +201,13 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
title = reader.readComponent(Integer.MAX_VALUE);
|
||||
description = reader.readComponent(Integer.MAX_VALUE);
|
||||
title = reader.readComponent();
|
||||
description = reader.readComponent();
|
||||
icon = reader.readItemStack();
|
||||
frameType = FrameType.values()[reader.readVarInt()];
|
||||
flags = reader.readInt();
|
||||
if ((flags & 0x1) != 0) {
|
||||
backgroundTexture = reader.readSizedString(Integer.MAX_VALUE);
|
||||
backgroundTexture = reader.readSizedString();
|
||||
} else {
|
||||
backgroundTexture = null;
|
||||
}
|
||||
@ -243,7 +243,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
key = reader.readSizedString(Integer.MAX_VALUE);
|
||||
key = reader.readSizedString();
|
||||
value = new AdvancementProgress();
|
||||
value.read(reader);
|
||||
}
|
||||
@ -283,7 +283,7 @@ public class AdvancementsPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
criterionIdentifier = reader.readSizedString(Integer.MAX_VALUE);
|
||||
criterionIdentifier = reader.readSizedString();
|
||||
criterionProgress = new CriterionProgress();
|
||||
criterionProgress.read(reader);
|
||||
}
|
||||
|
@ -26,7 +26,8 @@ public class BossBarPacket implements ComponentHoldingServerPacket {
|
||||
public BossBar.Overlay overlay = BossBar.Overlay.PROGRESS;
|
||||
public byte flags;
|
||||
|
||||
public BossBarPacket() {}
|
||||
public BossBarPacket() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
@ -67,7 +68,7 @@ public class BossBarPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
switch (action) {
|
||||
case ADD:
|
||||
title = reader.readComponent(Integer.MAX_VALUE);
|
||||
title = reader.readComponent();
|
||||
health = reader.readFloat();
|
||||
color = BossBar.Color.values()[reader.readVarInt()];
|
||||
overlay = BossBar.Overlay.values()[reader.readVarInt()];
|
||||
@ -80,7 +81,7 @@ public class BossBarPacket implements ComponentHoldingServerPacket {
|
||||
health = reader.readFloat();
|
||||
break;
|
||||
case UPDATE_TITLE:
|
||||
title = reader.readComponent(Integer.MAX_VALUE);
|
||||
title = reader.readComponent();
|
||||
break;
|
||||
case UPDATE_STYLE:
|
||||
color = BossBar.Color.values()[reader.readVarInt()];
|
||||
@ -127,7 +128,8 @@ public class BossBarPacket implements ComponentHoldingServerPacket {
|
||||
packet.flags = flags;
|
||||
return packet;
|
||||
}
|
||||
default: return this;
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class ChatMessagePacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
message = reader.readComponent(Integer.MAX_VALUE);
|
||||
message = reader.readComponent();
|
||||
position = ChatPosition.fromPacketID(reader.readByte());
|
||||
uuid = reader.readUuid();
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class CraftRecipeResponse implements ServerPacket {
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
windowId = reader.readByte();
|
||||
recipe = reader.readSizedString(Integer.MAX_VALUE);
|
||||
recipe = reader.readSizedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,7 @@ public class DeathCombatEventPacket implements ServerPacket {
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
this.playerId = reader.readVarInt();
|
||||
this.entityId = reader.readInt();
|
||||
this.message = reader.readComponent(Integer.MAX_VALUE);
|
||||
this.message = reader.readComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,16 +83,16 @@ public class DeclareCommandsPacket implements ServerPacket {
|
||||
}
|
||||
|
||||
if (isLiteral() || isArgument()) {
|
||||
name = reader.readSizedString(Integer.MAX_VALUE);
|
||||
name = reader.readSizedString();
|
||||
}
|
||||
|
||||
if(isArgument()) {
|
||||
parser = reader.readSizedString(Integer.MAX_VALUE);
|
||||
if (isArgument()) {
|
||||
parser = reader.readSizedString();
|
||||
properties = getProperties(reader, parser);
|
||||
}
|
||||
|
||||
if ((flags & 0x10) != 0) {
|
||||
suggestionsType = reader.readSizedString(Integer.MAX_VALUE);
|
||||
suggestionsType = reader.readSizedString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,10 +101,10 @@ public class DeclareCommandsPacket implements ServerPacket {
|
||||
case "brigadier:double":
|
||||
return reader.extractBytes(() -> {
|
||||
byte flags = reader.readByte();
|
||||
if((flags & 0x01) == 0x01) {
|
||||
if ((flags & 0x01) == 0x01) {
|
||||
reader.readDouble(); // min
|
||||
}
|
||||
if((flags & 0x02) == 0x02) {
|
||||
if ((flags & 0x02) == 0x02) {
|
||||
reader.readDouble(); // max
|
||||
}
|
||||
});
|
||||
@ -112,10 +112,10 @@ public class DeclareCommandsPacket implements ServerPacket {
|
||||
case "brigadier:integer":
|
||||
return reader.extractBytes(() -> {
|
||||
byte flags = reader.readByte();
|
||||
if((flags & 0x01) == 0x01) {
|
||||
if ((flags & 0x01) == 0x01) {
|
||||
reader.readInt(); // min
|
||||
}
|
||||
if((flags & 0x02) == 0x02) {
|
||||
if ((flags & 0x02) == 0x02) {
|
||||
reader.readInt(); // max
|
||||
}
|
||||
});
|
||||
|
@ -32,8 +32,8 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
int recipeCount = reader.readVarInt();
|
||||
recipes = new DeclaredRecipe[recipeCount];
|
||||
for (int i = 0; i < recipeCount; i++) {
|
||||
String type = reader.readSizedString(Integer.MAX_VALUE);
|
||||
String id = reader.readSizedString(Integer.MAX_VALUE);
|
||||
String type = reader.readSizedString();
|
||||
String id = reader.readSizedString();
|
||||
|
||||
switch (type) {
|
||||
case "crafting_shapeless":
|
||||
@ -136,7 +136,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
||||
group = reader.readSizedString();
|
||||
int count = reader.readVarInt();
|
||||
ingredients = new Ingredient[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
@ -193,7 +193,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
width = reader.readVarInt();
|
||||
height = reader.readVarInt();
|
||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
||||
group = reader.readSizedString();
|
||||
ingredients = new Ingredient[width * height];
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
ingredients[i] = new Ingredient();
|
||||
@ -245,7 +245,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
||||
group = reader.readSizedString();
|
||||
ingredient = new Ingredient();
|
||||
ingredient.read(reader);
|
||||
result = reader.readItemStack();
|
||||
@ -296,7 +296,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
||||
group = reader.readSizedString();
|
||||
ingredient = new Ingredient();
|
||||
ingredient.read(reader);
|
||||
result = reader.readItemStack();
|
||||
@ -347,7 +347,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
||||
group = reader.readSizedString();
|
||||
ingredient = new Ingredient();
|
||||
ingredient.read(reader);
|
||||
result = reader.readItemStack();
|
||||
@ -398,7 +398,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
||||
group = reader.readSizedString();
|
||||
ingredient = new Ingredient();
|
||||
ingredient.read(reader);
|
||||
result = reader.readItemStack();
|
||||
@ -441,7 +441,7 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
group = reader.readSizedString(Integer.MAX_VALUE);
|
||||
group = reader.readSizedString();
|
||||
ingredient = new Ingredient();
|
||||
ingredient.read(reader);
|
||||
result = reader.readItemStack();
|
||||
|
@ -17,6 +17,7 @@ public class DisconnectPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
/**
|
||||
* Creates a new disconnect packet with a given message.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public DisconnectPacket(@NotNull Component message) {
|
||||
@ -34,7 +35,7 @@ public class DisconnectPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
message = reader.readComponent(Integer.MAX_VALUE);
|
||||
message = reader.readComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ public class DisplayScoreboardPacket implements ServerPacket {
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
position = reader.readByte();
|
||||
scoreName = reader.readSizedString(Integer.MAX_VALUE);
|
||||
scoreName = reader.readSizedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,7 +76,7 @@ public class EntityPropertiesPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
String key = reader.readSizedString(Integer.MAX_VALUE);
|
||||
String key = reader.readSizedString();
|
||||
attribute = Attribute.fromKey(key);
|
||||
|
||||
value = reader.readDouble();
|
||||
|
@ -40,7 +40,7 @@ public class JoinGamePacket implements ServerPacket {
|
||||
writer.writeBoolean(hardcore);
|
||||
writer.writeByte(gameMode.getId());
|
||||
|
||||
if(previousGameMode == null) {
|
||||
if (previousGameMode == null) {
|
||||
writer.writeByte(gameMode.getId());
|
||||
} else {
|
||||
writer.writeByte(previousGameMode.getId());
|
||||
@ -80,23 +80,23 @@ public class JoinGamePacket implements ServerPacket {
|
||||
int worldCount = reader.readVarInt();
|
||||
Check.stateCondition(worldCount != 1, "Only 1 world is supported per JoinGamePacket by Minestom for the moment.");
|
||||
//for (int i = 0; i < worldCount; i++) {
|
||||
String worldName = reader.readSizedString(Integer.MAX_VALUE);
|
||||
try {
|
||||
NBTCompound dimensionCodec = (NBTCompound) reader.readTag();
|
||||
dimensionType = DimensionType.fromNBT((NBTCompound) reader.readTag());
|
||||
String worldName = reader.readSizedString();
|
||||
try {
|
||||
NBTCompound dimensionCodec = (NBTCompound) reader.readTag();
|
||||
dimensionType = DimensionType.fromNBT((NBTCompound) reader.readTag());
|
||||
|
||||
String dimensionName = reader.readSizedString(Integer.MAX_VALUE);
|
||||
hashedSeed = reader.readLong();
|
||||
maxPlayers = reader.readVarInt();
|
||||
viewDistance = reader.readVarInt();
|
||||
reducedDebugInfo = reader.readBoolean();
|
||||
enableRespawnScreen = reader.readBoolean();
|
||||
isDebug = reader.readBoolean();
|
||||
isFlat = reader.readBoolean();
|
||||
} catch (IOException | NBTException e) {
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
// TODO: should we throw as the packet is invalid?
|
||||
}
|
||||
String dimensionName = reader.readSizedString();
|
||||
hashedSeed = reader.readLong();
|
||||
maxPlayers = reader.readVarInt();
|
||||
viewDistance = reader.readVarInt();
|
||||
reducedDebugInfo = reader.readBoolean();
|
||||
enableRespawnScreen = reader.readBoolean();
|
||||
isDebug = reader.readBoolean();
|
||||
isFlat = reader.readBoolean();
|
||||
} catch (IOException | NBTException e) {
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
// TODO: should we throw as the packet is invalid?
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class MapDataPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
boolean hasDisplayName = reader.readBoolean();
|
||||
if (hasDisplayName) {
|
||||
displayName = reader.readComponent(Integer.MAX_VALUE);
|
||||
displayName = reader.readComponent();
|
||||
} else {
|
||||
displayName = null;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class NamedSoundEffectPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
soundName = reader.readSizedString(Integer.MAX_VALUE);
|
||||
soundName = reader.readSizedString();
|
||||
soundSource = Source.values()[reader.readVarInt()];
|
||||
x = reader.readInt() / 8;
|
||||
y = reader.readInt() / 8;
|
||||
|
@ -31,7 +31,7 @@ public class OpenWindowPacket implements ServerPacket {
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
windowId = reader.readVarInt();
|
||||
windowType = reader.readVarInt();
|
||||
title = reader.readComponent(Integer.MAX_VALUE);
|
||||
title = reader.readComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,7 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported action encountered: "+action.name());
|
||||
throw new IllegalArgumentException("Unsupported action encountered: " + action.name());
|
||||
}
|
||||
|
||||
playerInfos.set(i, info);
|
||||
@ -92,7 +92,8 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
||||
}
|
||||
}
|
||||
return components;
|
||||
default: return Collections.emptyList();
|
||||
default:
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +111,8 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
||||
playerInfos.add(playerInfo);
|
||||
}
|
||||
}
|
||||
default: return this;
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +165,7 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
AddPlayer(UUID uuid, BinaryReader reader) {
|
||||
super(uuid);
|
||||
name = reader.readSizedString(Integer.MAX_VALUE);
|
||||
name = reader.readSizedString();
|
||||
int propertyCount = reader.readVarInt();
|
||||
|
||||
properties = new ArrayList<>(propertyCount);
|
||||
@ -175,8 +177,8 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
||||
ping = reader.readVarInt();
|
||||
boolean hasDisplayName = reader.readBoolean();
|
||||
|
||||
if(hasDisplayName) {
|
||||
displayName = reader.readComponent(Integer.MAX_VALUE);
|
||||
if (hasDisplayName) {
|
||||
displayName = reader.readComponent();
|
||||
} else {
|
||||
displayName = null;
|
||||
}
|
||||
@ -235,12 +237,12 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
||||
}
|
||||
|
||||
Property(BinaryReader reader) {
|
||||
name = reader.readSizedString(Integer.MAX_VALUE);
|
||||
value = reader.readSizedString(Integer.MAX_VALUE);
|
||||
name = reader.readSizedString();
|
||||
value = reader.readSizedString();
|
||||
boolean hasSignature = reader.readBoolean();
|
||||
|
||||
if(hasSignature) {
|
||||
signature = reader.readSizedString(Integer.MAX_VALUE);
|
||||
if (hasSignature) {
|
||||
signature = reader.readSizedString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,8 +310,8 @@ public class PlayerInfoPacket implements ComponentHoldingServerPacket {
|
||||
UpdateDisplayName(UUID uuid, BinaryReader reader) {
|
||||
super(uuid);
|
||||
boolean hasDisplayName = reader.readBoolean();
|
||||
if(hasDisplayName) {
|
||||
displayName = reader.readComponent(Integer.MAX_VALUE);
|
||||
if (hasDisplayName) {
|
||||
displayName = reader.readComponent();
|
||||
} else {
|
||||
displayName = null;
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ public class PlayerListHeaderAndFooterPacket implements ComponentHoldingServerPa
|
||||
}
|
||||
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
header = reader.readComponent(Integer.MAX_VALUE);
|
||||
footer = reader.readComponent(Integer.MAX_VALUE);
|
||||
header = reader.readComponent();
|
||||
footer = reader.readComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,8 +20,8 @@ public class PluginMessagePacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
channel = reader.readSizedString(Integer.MAX_VALUE);
|
||||
data = reader.getRemainingBytes();
|
||||
channel = reader.readSizedString();
|
||||
data = reader.readRemainingBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,8 +37,8 @@ public class ResourcePackSendPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
this.url = reader.readSizedString(Integer.MAX_VALUE);
|
||||
this.hash = reader.readSizedString(Integer.MAX_VALUE);
|
||||
this.url = reader.readSizedString();
|
||||
this.hash = reader.readSizedString();
|
||||
this.forced = reader.readBoolean();
|
||||
if (forced) {
|
||||
this.forcedMessage = reader.readComponent();
|
||||
|
@ -47,7 +47,7 @@ public class RespawnPacket implements ServerPacket {
|
||||
dimensionType = DimensionType.fromNBT((NBTCompound) reader.readTag());
|
||||
|
||||
// dimension type name
|
||||
reader.readSizedString(Integer.MAX_VALUE);
|
||||
reader.readSizedString();
|
||||
|
||||
hashedSeed = reader.readLong();
|
||||
gameMode = GameMode.values()[reader.readByte()];
|
||||
|
@ -52,11 +52,11 @@ public class ScoreboardObjectivePacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
objectiveName = reader.readSizedString(Integer.MAX_VALUE);
|
||||
objectiveName = reader.readSizedString();
|
||||
mode = reader.readByte();
|
||||
|
||||
if(mode == 0 || mode == 2) {
|
||||
objectiveValue = reader.readComponent(Integer.MAX_VALUE);
|
||||
if (mode == 0 || mode == 2) {
|
||||
objectiveValue = reader.readComponent();
|
||||
type = Type.values()[reader.readVarInt()];
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ public class SelectAdvancementTabPacket implements ServerPacket {
|
||||
@Nullable
|
||||
public String identifier;
|
||||
|
||||
public SelectAdvancementTabPacket() {}
|
||||
public SelectAdvancementTabPacket() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
@ -27,8 +28,8 @@ public class SelectAdvancementTabPacket implements ServerPacket {
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
boolean hasID = reader.readBoolean();
|
||||
if(hasID) {
|
||||
identifier = reader.readSizedString(Integer.MAX_VALUE);
|
||||
if (hasID) {
|
||||
identifier = reader.readSizedString();
|
||||
} else {
|
||||
identifier = null;
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ public class StopSoundPacket implements ServerPacket {
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
flags = reader.readByte();
|
||||
if(flags == 3 || flags == 1) {
|
||||
if (flags == 3 || flags == 1) {
|
||||
source = reader.readVarInt();
|
||||
}
|
||||
if(flags == 2 || flags == 3) {
|
||||
sound = reader.readSizedString(Integer.MAX_VALUE);
|
||||
if (flags == 2 || flags == 3) {
|
||||
sound = reader.readSizedString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,11 +50,11 @@ public class TabCompletePacket implements ComponentHoldingServerPacket {
|
||||
int matchCount = reader.readVarInt();
|
||||
matches = new Match[matchCount];
|
||||
for (int i = 0; i < matchCount; i++) {
|
||||
String match = reader.readSizedString(Integer.MAX_VALUE);
|
||||
String match = reader.readSizedString();
|
||||
boolean hasTooltip = reader.readBoolean();
|
||||
Component tooltip = null;
|
||||
if(hasTooltip) {
|
||||
tooltip = reader.readComponent(Integer.MAX_VALUE);
|
||||
if (hasTooltip) {
|
||||
tooltip = reader.readComponent();
|
||||
}
|
||||
Match newMatch = new Match();
|
||||
newMatch.match = match;
|
||||
|
@ -147,14 +147,14 @@ public class TagsPacket implements ServerPacket {
|
||||
final int typeCount = reader.readVarInt();
|
||||
for (int i = 0; i < typeCount; i++) {
|
||||
// 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) {
|
||||
throw new IllegalArgumentException("Tag type could not be resolved");
|
||||
}
|
||||
|
||||
final int tagCount = reader.readVarInt();
|
||||
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();
|
||||
// TODO convert
|
||||
}
|
||||
|
@ -106,19 +106,19 @@ public class TeamsPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
teamName = reader.readSizedString(Integer.MAX_VALUE);
|
||||
teamName = reader.readSizedString();
|
||||
action = Action.values()[reader.readByte()];
|
||||
|
||||
switch (action) {
|
||||
case CREATE_TEAM:
|
||||
case UPDATE_TEAM_INFO:
|
||||
this.teamDisplayName = reader.readComponent(Integer.MAX_VALUE);
|
||||
this.teamDisplayName = reader.readComponent();
|
||||
this.friendlyFlags = reader.readByte();
|
||||
nameTagVisibility = NameTagVisibility.fromIdentifier(reader.readSizedString(Integer.MAX_VALUE));
|
||||
collisionRule = CollisionRule.fromIdentifier(reader.readSizedString(Integer.MAX_VALUE));
|
||||
nameTagVisibility = NameTagVisibility.fromIdentifier(reader.readSizedString());
|
||||
collisionRule = CollisionRule.fromIdentifier(reader.readSizedString());
|
||||
this.teamColor = NamedTextColor.ofExact(reader.readVarInt());
|
||||
this.teamPrefix = reader.readComponent(Integer.MAX_VALUE);
|
||||
this.teamSuffix = reader.readComponent(Integer.MAX_VALUE);
|
||||
this.teamPrefix = reader.readComponent();
|
||||
this.teamSuffix = reader.readComponent();
|
||||
break;
|
||||
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) {
|
||||
entities = reader.readSizedStringArray(Integer.MAX_VALUE);
|
||||
entities = reader.readSizedStringArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,11 +232,11 @@ public class TeamsPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@NotNull
|
||||
public static NameTagVisibility fromIdentifier(String identifier) {
|
||||
for(NameTagVisibility v : values()) {
|
||||
if(v.getIdentifier().equals(identifier))
|
||||
for (NameTagVisibility v : values()) {
|
||||
if (v.getIdentifier().equals(identifier))
|
||||
return v;
|
||||
}
|
||||
Check.fail("Identifier for NameTagVisibility is invalid: "+identifier);
|
||||
Check.fail("Identifier for NameTagVisibility is invalid: " + identifier);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -288,11 +288,11 @@ public class TeamsPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
@NotNull
|
||||
public static CollisionRule fromIdentifier(String identifier) {
|
||||
for(CollisionRule v : values()) {
|
||||
if(v.getIdentifier().equals(identifier))
|
||||
for (CollisionRule v : values()) {
|
||||
if (v.getIdentifier().equals(identifier))
|
||||
return v;
|
||||
}
|
||||
Check.fail("Identifier for CollisionRule is invalid: "+identifier);
|
||||
Check.fail("Identifier for CollisionRule is invalid: " + identifier);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -62,14 +62,14 @@ public class UnlockRecipesPacket implements ServerPacket {
|
||||
int length = reader.readVarInt();
|
||||
recipesId = new String[length];
|
||||
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();
|
||||
initRecipesId = new String[initRecipesLength];
|
||||
for (int i = 0; i < length; i++) {
|
||||
initRecipesId[i] = reader.readSizedString(Integer.MAX_VALUE);
|
||||
initRecipesId[i] = reader.readSizedString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +33,10 @@ public class UpdateScorePacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
entityName = reader.readSizedString(Integer.MAX_VALUE);
|
||||
entityName = reader.readSizedString();
|
||||
action = reader.readByte();
|
||||
objectiveName = reader.readSizedString(Integer.MAX_VALUE);
|
||||
if(action != 1) {
|
||||
objectiveName = reader.readSizedString();
|
||||
if (action != 1) {
|
||||
value = reader.readVarInt();
|
||||
}
|
||||
}
|
||||
|
@ -117,6 +117,10 @@ public class BinaryReader extends InputStream {
|
||||
return str;
|
||||
}
|
||||
|
||||
public String readSizedString() {
|
||||
return readSizedString(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public byte[] readBytes(int length) {
|
||||
ByteBuf buf = buffer.readBytes(length);
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
@ -134,6 +138,10 @@ public class BinaryReader extends InputStream {
|
||||
return strings;
|
||||
}
|
||||
|
||||
public String[] readSizedStringArray() {
|
||||
return readSizedStringArray(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public int[] readVarIntArray() {
|
||||
final int size = readVarInt();
|
||||
int[] array = new int[size];
|
||||
@ -152,14 +160,6 @@ public class BinaryReader extends InputStream {
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #readRemainingBytes()} (same semantics, but more consistent naming)
|
||||
*/
|
||||
@Deprecated
|
||||
public byte[] getRemainingBytes() {
|
||||
return readRemainingBytes();
|
||||
}
|
||||
|
||||
public byte[] readRemainingBytes() {
|
||||
return readBytes(available());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user