From ea80d56bd04a94f5d0f405faa9bfd35a6e92442b Mon Sep 17 00:00:00 2001 From: themode Date: Sun, 25 Oct 2020 22:19:27 +0100 Subject: [PATCH] Small packet cleanup, removed LevelType, new RawJsonMessage --- .../net/minestom/server/chat/JsonMessage.java | 16 +++++++ .../server/data/type/array/ByteArrayData.java | 4 +- .../net/minestom/server/entity/GameMode.java | 12 +++++ .../net/minestom/server/entity/Player.java | 17 +++---- .../server/instance/block/CustomBlock.java | 4 ++ .../network/packet/server/ServerPacket.java | 6 ++- .../server/handshake/ResponsePacket.java | 3 +- .../server/login/EncryptionRequestPacket.java | 8 ++-- .../packet/server/login/JoinGamePacket.java | 13 +++--- .../packet/server/login/LoginDisconnect.java | 3 +- .../server/login/LoginSuccessPacket.java | 3 +- .../server/login/SetCompressionPacket.java | 3 +- .../play/AcknowledgePlayerDiggingPacket.java | 3 +- .../server/play/AdvancementsPacket.java | 45 ++++++++++++------- .../server/play/AttachEntityPacket.java | 3 +- .../packet/server/play/BlockActionPacket.java | 3 +- .../play/BlockBreakAnimationPacket.java | 3 +- .../packet/server/play/BlockChangePacket.java | 3 +- .../packet/server/play/BossBarPacket.java | 3 +- .../packet/server/play/CameraPacket.java | 3 +- .../server/play/ChangeGameStatePacket.java | 3 +- .../packet/server/play/ChatMessagePacket.java | 3 +- .../packet/server/play/ChunkDataPacket.java | 3 +- .../packet/server/play/CloseWindowPacket.java | 3 +- .../packet/server/play/CollectItemPacket.java | 3 +- .../packet/server/play/CombatEventPacket.java | 3 +- .../server/play/CraftRecipeResponse.java | 3 +- .../server/play/DeclareCommandsPacket.java | 10 +++-- .../server/play/DeclareRecipesPacket.java | 2 +- .../server/play/DestroyEntitiesPacket.java | 3 +- .../packet/server/play/DisconnectPacket.java | 3 +- .../server/play/DisplayScoreboardPacket.java | 3 +- .../packet/server/play/EffectPacket.java | 3 +- .../server/play/EntityAnimationPacket.java | 3 +- .../server/play/EntityEffectPacket.java | 3 +- .../server/play/EntityEquipmentPacket.java | 3 +- .../server/play/EntityHeadLookPacket.java | 3 +- .../server/play/EntityMetaDataPacket.java | 3 +- .../packet/server/play/EntityPacket.java | 3 +- .../play/EntityPositionAndRotationPacket.java | 3 +- .../server/play/EntityPositionPacket.java | 3 +- .../server/play/EntityPropertiesPacket.java | 3 +- .../server/play/EntityRotationPacket.java | 3 +- .../packet/server/play/EntitySoundEffect.java | 3 +- .../server/play/EntityStatusPacket.java | 3 +- .../server/play/EntityTeleportPacket.java | 3 +- .../server/play/EntityVelocityPacket.java | 3 +- .../packet/server/play/ExplosionPacket.java | 3 +- .../packet/server/play/FacePlayerPacket.java | 3 +- .../server/play/HeldItemChangePacket.java | 3 +- .../packet/server/play/KeepAlivePacket.java | 3 +- .../packet/server/play/MapDataPacket.java | 3 +- .../server/play/MultiBlockChangePacket.java | 3 +- .../server/play/NamedSoundEffectPacket.java | 3 +- .../packet/server/play/OpenBookPacket.java | 3 +- .../server/play/OpenHorseWindowPacket.java | 3 +- .../server/play/OpenSignEditorPacket.java | 3 +- .../packet/server/play/OpenWindowPacket.java | 3 +- .../packet/server/play/ParticlePacket.java | 3 +- .../server/play/PlayerAbilitiesPacket.java | 3 +- .../packet/server/play/PlayerInfoPacket.java | 2 +- .../play/PlayerListHeaderAndFooterPacket.java | 3 +- .../play/PlayerPositionAndLookPacket.java | 3 +- .../server/play/PluginMessagePacket.java | 3 +- .../server/play/RemoveEntityEffectPacket.java | 3 +- .../server/play/ResourcePackSendPacket.java | 3 +- .../packet/server/play/RespawnPacket.java | 17 ++++--- .../play/ScoreboardObjectivePacket.java | 3 +- .../server/play/ServerDifficultyPacket.java | 3 +- .../packet/server/play/SetCooldownPacket.java | 3 +- .../server/play/SetExperiencePacket.java | 3 +- .../server/play/SetPassengersPacket.java | 3 +- .../packet/server/play/SetSlotPacket.java | 3 +- .../packet/server/play/SoundEffectPacket.java | 3 +- .../packet/server/play/SpawnEntityPacket.java | 3 +- .../server/play/SpawnExperienceOrbPacket.java | 3 +- .../server/play/SpawnLivingEntityPacket.java | 3 +- .../server/play/SpawnPaintingPacket.java | 3 +- .../packet/server/play/SpawnPlayerPacket.java | 3 +- .../server/play/SpawnPositionPacket.java | 3 +- .../packet/server/play/StatisticsPacket.java | 3 +- .../packet/server/play/StopSoundPacket.java | 3 +- .../packet/server/play/TabCompletePacket.java | 3 +- .../packet/server/play/TagsPacket.java | 3 +- .../packet/server/play/TeamsPacket.java | 2 +- .../packet/server/play/TimeUpdatePacket.java | 3 +- .../packet/server/play/TitlePacket.java | 3 +- .../packet/server/play/TradeListPacket.java | 3 +- .../packet/server/play/UnloadChunkPacket.java | 3 +- .../server/play/UnlockRecipesPacket.java | 3 +- .../server/play/UpdateHealthPacket.java | 3 +- .../packet/server/play/UpdateLightPacket.java | 3 +- .../packet/server/play/UpdateScorePacket.java | 3 +- .../server/play/UpdateViewPositionPacket.java | 3 +- .../packet/server/play/VehicleMovePacket.java | 3 +- .../server/play/WindowConfirmationPacket.java | 3 +- .../packet/server/play/WindowItemsPacket.java | 3 +- .../server/play/WindowPropertyPacket.java | 3 +- .../packet/server/play/WorldBorderPacket.java | 3 +- .../packet/server/status/PongPacket.java | 3 +- .../server/utils/binary/BinaryReader.java | 27 +++++++++++ .../server/utils/binary/Readable.java | 17 +++++++ .../server/utils/binary/Writeable.java | 17 +++++++ .../utils/callback/OptionalCallback.java | 7 +-- .../net/minestom/server/world/LevelType.java | 23 ---------- 105 files changed, 338 insertions(+), 169 deletions(-) create mode 100644 src/main/java/net/minestom/server/utils/binary/Readable.java create mode 100644 src/main/java/net/minestom/server/utils/binary/Writeable.java delete mode 100644 src/main/java/net/minestom/server/world/LevelType.java diff --git a/src/main/java/net/minestom/server/chat/JsonMessage.java b/src/main/java/net/minestom/server/chat/JsonMessage.java index c65275695..7668b7a89 100644 --- a/src/main/java/net/minestom/server/chat/JsonMessage.java +++ b/src/main/java/net/minestom/server/chat/JsonMessage.java @@ -55,4 +55,20 @@ public abstract class JsonMessage { return compiledJson; } + + public static class RawJsonMessage extends JsonMessage { + + private JsonObject jsonObject; + + public RawJsonMessage(JsonObject jsonObject) { + this.jsonObject = jsonObject; + } + + @NotNull + @Override + public JsonObject getJsonObject() { + return jsonObject; + } + } + } diff --git a/src/main/java/net/minestom/server/data/type/array/ByteArrayData.java b/src/main/java/net/minestom/server/data/type/array/ByteArrayData.java index eb69118de..a1adb5881 100644 --- a/src/main/java/net/minestom/server/data/type/array/ByteArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/ByteArrayData.java @@ -17,14 +17,14 @@ public class ByteArrayData extends DataType { return decodeByteArray(reader); } - public static void encodeByteArray(BinaryWriter binaryWriter, byte[] value) { + public static void encodeByteArray(@NotNull BinaryWriter binaryWriter, @NotNull byte[] value) { binaryWriter.writeVarInt(value.length); for (byte val : value) { binaryWriter.writeByte(val); } } - public static byte[] decodeByteArray(BinaryReader binaryReader) { + public static byte[] decodeByteArray(@NotNull BinaryReader binaryReader) { byte[] array = new byte[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = binaryReader.readByte(); diff --git a/src/main/java/net/minestom/server/entity/GameMode.java b/src/main/java/net/minestom/server/entity/GameMode.java index a459b58dd..d7133cb24 100644 --- a/src/main/java/net/minestom/server/entity/GameMode.java +++ b/src/main/java/net/minestom/server/entity/GameMode.java @@ -1,5 +1,7 @@ package net.minestom.server.entity; +import org.jetbrains.annotations.Nullable; + /** * Represents the game mode of a player. *

@@ -33,4 +35,14 @@ public enum GameMode { public boolean canTakeDamage() { return canTakeDamage; } + + @Nullable + public static GameMode fromId(byte id) { + for (GameMode gameMode : values()) { + if (gameMode.id == id) { + return gameMode; + } + } + return null; + } } diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 23e6ab87a..991e5af41 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -57,7 +57,6 @@ import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.validate.Check; import net.minestom.server.world.DimensionType; -import net.minestom.server.world.LevelType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -93,7 +92,7 @@ public class Player extends LivingEntity implements CommandSender { protected boolean onGround; private final ConcurrentLinkedQueue packets = new ConcurrentLinkedQueue<>(); - private final LevelType levelType; + private final boolean levelFlat; private final PlayerSettings settings; private float exp; private int level; @@ -170,7 +169,7 @@ public class Player extends LivingEntity implements CommandSender { this.gameMode = GameMode.SURVIVAL; this.dimensionType = DimensionType.OVERWORLD; - this.levelType = LevelType.FLAT; + this.levelFlat = true; refreshPosition(0, 0, 0); // Used to cache the breaker for single custom block breaking @@ -194,9 +193,9 @@ public class Player extends LivingEntity implements CommandSender { joinGamePacket.gameMode = gameMode; joinGamePacket.dimensionType = dimensionType; joinGamePacket.maxPlayers = 0; // Unused - joinGamePacket.levelType = levelType; joinGamePacket.viewDistance = MinecraftServer.getChunkViewDistance(); joinGamePacket.reducedDebugInfo = false; + joinGamePacket.isFlat = levelFlat; playerConnection.sendPacket(joinGamePacket); // Server brand name @@ -507,7 +506,7 @@ public class Player extends LivingEntity implements CommandSender { RespawnPacket respawnPacket = new RespawnPacket(); respawnPacket.dimensionType = getDimensionType(); respawnPacket.gameMode = getGameMode(); - respawnPacket.levelType = getLevelType(); + respawnPacket.isFlat = levelFlat; getPlayerConnection().sendPacket(respawnPacket); PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this); callEvent(PlayerRespawnEvent.class, respawnEvent); @@ -1075,7 +1074,7 @@ public class Player extends LivingEntity implements CommandSender { RespawnPacket respawnPacket = new RespawnPacket(); respawnPacket.dimensionType = getDimensionType(); respawnPacket.gameMode = getGameMode(); - respawnPacket.levelType = getLevelType(); + respawnPacket.isFlat = levelFlat; playerConnection.sendPacket(removePlayerPacket); playerConnection.sendPacket(destroyEntitiesPacket); @@ -1513,7 +1512,7 @@ public class Player extends LivingEntity implements CommandSender { RespawnPacket respawnPacket = new RespawnPacket(); respawnPacket.dimensionType = dimensionType; respawnPacket.gameMode = gameMode; - respawnPacket.levelType = levelType; + respawnPacket.isFlat = levelFlat; playerConnection.sendPacket(respawnPacket); } @@ -1539,10 +1538,6 @@ public class Player extends LivingEntity implements CommandSender { kick(ColoredText.of(message)); } - public LevelType getLevelType() { - return levelType; - } - /** * Changes the current held slot for the player. * diff --git a/src/main/java/net/minestom/server/instance/block/CustomBlock.java b/src/main/java/net/minestom/server/instance/block/CustomBlock.java index cfe2acdbf..377729af9 100644 --- a/src/main/java/net/minestom/server/instance/block/CustomBlock.java +++ b/src/main/java/net/minestom/server/instance/block/CustomBlock.java @@ -29,6 +29,10 @@ import java.util.Set; * There should be only one instance of this class for each custom block type, * every individual blocks will execute the callbacks present there. Each of which contains the * custom block position and the instance concerned. + *

+ * Each block in a chunk contains 2 id, the block state id (only visual) and a custom block id corresponding to + * {@link CustomBlock#getCustomBlockId()}. A custom block is responsible for the blocks tick, the custom break time feature, + * and some useful callbacks. */ public abstract class CustomBlock { diff --git a/src/main/java/net/minestom/server/network/packet/server/ServerPacket.java b/src/main/java/net/minestom/server/network/packet/server/ServerPacket.java index 3d13b29d2..a4cdb19d5 100644 --- a/src/main/java/net/minestom/server/network/packet/server/ServerPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/ServerPacket.java @@ -2,18 +2,20 @@ package net.minestom.server.network.packet.server; import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.utils.binary.BinaryWriter; +import net.minestom.server.utils.binary.Writeable; +import org.jetbrains.annotations.NotNull; /** * Represents a packet which can be sent to a player using {@link PlayerConnection#sendPacket(ServerPacket)}. */ -public interface ServerPacket { +public interface ServerPacket extends Writeable { /** * Writes the packet to a {@link BinaryWriter}. * * @param writer the writer to write the packet to. */ - void write(BinaryWriter writer); + void write(@NotNull BinaryWriter writer); /** * Gets the id of this packet. diff --git a/src/main/java/net/minestom/server/network/packet/server/handshake/ResponsePacket.java b/src/main/java/net/minestom/server/network/packet/server/handshake/ResponsePacket.java index 8b06dd1ea..2e5dfba81 100644 --- a/src/main/java/net/minestom/server/network/packet/server/handshake/ResponsePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/handshake/ResponsePacket.java @@ -2,13 +2,14 @@ package net.minestom.server.network.packet.server.handshake; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ResponsePacket implements ServerPacket { public String jsonResponse; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(jsonResponse); } diff --git a/src/main/java/net/minestom/server/network/packet/server/login/EncryptionRequestPacket.java b/src/main/java/net/minestom/server/network/packet/server/login/EncryptionRequestPacket.java index 1788e1ea7..f3d5da982 100644 --- a/src/main/java/net/minestom/server/network/packet/server/login/EncryptionRequestPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/login/EncryptionRequestPacket.java @@ -5,12 +5,14 @@ import net.minestom.server.data.type.array.ByteArrayData; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.concurrent.ThreadLocalRandom; public class EncryptionRequestPacket implements ServerPacket { - private byte[] nonce = new byte[4]; + public byte[] publicKey; + public byte[] nonce = new byte[4]; public EncryptionRequestPacket(PlayerConnection connection) { ThreadLocalRandom.current().nextBytes(nonce); @@ -18,9 +20,9 @@ public class EncryptionRequestPacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(""); - byte[] publicKey = MinecraftServer.getKeyPair().getPublic().getEncoded(); + final byte[] publicKey = MinecraftServer.getKeyPair().getPublic().getEncoded(); ByteArrayData.encodeByteArray(writer, publicKey); ByteArrayData.encodeByteArray(writer, nonce); } diff --git a/src/main/java/net/minestom/server/network/packet/server/login/JoinGamePacket.java b/src/main/java/net/minestom/server/network/packet/server/login/JoinGamePacket.java index 575e9597b..46191b208 100644 --- a/src/main/java/net/minestom/server/network/packet/server/login/JoinGamePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/login/JoinGamePacket.java @@ -6,7 +6,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.world.DimensionType; -import net.minestom.server.world.LevelType; +import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBTCompound; public class JoinGamePacket implements ServerPacket { @@ -15,14 +15,15 @@ public class JoinGamePacket implements ServerPacket { public GameMode gameMode = GameMode.SURVIVAL; public DimensionType dimensionType = DimensionType.OVERWORLD; public long hashedSeed; - public byte maxPlayers = 0; // Unused - public LevelType levelType; + public int maxPlayers = 0; // Unused public int viewDistance; public boolean reducedDebugInfo = false; public boolean enableRespawnScreen = true; + public boolean isDebug = false; + public boolean isFlat = false; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeInt(entityId); writer.writeBoolean(MinecraftServer.isHardcoreLook()); writer.writeByte(gameMode.getId()); @@ -49,9 +50,9 @@ public class JoinGamePacket implements ServerPacket { writer.writeBoolean(reducedDebugInfo); writer.writeBoolean(enableRespawnScreen); //debug - writer.writeBoolean(false); + writer.writeBoolean(isDebug); //is flat - writer.writeBoolean(levelType == LevelType.FLAT); + writer.writeBoolean(isFlat); } @Override diff --git a/src/main/java/net/minestom/server/network/packet/server/login/LoginDisconnect.java b/src/main/java/net/minestom/server/network/packet/server/login/LoginDisconnect.java index 9d5a99f9c..c1e5d3272 100644 --- a/src/main/java/net/minestom/server/network/packet/server/login/LoginDisconnect.java +++ b/src/main/java/net/minestom/server/network/packet/server/login/LoginDisconnect.java @@ -2,6 +2,7 @@ package net.minestom.server.network.packet.server.login; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class LoginDisconnect implements ServerPacket { @@ -12,7 +13,7 @@ public class LoginDisconnect implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(kickMessage); } diff --git a/src/main/java/net/minestom/server/network/packet/server/login/LoginSuccessPacket.java b/src/main/java/net/minestom/server/network/packet/server/login/LoginSuccessPacket.java index 67d79bd2b..b48b936cc 100644 --- a/src/main/java/net/minestom/server/network/packet/server/login/LoginSuccessPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/login/LoginSuccessPacket.java @@ -2,6 +2,7 @@ package net.minestom.server.network.packet.server.login; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -16,7 +17,7 @@ public class LoginSuccessPacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeUuid(uuid); writer.writeSizedString(username); } diff --git a/src/main/java/net/minestom/server/network/packet/server/login/SetCompressionPacket.java b/src/main/java/net/minestom/server/network/packet/server/login/SetCompressionPacket.java index 4088dc234..88fb49cb9 100644 --- a/src/main/java/net/minestom/server/network/packet/server/login/SetCompressionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/login/SetCompressionPacket.java @@ -2,6 +2,7 @@ package net.minestom.server.network.packet.server.login; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class SetCompressionPacket implements ServerPacket { @@ -12,7 +13,7 @@ public class SetCompressionPacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(threshold); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/AcknowledgePlayerDiggingPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/AcknowledgePlayerDiggingPacket.java index adff1382f..b8d500391 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/AcknowledgePlayerDiggingPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/AcknowledgePlayerDiggingPacket.java @@ -5,6 +5,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class AcknowledgePlayerDiggingPacket implements ServerPacket { @@ -14,7 +15,7 @@ public class AcknowledgePlayerDiggingPacket implements ServerPacket { public boolean successful; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeBlockPosition(blockPosition); writer.writeVarInt(blockStateId); writer.writeVarInt(status.ordinal()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java index 684daf575..06385aa31 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java @@ -6,6 +6,8 @@ import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import net.minestom.server.utils.binary.Writeable; +import org.jetbrains.annotations.NotNull; public class AdvancementsPacket implements ServerPacket { @@ -15,7 +17,7 @@ public class AdvancementsPacket implements ServerPacket { public ProgressMapping[] progressMappings; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeBoolean(resetAdvancements); writer.writeVarInt(advancementMappings.length); @@ -38,25 +40,27 @@ public class AdvancementsPacket implements ServerPacket { /** * AdvancementMapping maps the namespaced ID to the Advancement. */ - public static class AdvancementMapping { + public static class AdvancementMapping implements Writeable { public String key; public Advancement value; - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { writer.writeSizedString(key); value.write(writer); } } - public static class Advancement { + public static class Advancement implements Writeable { public String parentIdentifier; public DisplayData displayData; public String[] criterions; public Requirement[] requirements; - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { // hasParent writer.writeBoolean(parentIdentifier != null); if (parentIdentifier != null) { @@ -79,7 +83,7 @@ public class AdvancementsPacket implements ServerPacket { } } - public static class DisplayData { + public static class DisplayData implements Writeable { public JsonMessage title; // Only text public JsonMessage description; // Only text public ItemStack icon; @@ -89,7 +93,8 @@ public class AdvancementsPacket implements ServerPacket { public float x; public float y; - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { writer.writeSizedString(title.toString()); writer.writeSizedString(description.toString()); writer.writeItemStack(icon); @@ -104,11 +109,12 @@ public class AdvancementsPacket implements ServerPacket { } - public static class Requirement { + public static class Requirement implements Writeable { public String[] requirements; - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { writer.writeVarInt(requirements.length); for (String requirement : requirements) { writer.writeSizedString(requirement); @@ -116,20 +122,22 @@ public class AdvancementsPacket implements ServerPacket { } } - public static class ProgressMapping { + public static class ProgressMapping implements Writeable { public String key; public AdvancementProgress value; - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { writer.writeSizedString(key); value.write(writer); } } - public static class AdvancementProgress { + public static class AdvancementProgress implements Writeable { public Criteria[] criteria; - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { writer.writeVarInt(criteria.length); for (Criteria criterion : criteria) { criterion.write(writer); @@ -137,21 +145,24 @@ public class AdvancementsPacket implements ServerPacket { } } - public static class Criteria { + public static class Criteria implements Writeable { public String criterionIdentifier; public CriterionProgress criterionProgress; - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { writer.writeSizedString(criterionIdentifier); criterionProgress.write(writer); } + } - public static class CriterionProgress { + public static class CriterionProgress implements Writeable { public boolean achieved; public long dateOfAchieving; - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { writer.writeBoolean(achieved); if (dateOfAchieving != 0) writer.writeLong(dateOfAchieving); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/AttachEntityPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/AttachEntityPacket.java index 7813b7713..ee219d479 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/AttachEntityPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/AttachEntityPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class AttachEntityPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class AttachEntityPacket implements ServerPacket { public int holdingEntityId; // Or -1 to detach @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeInt(attachedEntityId); writer.writeInt(holdingEntityId); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/BlockActionPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/BlockActionPacket.java index 4d9571e1b..5254db825 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/BlockActionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/BlockActionPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class BlockActionPacket implements ServerPacket { @@ -13,7 +14,7 @@ public class BlockActionPacket implements ServerPacket { public int blockId; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeBlockPosition(blockPosition); writer.writeByte(actionId); writer.writeByte(actionParam); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/BlockBreakAnimationPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/BlockBreakAnimationPacket.java index b35efc440..6f98c1a52 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/BlockBreakAnimationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/BlockBreakAnimationPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class BlockBreakAnimationPacket implements ServerPacket { @@ -22,7 +23,7 @@ public class BlockBreakAnimationPacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeBlockPosition(blockPosition); writer.writeByte(destroyStage); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/BlockChangePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/BlockChangePacket.java index d31caaade..7672375f0 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/BlockChangePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/BlockChangePacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class BlockChangePacket implements ServerPacket { @@ -11,7 +12,7 @@ public class BlockChangePacket implements ServerPacket { public int blockStateId; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeBlockPosition(blockPosition); writer.writeVarInt(blockStateId); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/BossBarPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/BossBarPacket.java index b099cf355..cf14956a8 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/BossBarPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/BossBarPacket.java @@ -6,6 +6,7 @@ import net.minestom.server.chat.JsonMessage; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -22,7 +23,7 @@ public class BossBarPacket implements ServerPacket { @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeUuid(uuid); writer.writeVarInt(action.ordinal()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/CameraPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/CameraPacket.java index 8d579a805..6d76b210a 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/CameraPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/CameraPacket.java @@ -3,13 +3,14 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class CameraPacket implements ServerPacket { public int cameraId; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(cameraId); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ChangeGameStatePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ChangeGameStatePacket.java index dbdd8eda1..9e4f00f6a 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ChangeGameStatePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ChangeGameStatePacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ChangeGameStatePacket implements ServerPacket { @@ -10,7 +11,7 @@ public class ChangeGameStatePacket implements ServerPacket { public float value; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte((byte) reason.ordinal()); writer.writeFloat(value); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ChatMessagePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ChatMessagePacket.java index d2b196bf2..02d096e76 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ChatMessagePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ChatMessagePacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -23,7 +24,7 @@ public class ChatMessagePacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(jsonMessage); writer.writeByte((byte) position.ordinal()); writer.writeUuid(uuid); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java index 3d0e7e231..d16aa6499 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java @@ -15,6 +15,7 @@ import net.minestom.server.utils.Utils; import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.world.biomes.Biome; +import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBTCompound; import java.util.Set; @@ -41,7 +42,7 @@ public class ChunkDataPacket implements ServerPacket { private static final int MAX_BUFFER_SIZE = (Short.BYTES + Byte.BYTES + 5 * Byte.BYTES + (4096 * BITS_PER_ENTRY / Long.SIZE * Long.BYTES)) * CHUNK_SECTION_COUNT + 256 * Integer.BYTES; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeInt(chunkX); writer.writeInt(chunkZ); writer.writeBoolean(fullChunk); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/CloseWindowPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/CloseWindowPacket.java index b9e0c7f2a..17db19d12 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/CloseWindowPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/CloseWindowPacket.java @@ -3,13 +3,14 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class CloseWindowPacket implements ServerPacket { public byte windowId; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/CollectItemPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/CollectItemPacket.java index 60150045d..767ed5ab2 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/CollectItemPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/CollectItemPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class CollectItemPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class CollectItemPacket implements ServerPacket { public int pickupItemCount; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(collectedEntityId); writer.writeVarInt(collectorEntityId); writer.writeVarInt(pickupItemCount); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/CombatEventPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/CombatEventPacket.java index 7f91ed9d4..685a2ad1c 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/CombatEventPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/CombatEventPacket.java @@ -6,6 +6,7 @@ import net.minestom.server.entity.Player; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.Optional; @@ -48,7 +49,7 @@ public class CombatEventPacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(type.ordinal()); switch (type) { case ENTER_COMBAT: diff --git a/src/main/java/net/minestom/server/network/packet/server/play/CraftRecipeResponse.java b/src/main/java/net/minestom/server/network/packet/server/play/CraftRecipeResponse.java index 589b2663e..6e77cfee3 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/CraftRecipeResponse.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/CraftRecipeResponse.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class CraftRecipeResponse implements ServerPacket { @@ -10,7 +11,7 @@ public class CraftRecipeResponse implements ServerPacket { public String recipe; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); writer.writeSizedString(recipe); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DeclareCommandsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DeclareCommandsPacket.java index ca5558ecf..97b7e5207 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DeclareCommandsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DeclareCommandsPacket.java @@ -3,17 +3,18 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import net.minestom.server.utils.binary.Writeable; +import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; public class DeclareCommandsPacket implements ServerPacket { - public Node[] nodes; public int rootIndex; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(nodes.length); for (Node node : nodes) { node.write(writer); @@ -26,7 +27,7 @@ public class DeclareCommandsPacket implements ServerPacket { return ServerPacketIdentifier.DECLARE_COMMANDS; } - public static class Node { + public static class Node implements Writeable { public byte flags; public int[] children; @@ -36,7 +37,8 @@ public class DeclareCommandsPacket implements ServerPacket { public Consumer properties; // Only for argument public String suggestionsType; // Only if flags 0x10 - private void write(BinaryWriter writer) { + @Override + public void write(BinaryWriter writer) { writer.writeByte(flags); writer.writeVarIntArray(children); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DeclareRecipesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DeclareRecipesPacket.java index cdb2f43f7..bb74e5d0d 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DeclareRecipesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DeclareRecipesPacket.java @@ -12,7 +12,7 @@ public class DeclareRecipesPacket implements ServerPacket { public DeclaredRecipe[] recipes; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { Check.notNull(recipes, "Recipes cannot be null!"); writer.writeVarInt(recipes.length); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DestroyEntitiesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DestroyEntitiesPacket.java index 167c3ffe9..cedae16f5 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DestroyEntitiesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DestroyEntitiesPacket.java @@ -3,13 +3,14 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class DestroyEntitiesPacket implements ServerPacket { public int[] entityIds; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarIntArray(entityIds); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DisconnectPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DisconnectPacket.java index 890e2fa39..94060a6f1 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DisconnectPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DisconnectPacket.java @@ -4,13 +4,14 @@ import net.minestom.server.chat.JsonMessage; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class DisconnectPacket implements ServerPacket { public JsonMessage message; // Only text @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(message.toString()); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DisplayScoreboardPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DisplayScoreboardPacket.java index 491d21c78..a1f25ad05 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DisplayScoreboardPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DisplayScoreboardPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class DisplayScoreboardPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class DisplayScoreboardPacket implements ServerPacket { public String scoreName; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(position); writer.writeSizedString(scoreName); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EffectPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EffectPacket.java index 7b8be55de..b17b71c1c 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EffectPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EffectPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EffectPacket implements ServerPacket { @@ -13,7 +14,7 @@ public class EffectPacket implements ServerPacket { public boolean disableRelativeVolume; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeInt(effectId); writer.writeBlockPosition(position); writer.writeInt(data); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityAnimationPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityAnimationPacket.java index 0f8b52ae3..b90bd9ee8 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityAnimationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityAnimationPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityAnimationPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class EntityAnimationPacket implements ServerPacket { public Animation animation; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeByte((byte) animation.ordinal()); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityEffectPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityEffectPacket.java index a236b6659..596faced4 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityEffectPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityEffectPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.potion.PotionEffect; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityEffectPacket implements ServerPacket { @@ -14,7 +15,7 @@ public class EntityEffectPacket implements ServerPacket { public byte flags; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeByte((byte) effect.getId()); writer.writeByte(amplifier); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityEquipmentPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityEquipmentPacket.java index 52ea68526..e03f7e47c 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityEquipmentPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityEquipmentPacket.java @@ -5,6 +5,7 @@ import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityEquipmentPacket implements ServerPacket { @@ -13,7 +14,7 @@ public class EntityEquipmentPacket implements ServerPacket { public ItemStack[] itemStacks; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); if (slots == null || itemStacks == null) { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityHeadLookPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityHeadLookPacket.java index f42652888..aaff5f560 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityHeadLookPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityHeadLookPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityHeadLookPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class EntityHeadLookPacket implements ServerPacket { public float yaw; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeByte((byte) (this.yaw * 256 / 360)); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityMetaDataPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityMetaDataPacket.java index 732d6595d..76953f8f2 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityMetaDataPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityMetaDataPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; @@ -12,7 +13,7 @@ public class EntityMetaDataPacket implements ServerPacket { public Consumer consumer; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.write(consumer); writer.writeByte((byte) 0xFF); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityPacket.java index 6a4f02ad9..6c4d076ee 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityPacket.java @@ -3,13 +3,14 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityPacket implements ServerPacket { public int entityId; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityPositionAndRotationPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityPositionAndRotationPacket.java index 0f0f208df..7757b5232 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityPositionAndRotationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityPositionAndRotationPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityPositionAndRotationPacket implements ServerPacket { @@ -12,7 +13,7 @@ public class EntityPositionAndRotationPacket implements ServerPacket { public boolean onGround; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeShort(deltaX); writer.writeShort(deltaY); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityPositionPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityPositionPacket.java index 7819c36b5..cf5eeff3a 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityPositionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityPositionPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityPositionPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class EntityPositionPacket implements ServerPacket { public boolean onGround; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeShort(deltaX); writer.writeShort(deltaY); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityPropertiesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityPropertiesPacket.java index e2bbe2297..3f3a3347a 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityPropertiesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityPropertiesPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.attribute.Attribute; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityPropertiesPacket implements ServerPacket { @@ -12,7 +13,7 @@ public class EntityPropertiesPacket implements ServerPacket { @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeInt(properties.length); for (Property property : properties) { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityRotationPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityRotationPacket.java index 1992e0c38..a4f56972a 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityRotationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityRotationPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityRotationPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class EntityRotationPacket implements ServerPacket { public boolean onGround; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeByte((byte) (yaw * 256 / 360)); writer.writeByte((byte) (pitch * 256 / 360)); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntitySoundEffect.java b/src/main/java/net/minestom/server/network/packet/server/play/EntitySoundEffect.java index 58f6b1c70..254b2ac02 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntitySoundEffect.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntitySoundEffect.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.sound.SoundCategory; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntitySoundEffect implements ServerPacket { @@ -14,7 +15,7 @@ public class EntitySoundEffect implements ServerPacket { public float pitch; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(soundId); writer.writeVarInt(soundCategory.ordinal()); writer.writeVarInt(entityId); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityStatusPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityStatusPacket.java index c2569b39b..fecc38986 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityStatusPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityStatusPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityStatusPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class EntityStatusPacket implements ServerPacket { public byte status; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeInt(entityId); writer.writeByte(status); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityTeleportPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityTeleportPacket.java index a68984f7f..6cf90eab7 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityTeleportPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityTeleportPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.Position; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityTeleportPacket implements ServerPacket { @@ -12,7 +13,7 @@ public class EntityTeleportPacket implements ServerPacket { public boolean onGround; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeDouble(position.getX()); writer.writeDouble(position.getY()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/EntityVelocityPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/EntityVelocityPacket.java index 1f45c26c6..c1e828330 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/EntityVelocityPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/EntityVelocityPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class EntityVelocityPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class EntityVelocityPacket implements ServerPacket { public short velocityX, velocityY, velocityZ; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeShort(velocityX); writer.writeShort(velocityY); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ExplosionPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ExplosionPacket.java index 056c80804..05a458ba6 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ExplosionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ExplosionPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ExplosionPacket implements ServerPacket { @@ -12,7 +13,7 @@ public class ExplosionPacket implements ServerPacket { public float playerMotionX, playerMotionY, playerMotionZ; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeFloat(x); writer.writeFloat(y); writer.writeFloat(z); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/FacePlayerPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/FacePlayerPacket.java index 7efe9caac..28a1ca40b 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/FacePlayerPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/FacePlayerPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class FacePlayerPacket implements ServerPacket { @@ -13,7 +14,7 @@ public class FacePlayerPacket implements ServerPacket { @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(facePosition.ordinal()); writer.writeDouble(targetX); writer.writeDouble(targetY); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/HeldItemChangePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/HeldItemChangePacket.java index ce4b7225a..cf0ee41c4 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/HeldItemChangePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/HeldItemChangePacket.java @@ -3,13 +3,14 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class HeldItemChangePacket implements ServerPacket { public byte slot; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(slot); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/KeepAlivePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/KeepAlivePacket.java index 2b1e70f0d..2efe8c1f9 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/KeepAlivePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/KeepAlivePacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class KeepAlivePacket implements ServerPacket { @@ -13,7 +14,7 @@ public class KeepAlivePacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeLong(id); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/MapDataPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/MapDataPacket.java index 7efb2b0f4..1a3a8ac0a 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/MapDataPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/MapDataPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.chat.JsonMessage; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class MapDataPacket implements ServerPacket { @@ -21,7 +22,7 @@ public class MapDataPacket implements ServerPacket { public byte[] data; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(mapId); writer.writeByte(scale); writer.writeBoolean(trackingPosition); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/MultiBlockChangePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/MultiBlockChangePacket.java index b54e1159e..7eea865fb 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/MultiBlockChangePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/MultiBlockChangePacket.java @@ -5,6 +5,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.chunk.ChunkUtils; +import org.jetbrains.annotations.NotNull; public class MultiBlockChangePacket implements ServerPacket { @@ -16,7 +17,7 @@ public class MultiBlockChangePacket implements ServerPacket { public BlockChange[] blockChanges; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeLong(ChunkUtils.getChunkIndexWithSection(chunkX, chunkZ, section)); writer.writeBoolean(suppressLightUpdates); if (blockChanges != null) { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/NamedSoundEffectPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/NamedSoundEffectPacket.java index 644b035db..f41d8d21b 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/NamedSoundEffectPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/NamedSoundEffectPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.sound.SoundCategory; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class NamedSoundEffectPacket implements ServerPacket { @@ -14,7 +15,7 @@ public class NamedSoundEffectPacket implements ServerPacket { public float pitch; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(soundName); writer.writeVarInt(soundCategory.ordinal()); writer.writeInt(x); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/OpenBookPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/OpenBookPacket.java index 88c9f0b54..5ac2c88c9 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/OpenBookPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/OpenBookPacket.java @@ -4,13 +4,14 @@ import net.minestom.server.entity.Player; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class OpenBookPacket implements ServerPacket { public Player.Hand hand; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(hand.ordinal()); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/OpenHorseWindowPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/OpenHorseWindowPacket.java index edb7fcf0c..273e83bae 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/OpenHorseWindowPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/OpenHorseWindowPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class OpenHorseWindowPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class OpenHorseWindowPacket implements ServerPacket { public int entityId; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); writer.writeVarInt(slotCount); writer.writeInt(entityId); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/OpenSignEditorPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/OpenSignEditorPacket.java index 72bd53ef1..987827801 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/OpenSignEditorPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/OpenSignEditorPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class OpenSignEditorPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class OpenSignEditorPacket implements ServerPacket { public BlockPosition signPosition; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeBlockPosition(signPosition); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/OpenWindowPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/OpenWindowPacket.java index 3ff8ab2c4..d4b3bc64b 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/OpenWindowPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/OpenWindowPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class OpenWindowPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class OpenWindowPacket implements ServerPacket { public String title; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(windowId); writer.writeVarInt(windowType); writer.writeSizedString("{\"text\": \"" + title + " \"}"); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ParticlePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ParticlePacket.java index 88c9f25b2..fc81ff460 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ParticlePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ParticlePacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; @@ -18,7 +19,7 @@ public class ParticlePacket implements ServerPacket { public Consumer dataConsumer; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeInt(particleId); writer.writeBoolean(longDistance); writer.writeDouble(x); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java index 49073eb9e..5aa879c74 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerAbilitiesPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class PlayerAbilitiesPacket implements ServerPacket { @@ -17,7 +18,7 @@ public class PlayerAbilitiesPacket implements ServerPacket { public float walkingSpeed; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { byte flags = 0; if (invulnerable) flags += 1; diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoPacket.java index 912772f4b..ca9741dd3 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerInfoPacket.java @@ -21,7 +21,7 @@ public class PlayerInfoPacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(action.ordinal()); writer.writeVarInt(playerInfos.size()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerListHeaderAndFooterPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerListHeaderAndFooterPacket.java index 9c6fdfa76..eaa406717 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerListHeaderAndFooterPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerListHeaderAndFooterPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.chat.JsonMessage; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class PlayerListHeaderAndFooterPacket implements ServerPacket { @@ -17,7 +18,7 @@ public class PlayerListHeaderAndFooterPacket implements ServerPacket { @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { if (emptyHeader) { writer.writeSizedString(EMPTY_COMPONENT); } else { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PlayerPositionAndLookPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PlayerPositionAndLookPacket.java index 490669337..97a09cf3f 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PlayerPositionAndLookPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PlayerPositionAndLookPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.Position; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class PlayerPositionAndLookPacket implements ServerPacket { @@ -13,7 +14,7 @@ public class PlayerPositionAndLookPacket implements ServerPacket { @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeDouble(position.getX()); writer.writeDouble(position.getY()); writer.writeDouble(position.getZ()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/PluginMessagePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/PluginMessagePacket.java index 1483d54d9..2d1af7f14 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/PluginMessagePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/PluginMessagePacket.java @@ -4,6 +4,7 @@ import net.minestom.server.MinecraftServer; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class PluginMessagePacket implements ServerPacket { @@ -11,7 +12,7 @@ public class PluginMessagePacket implements ServerPacket { public byte[] data; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(channel); writer.writeBytes(data); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/RemoveEntityEffectPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/RemoveEntityEffectPacket.java index 2cf6a382f..ad7283df7 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/RemoveEntityEffectPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/RemoveEntityEffectPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.potion.PotionEffect; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class RemoveEntityEffectPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class RemoveEntityEffectPacket implements ServerPacket { public PotionEffect effect; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeByte((byte) effect.getId()); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ResourcePackSendPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ResourcePackSendPacket.java index 5f4e620b1..574f415a0 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ResourcePackSendPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ResourcePackSendPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ResourcePackSendPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class ResourcePackSendPacket implements ServerPacket { public String hash; // Size 40 @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(url); writer.writeSizedString(hash); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/RespawnPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/RespawnPacket.java index 6e4e089e1..b464cdd4a 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/RespawnPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/RespawnPacket.java @@ -5,17 +5,19 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.world.DimensionType; -import net.minestom.server.world.LevelType; +import org.jetbrains.annotations.NotNull; public class RespawnPacket implements ServerPacket { public DimensionType dimensionType; public long hashedSeed; public GameMode gameMode; - public LevelType levelType; + public boolean isDebug = false; + public boolean isFlat = true; + public boolean copyMeta = true; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { //TODO add api writer.writeNBT("", dimensionType.toNBT()); @@ -25,12 +27,9 @@ public class RespawnPacket implements ServerPacket { writer.writeLong(hashedSeed); writer.writeByte(gameMode.getId()); writer.writeByte(gameMode.getId()); // Hardcore flag not included - //debug - writer.writeBoolean(false); - //is flat - writer.writeBoolean(true); - //copy meta - writer.writeBoolean(true); + writer.writeBoolean(isDebug); + writer.writeBoolean(isFlat); + writer.writeBoolean(copyMeta); } @Override diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java index 0e20089b0..c7750df91 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java @@ -4,6 +4,7 @@ import net.minestom.server.chat.JsonMessage; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ScoreboardObjectivePacket implements ServerPacket { @@ -27,7 +28,7 @@ public class ScoreboardObjectivePacket implements ServerPacket { public Type type; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(objectiveName); writer.writeByte(mode); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ServerDifficultyPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ServerDifficultyPacket.java index 36de5506f..db2d70d45 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ServerDifficultyPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ServerDifficultyPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.world.Difficulty; +import org.jetbrains.annotations.NotNull; public class ServerDifficultyPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class ServerDifficultyPacket implements ServerPacket { public boolean locked; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte((byte) difficulty.ordinal()); writer.writeBoolean(locked); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SetCooldownPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SetCooldownPacket.java index f742de589..b0e84393d 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SetCooldownPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SetCooldownPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class SetCooldownPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class SetCooldownPacket implements ServerPacket { public int cooldownTicks; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(itemId); writer.writeVarInt(cooldownTicks); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SetExperiencePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SetExperiencePacket.java index 78e51d430..97e94c412 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SetExperiencePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SetExperiencePacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class SetExperiencePacket implements ServerPacket { @@ -11,7 +12,7 @@ public class SetExperiencePacket implements ServerPacket { public int totalExperience; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeFloat(percentage); writer.writeVarInt(level); writer.writeVarInt(totalExperience); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SetPassengersPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SetPassengersPacket.java index e0ee017de..129828cec 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SetPassengersPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SetPassengersPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class SetPassengersPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class SetPassengersPacket implements ServerPacket { public int[] passengersId; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(vehicleEntityId); writer.writeVarIntArray(passengersId); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SetSlotPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SetSlotPacket.java index aad49ecbd..aef5e4947 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SetSlotPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SetSlotPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class SetSlotPacket implements ServerPacket { @@ -12,7 +13,7 @@ public class SetSlotPacket implements ServerPacket { public ItemStack itemStack; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); writer.writeShort(slot); writer.writeItemStack(itemStack); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SoundEffectPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SoundEffectPacket.java index 7dfb7d1cb..c232e06d5 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SoundEffectPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SoundEffectPacket.java @@ -5,6 +5,7 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundCategory; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class SoundEffectPacket implements ServerPacket { @@ -28,7 +29,7 @@ public class SoundEffectPacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(soundId); writer.writeVarInt(soundCategory.ordinal()); writer.writeInt(x); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SpawnEntityPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SpawnEntityPacket.java index b54f92259..87a1cfa40 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SpawnEntityPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SpawnEntityPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.Position; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -17,7 +18,7 @@ public class SpawnEntityPacket implements ServerPacket { public short velocityX, velocityY, velocityZ; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeUuid(uuid); writer.writeVarInt(type); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SpawnExperienceOrbPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SpawnExperienceOrbPacket.java index e708c9c6b..59b2cb3f2 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SpawnExperienceOrbPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SpawnExperienceOrbPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.Position; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class SpawnExperienceOrbPacket implements ServerPacket { @@ -12,7 +13,7 @@ public class SpawnExperienceOrbPacket implements ServerPacket { public short expCount; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeDouble(position.getX()); writer.writeDouble(position.getY()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SpawnLivingEntityPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SpawnLivingEntityPacket.java index be8e6b0f0..790d27849 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SpawnLivingEntityPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SpawnLivingEntityPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.Position; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -17,7 +18,7 @@ public class SpawnLivingEntityPacket implements ServerPacket { public short velocityX, velocityY, velocityZ; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeUuid(entityUuid); writer.writeVarInt(entityType); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SpawnPaintingPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SpawnPaintingPacket.java index 00392b3f4..89c1c7706 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SpawnPaintingPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SpawnPaintingPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -16,7 +17,7 @@ public class SpawnPaintingPacket implements ServerPacket { public byte direction; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeUuid(entityUuid); writer.writeVarInt(motive); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SpawnPlayerPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SpawnPlayerPacket.java index b3e8bdba1..d0612b5d4 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SpawnPlayerPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SpawnPlayerPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.Position; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -14,7 +15,7 @@ public class SpawnPlayerPacket implements ServerPacket { public Position position; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeUuid(playerUuid); writer.writeDouble(position.getX()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SpawnPositionPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SpawnPositionPacket.java index f5b648baa..0c050a207 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SpawnPositionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SpawnPositionPacket.java @@ -3,13 +3,14 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class SpawnPositionPacket implements ServerPacket { public int x, y, z; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeBlockPosition(x, y, z); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/StatisticsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/StatisticsPacket.java index 3db1b71a2..db2b6af56 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/StatisticsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/StatisticsPacket.java @@ -4,13 +4,14 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.stat.StatisticCategory; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class StatisticsPacket implements ServerPacket { public Statistic[] statistics; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(statistics.length); for (Statistic statistic : statistics) { statistic.write(writer); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/StopSoundPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/StopSoundPacket.java index 7c1fb88ca..5a6bd2b92 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/StopSoundPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/StopSoundPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class StopSoundPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class StopSoundPacket implements ServerPacket { public String sound; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(flags); if (flags == 3 || flags == 1) writer.writeVarInt(source); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/TabCompletePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/TabCompletePacket.java index 4778d915b..1fdb12d12 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/TabCompletePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/TabCompletePacket.java @@ -4,6 +4,7 @@ import net.minestom.server.chat.JsonMessage; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class TabCompletePacket implements ServerPacket { @@ -13,7 +14,7 @@ public class TabCompletePacket implements ServerPacket { public Match[] matches; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(transactionId); writer.writeVarInt(start); writer.writeVarInt(length); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/TagsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/TagsPacket.java index 07427ea82..ffc1ed317 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/TagsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/TagsPacket.java @@ -6,6 +6,7 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.registry.Registries; import net.minestom.server.utils.NamespaceID; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.LinkedList; import java.util.List; @@ -20,7 +21,7 @@ public class TagsPacket implements ServerPacket { public List entityTags = new LinkedList<>(); @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writeTags(writer, blockTags, name -> Registries.getBlock(name).ordinal()); writeTags(writer, itemTags, name -> Registries.getMaterial(name).ordinal()); writeTags(writer, fluidTags, name -> Registries.getFluid(name).ordinal()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/TeamsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/TeamsPacket.java index 31aa23a1d..9b3189cb3 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/TeamsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/TeamsPacket.java @@ -58,7 +58,7 @@ public class TeamsPacket implements ServerPacket { * @param writer The writer to writes */ @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(this.teamName); writer.writeByte((byte) this.action.ordinal()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/TimeUpdatePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/TimeUpdatePacket.java index 82c11adf5..9b6c98622 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/TimeUpdatePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/TimeUpdatePacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class TimeUpdatePacket implements ServerPacket { @@ -10,7 +11,7 @@ public class TimeUpdatePacket implements ServerPacket { public long timeOfDay; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeLong(worldAge); writer.writeLong(timeOfDay); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/TitlePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/TitlePacket.java index 4a216bdc9..2a54e9770 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/TitlePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/TitlePacket.java @@ -4,6 +4,7 @@ import net.minestom.server.chat.JsonMessage; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class TitlePacket implements ServerPacket { @@ -20,7 +21,7 @@ public class TitlePacket implements ServerPacket { public int fadeOut; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(action.ordinal()); switch (action) { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/TradeListPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/TradeListPacket.java index bbfaf1c23..f921563dd 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/TradeListPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/TradeListPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class TradeListPacket implements ServerPacket { @@ -15,7 +16,7 @@ public class TradeListPacket implements ServerPacket { public boolean canRestock; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(windowId); writer.writeByte((byte) trades.length); for (Trade trade : trades) { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/UnloadChunkPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/UnloadChunkPacket.java index 20d91947b..79e858a5e 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/UnloadChunkPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/UnloadChunkPacket.java @@ -3,13 +3,14 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class UnloadChunkPacket implements ServerPacket { public int chunkX, chunkZ; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeInt(chunkX); writer.writeInt(chunkZ); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/UnlockRecipesPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/UnlockRecipesPacket.java index 58d466807..68f435baa 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/UnlockRecipesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/UnlockRecipesPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class UnlockRecipesPacket implements ServerPacket { @@ -19,7 +20,7 @@ public class UnlockRecipesPacket implements ServerPacket { public String[] initRecipesId; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(mode); writer.writeBoolean(craftingRecipeBookOpen); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/UpdateHealthPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/UpdateHealthPacket.java index be300bfa4..25ccde28a 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/UpdateHealthPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/UpdateHealthPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class UpdateHealthPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class UpdateHealthPacket implements ServerPacket { public float foodSaturation; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeFloat(health); writer.writeVarInt(food); writer.writeFloat(foodSaturation); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/UpdateLightPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/UpdateLightPacket.java index c16935752..6647d99ae 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/UpdateLightPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/UpdateLightPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -23,7 +24,7 @@ public class UpdateLightPacket implements ServerPacket { public List blockLight; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(chunkX); writer.writeVarInt(chunkZ); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/UpdateScorePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/UpdateScorePacket.java index c59600f99..2140e37a0 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/UpdateScorePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/UpdateScorePacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class UpdateScorePacket implements ServerPacket { @@ -12,7 +13,7 @@ public class UpdateScorePacket implements ServerPacket { public int value; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeSizedString(entityName); writer.writeByte(action); writer.writeSizedString(objectiveName); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/UpdateViewPositionPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/UpdateViewPositionPacket.java index f13c1d65f..14204bac5 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/UpdateViewPositionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/UpdateViewPositionPacket.java @@ -3,13 +3,14 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class UpdateViewPositionPacket implements ServerPacket { public int chunkX, chunkZ; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(chunkX); writer.writeVarInt(chunkZ); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/VehicleMovePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/VehicleMovePacket.java index f84128e2e..4b886ac1b 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/VehicleMovePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/VehicleMovePacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class VehicleMovePacket implements ServerPacket { @@ -10,7 +11,7 @@ public class VehicleMovePacket implements ServerPacket { public float yaw, pitch; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeDouble(x); writer.writeDouble(y); writer.writeDouble(z); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/WindowConfirmationPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/WindowConfirmationPacket.java index e342143af..5bad0d5bc 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/WindowConfirmationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/WindowConfirmationPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class WindowConfirmationPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class WindowConfirmationPacket implements ServerPacket { public boolean accepted; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); writer.writeShort(actionNumber); writer.writeBoolean(accepted); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java index 866e0b00f..4ba690fd1 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java @@ -4,6 +4,7 @@ import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class WindowItemsPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class WindowItemsPacket implements ServerPacket { public ItemStack[] items; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); if (items == null) { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/WindowPropertyPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/WindowPropertyPacket.java index 15cb21d48..261ed1db8 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/WindowPropertyPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/WindowPropertyPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class WindowPropertyPacket implements ServerPacket { @@ -11,7 +12,7 @@ public class WindowPropertyPacket implements ServerPacket { public short value; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); writer.writeShort(property); writer.writeShort(value); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/WorldBorderPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/WorldBorderPacket.java index 88c48aacb..059110667 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/WorldBorderPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/WorldBorderPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class WorldBorderPacket implements ServerPacket { @@ -10,7 +11,7 @@ public class WorldBorderPacket implements ServerPacket { public WBAction wbAction; @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeVarInt(action.ordinal()); wbAction.write(writer); } diff --git a/src/main/java/net/minestom/server/network/packet/server/status/PongPacket.java b/src/main/java/net/minestom/server/network/packet/server/status/PongPacket.java index a0cbf76c1..4d0df60a2 100644 --- a/src/main/java/net/minestom/server/network/packet/server/status/PongPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/status/PongPacket.java @@ -2,6 +2,7 @@ package net.minestom.server.network.packet.server.status; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class PongPacket implements ServerPacket { @@ -12,7 +13,7 @@ public class PongPacket implements ServerPacket { } @Override - public void write(BinaryWriter writer) { + public void write(@NotNull BinaryWriter writer) { writer.writeLong(number); } diff --git a/src/main/java/net/minestom/server/utils/binary/BinaryReader.java b/src/main/java/net/minestom/server/utils/binary/BinaryReader.java index 0c6ea3582..84a367bbc 100644 --- a/src/main/java/net/minestom/server/utils/binary/BinaryReader.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryReader.java @@ -1,7 +1,10 @@ package net.minestom.server.utils.binary; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import net.minestom.server.chat.JsonMessage; import net.minestom.server.item.ItemStack; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.NBTUtils; @@ -93,6 +96,24 @@ public class BinaryReader extends InputStream { return bytes; } + public String[] readSizedStringArray() { + final int size = readVarInt(); + String[] strings = new String[size]; + for (int i = 0; i < size; i++) { + strings[i] = readSizedString(); + } + return strings; + } + + public int[] readVarIntArray() { + final int size = readVarInt(); + int[] array = new int[size]; + for (int i = 0; i < size; i++) { + array[i] = readVarInt(); + } + return array; + } + public byte[] getRemainingBytes() { return readBytes(buffer.readableBytes()); } @@ -112,6 +133,12 @@ public class BinaryReader extends InputStream { return NBTUtils.readItemStack(this); } + public JsonMessage readJsonMessage() { + final String string = readSizedString(); + final JsonObject jsonObject = JsonParser.parseString(string).getAsJsonObject(); + return new JsonMessage.RawJsonMessage(jsonObject); + } + public ByteBuf getBuffer() { return buffer; } diff --git a/src/main/java/net/minestom/server/utils/binary/Readable.java b/src/main/java/net/minestom/server/utils/binary/Readable.java new file mode 100644 index 000000000..48fa33012 --- /dev/null +++ b/src/main/java/net/minestom/server/utils/binary/Readable.java @@ -0,0 +1,17 @@ +package net.minestom.server.utils.binary; + +import org.jetbrains.annotations.NotNull; + +/** + * Represents an element which can read from a {@link BinaryReader}. + */ +public interface Readable { + + /** + * Reads from a {@link BinaryReader}. + * + * @param reader the reader to read from + */ + void read(@NotNull BinaryReader reader); + +} diff --git a/src/main/java/net/minestom/server/utils/binary/Writeable.java b/src/main/java/net/minestom/server/utils/binary/Writeable.java new file mode 100644 index 000000000..1099b84a2 --- /dev/null +++ b/src/main/java/net/minestom/server/utils/binary/Writeable.java @@ -0,0 +1,17 @@ +package net.minestom.server.utils.binary; + +import org.jetbrains.annotations.NotNull; + +/** + * Represents an element which can write to a {@link BinaryWriter}. + */ +public interface Writeable { + + /** + * Writes into a {@link BinaryWriter}. + * + * @param writer the writer to write to + */ + void write(@NotNull BinaryWriter writer); + +} diff --git a/src/main/java/net/minestom/server/utils/callback/OptionalCallback.java b/src/main/java/net/minestom/server/utils/callback/OptionalCallback.java index 315bcc98b..ab8ff2866 100644 --- a/src/main/java/net/minestom/server/utils/callback/OptionalCallback.java +++ b/src/main/java/net/minestom/server/utils/callback/OptionalCallback.java @@ -2,6 +2,7 @@ package net.minestom.server.utils.callback; import net.minestom.server.instance.Chunk; import net.minestom.server.utils.chunk.ChunkCallback; +import org.jetbrains.annotations.Nullable; /** * Convenient class to execute callbacks which can be null. @@ -10,10 +11,10 @@ public class OptionalCallback { /** * Executes an optional {@link Runnable}. - *¬ + * * @param callback the optional runnable, can be null */ - public static void execute(Runnable callback) { + public static void execute(@Nullable Runnable callback) { if (callback != null) { callback.run(); } @@ -25,7 +26,7 @@ public class OptionalCallback { * @param callback the optional chunk callback, can be null * @param chunk the chunk to forward to the callback */ - public static void execute(ChunkCallback callback, Chunk chunk) { + public static void execute(@Nullable ChunkCallback callback, @Nullable Chunk chunk) { if (callback != null) { callback.accept(chunk); } diff --git a/src/main/java/net/minestom/server/world/LevelType.java b/src/main/java/net/minestom/server/world/LevelType.java deleted file mode 100644 index e4f39303a..000000000 --- a/src/main/java/net/minestom/server/world/LevelType.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.minestom.server.world; - -import org.jetbrains.annotations.Nullable; - -public enum LevelType { - - DEFAULT("default"), - FLAT("flat"), - LARGE_BIOMES("largeBiomes"), - AMPLIFIED("amplified"), - DEFAULT_1_1("default_1_1"); - - private final String type; - - LevelType(@Nullable String type) { - this.type = type; - } - - @Nullable - public String getType() { - return type; - } -}