More cleanup

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-12-01 22:59:38 +01:00
parent 22a8ccabfa
commit 74aceda0ad
12 changed files with 40 additions and 31 deletions

View File

@ -7,7 +7,8 @@ import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
public record BlockBreakAnimationPacket(int entityId, Point blockPosition, byte destroyStage) implements ServerPacket {
public record BlockBreakAnimationPacket(int entityId, @NotNull Point blockPosition,
byte destroyStage) implements ServerPacket {
public BlockBreakAnimationPacket(BinaryReader reader) {
this(reader.readVarInt(), reader.readBlockPosition(), reader.readByte());
}

View File

@ -6,9 +6,11 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
public record BlockEntityDataPacket(Point blockPosition, int action, NBTCompound data) implements ServerPacket {
public record BlockEntityDataPacket(@NotNull Point blockPosition, int action,
@Nullable NBTCompound data) implements ServerPacket {
public BlockEntityDataPacket(BinaryReader reader) {
this(reader.readBlockPosition(), reader.readVarInt(), (NBTCompound) reader.readTag());
}

View File

@ -5,17 +5,17 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public record SelectAdvancementTabPacket(String identifier) implements ServerPacket {
public record SelectAdvancementTabPacket(@Nullable String identifier) implements ServerPacket {
public SelectAdvancementTabPacket(BinaryReader reader) {
this(reader.readBoolean() ? reader.readSizedString() : null);
}
@Override
public void write(@NotNull BinaryWriter writer) {
final boolean hasId = identifier != null;
writer.writeBoolean(hasId);
if (hasId) writer.writeSizedString(identifier);
writer.writeBoolean(identifier != null);
if (identifier != null) writer.writeSizedString(identifier);
}
@Override

View File

@ -9,7 +9,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public record SpawnEntityPacket(int entityId, UUID uuid, int type, Pos position, int data,
public record SpawnEntityPacket(int entityId, @NotNull UUID uuid, int type,
@NotNull Pos position, int data,
short velocityX, short velocityY, short velocityZ) implements ServerPacket {
public SpawnEntityPacket(BinaryReader reader) {
this(reader.readVarInt(), reader.readUuid(), reader.readVarInt(),

View File

@ -7,9 +7,11 @@ import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
public record SpawnExperienceOrbPacket(int entityId, Pos position, short expCount) implements ServerPacket {
public record SpawnExperienceOrbPacket(int entityId,
@NotNull Pos position, short expCount) implements ServerPacket {
public SpawnExperienceOrbPacket(BinaryReader reader) {
this(reader.readVarInt(), new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble()), reader.readShort());
this(reader.readVarInt(),
new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble()), reader.readShort());
}
@Override

View File

@ -9,14 +9,14 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public record SpawnLivingEntityPacket(int entityId, UUID entityUuid, int entityType, Pos position, float headPitch,
public record SpawnLivingEntityPacket(int entityId, @NotNull UUID entityUuid, int entityType,
@NotNull Pos position, float headPitch,
short velocityX, short velocityY, short velocityZ) implements ServerPacket {
public SpawnLivingEntityPacket(BinaryReader reader) {
this(reader.readVarInt(), reader.readUuid(), reader.readVarInt(),
new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble(),
reader.readByte() * 360f / 256f,
reader.readByte() * 360f / 256f),
reader.readByte() * 360f / 256f,
reader.readByte() * 360f / 256f), reader.readByte() * 360f / 256f,
reader.readShort(), reader.readShort(), reader.readShort());
}

View File

@ -9,10 +9,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public record SpawnPaintingPacket(int entityId, UUID entityUuid, int motive, Point position,
byte direction) implements ServerPacket {
public record SpawnPaintingPacket(int entityId, @NotNull UUID entityUuid, int motive,
@NotNull Point position, byte direction) implements ServerPacket {
public SpawnPaintingPacket(BinaryReader reader) {
this(reader.readVarInt(), reader.readUuid(), reader.readVarInt(), reader.readBlockPosition(), reader.readByte());
this(reader.readVarInt(), reader.readUuid(), reader.readVarInt(),
reader.readBlockPosition(), reader.readByte());
}
@Override

View File

@ -9,10 +9,12 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public record SpawnPlayerPacket(int entityId, UUID playerUuid, Pos position) implements ServerPacket {
public record SpawnPlayerPacket(int entityId, @NotNull UUID playerUuid,
@NotNull Pos position) implements ServerPacket {
public SpawnPlayerPacket(BinaryReader reader) {
this(reader.readVarInt(), reader.readUuid(), new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble(),
(reader.readByte() * 360f) / 256f, (reader.readByte() * 360f) / 256f));
this(reader.readVarInt(), reader.readUuid(),
new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble(),
(reader.readByte() * 360f) / 256f, (reader.readByte() * 360f) / 256f));
}
@Override

View File

@ -7,7 +7,7 @@ import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
public record SpawnPositionPacket(Point position, float angle) implements ServerPacket {
public record SpawnPositionPacket(@NotNull Point position, float angle) implements ServerPacket {
public SpawnPositionPacket(BinaryReader reader) {
this(reader.readBlockPosition(), reader.readFloat());
}

View File

@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public record StatisticsPacket(List<Statistic> statistics) implements ServerPacket {
public record StatisticsPacket(@NotNull List<Statistic> statistics) implements ServerPacket {
public StatisticsPacket {
statistics = List.copyOf(statistics);
}
@ -21,10 +21,7 @@ public record StatisticsPacket(List<Statistic> statistics) implements ServerPack
@Override
public void write(@NotNull BinaryWriter writer) {
writer.writeVarInt(statistics.size());
for (Statistic statistic : statistics) {
statistic.write(writer);
}
writer.writeVarIntList(statistics, BinaryWriter::write);
}
@Override
@ -32,9 +29,11 @@ public record StatisticsPacket(List<Statistic> statistics) implements ServerPack
return ServerPacketIdentifier.STATISTICS;
}
public record Statistic(StatisticCategory category, int statisticId, int value) implements Writeable {
public record Statistic(@NotNull StatisticCategory category,
int statisticId, int value) implements Writeable {
public Statistic(BinaryReader reader) {
this(StatisticCategory.values()[reader.readVarInt()], reader.readVarInt(), reader.readVarInt());
this(StatisticCategory.values()[reader.readVarInt()],
reader.readVarInt(), reader.readVarInt());
}
@Override

View File

@ -10,11 +10,11 @@ import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
public record TagsPacket(Map<Tag.BasicType, List<Tag>> tagsMap) implements ServerPacket {
public record TagsPacket(@NotNull Map<Tag.BasicType, List<Tag>> tagsMap) implements ServerPacket {
@ApiStatus.Internal
public static final CachedPacket DEFAULT_TAGS = new CachedPacket(new TagsPacket(MinecraftServer.getTagManager().getTagMap()));
@ -51,7 +51,7 @@ public record TagsPacket(Map<Tag.BasicType, List<Tag>> tagsMap) implements Serve
}
private static Map<Tag.BasicType, List<Tag>> readTagsMap(BinaryReader reader) {
Map<Tag.BasicType, List<Tag>> tagsMap = new HashMap<>();
Map<Tag.BasicType, List<Tag>> tagsMap = new EnumMap<>(Tag.BasicType.class);
// Read amount of tag types
final int typeCount = reader.readVarInt();
for (int i = 0; i < typeCount; i++) {

View File

@ -7,9 +7,10 @@ import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
public record VehicleMovePacket(Pos position) implements ServerPacket {
public record VehicleMovePacket(@NotNull Pos position) implements ServerPacket {
public VehicleMovePacket(BinaryReader reader) {
this(new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble(), reader.readFloat(), reader.readFloat()));
this(new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble(),
reader.readFloat(), reader.readFloat()));
}
@Override