From 571bb7a86694ec8f1838a1c387bb5b8d3e18b2e3 Mon Sep 17 00:00:00 2001 From: themode Date: Wed, 19 Aug 2020 20:34:21 +0200 Subject: [PATCH] Renamed PacketWriter/Reader to BinaryWriter/Reader + optimization to serializing --- src/main/java/fr/themode/demo/PlayerInit.java | 29 +++- .../themode/demo/commands/SimpleCommand.java | 2 + .../demo/generator/NoiseTestGenerator.java | 4 +- .../net/minestom/server/data/DataManager.java | 3 +- .../net/minestom/server/data/DataType.java | 14 +- .../server/data/SerializableData.java | 40 ++---- .../server/data/type/BooleanData.java | 12 +- .../minestom/server/data/type/ByteData.java | 12 +- .../server/data/type/CharacterData.java | 12 +- .../minestom/server/data/type/DoubleData.java | 12 +- .../minestom/server/data/type/FloatData.java | 12 +- .../server/data/type/IntegerData.java | 12 +- .../server/data/type/InventoryData.java | 20 +-- .../server/data/type/ItemStackData.java | 12 +- .../minestom/server/data/type/LongData.java | 12 +- .../data/type/SerializableDataData.java | 19 +-- .../minestom/server/data/type/ShortData.java | 12 +- .../minestom/server/data/type/StringData.java | 12 +- .../minestom/server/data/type/UuidType.java | 12 +- .../data/type/array/BooleanArrayData.java | 16 +-- .../server/data/type/array/ByteArrayData.java | 24 ++-- .../data/type/array/CharacterArrayData.java | 16 +-- .../data/type/array/DoubleArrayData.java | 16 +-- .../data/type/array/FloatArrayData.java | 16 +-- .../data/type/array/IntegerArrayData.java | 16 +-- .../data/type/array/ItemStackArrayData.java | 16 +-- .../server/data/type/array/LongArrayData.java | 16 +-- .../data/type/array/ShortArrayData.java | 16 +-- .../data/type/array/StringArrayData.java | 16 +-- .../net/minestom/server/entity/Entity.java | 22 +-- .../minestom/server/entity/ItemEntity.java | 6 +- .../minestom/server/entity/LivingEntity.java | 6 +- .../net/minestom/server/entity/Player.java | 8 +- .../server/entity/type/ambient/EntityBat.java | 6 +- .../entity/type/animal/EntityMooshroom.java | 6 +- .../server/entity/type/animal/EntityPig.java | 6 +- .../entity/type/animal/EntityPolarBear.java | 6 +- .../entity/type/animal/EntityRabbit.java | 6 +- .../type/decoration/EntityArmorStand.java | 6 +- .../type/decoration/EntityItemFrame.java | 6 +- .../entity/type/monster/EntityBlaze.java | 6 +- .../entity/type/monster/EntityCreeper.java | 6 +- .../entity/type/monster/EntityGhast.java | 6 +- .../entity/type/monster/EntityGuardian.java | 6 +- .../entity/type/monster/EntityPhantom.java | 6 +- .../entity/type/monster/EntitySlime.java | 6 +- .../entity/type/monster/EntitySpider.java | 6 +- .../entity/type/monster/EntityWitch.java | 6 +- .../entity/type/monster/EntityZombie.java | 6 +- .../type/monster/EntityZombifiedPiglin.java | 6 +- .../type/other/EntityAreaEffectCloud.java | 12 +- .../entity/type/other/EntityIronGolem.java | 6 +- .../entity/type/other/EntitySnowman.java | 6 +- .../type/projectile/EntityEyeOfEnder.java | 6 +- .../entity/type/projectile/EntityPotion.java | 6 +- .../entity/type/vehicle/EntityBoat.java | 6 +- .../net/minestom/server/instance/Chunk.java | 4 +- .../server/instance/DynamicChunk.java | 38 +++-- .../instance/MinestomBasicChunkLoader.java | 19 +-- .../server/network/PacketProcessor.java | 12 +- .../network/packet/client/ClientPacket.java | 4 +- .../client/handshake/HandshakePacket.java | 4 +- .../login/EncryptionResponsePacket.java | 4 +- .../packet/client/login/LoginStartPacket.java | 4 +- .../play/ClientAdvancementTabPacket.java | 4 +- .../client/play/ClientAnimationPacket.java | 4 +- .../client/play/ClientChatMessagePacket.java | 4 +- .../play/ClientClickWindowButtonPacket.java | 4 +- .../client/play/ClientClickWindowPacket.java | 4 +- .../packet/client/play/ClientCloseWindow.java | 4 +- .../client/play/ClientCraftRecipeRequest.java | 4 +- .../ClientCreativeInventoryActionPacket.java | 4 +- .../client/play/ClientEntityActionPacket.java | 4 +- .../play/ClientHeldItemChangePacket.java | 4 +- .../play/ClientInteractEntityPacket.java | 4 +- .../client/play/ClientKeepAlivePacket.java | 4 +- .../client/play/ClientNameItemPacket.java | 4 +- .../client/play/ClientPickItemPacket.java | 4 +- .../play/ClientPlayerAbilitiesPacket.java | 4 +- .../ClientPlayerBlockPlacementPacket.java | 4 +- .../play/ClientPlayerDiggingPacket.java | 4 +- .../client/play/ClientPlayerPacket.java | 4 +- ...ClientPlayerPositionAndRotationPacket.java | 4 +- .../play/ClientPlayerPositionPacket.java | 4 +- .../play/ClientPlayerRotationPacket.java | 4 +- .../play/ClientPluginMessagePacket.java | 4 +- .../client/play/ClientRecipeBookData.java | 4 +- .../play/ClientResourcePackStatusPacket.java | 4 +- .../client/play/ClientSelectTradePacket.java | 4 +- .../client/play/ClientSettingsPacket.java | 4 +- .../client/play/ClientSpectatePacket.java | 4 +- .../client/play/ClientStatusPacket.java | 4 +- .../client/play/ClientSteerBoatPacket.java | 4 +- .../client/play/ClientSteerVehiclePacket.java | 4 +- .../client/play/ClientTabCompletePacket.java | 4 +- .../play/ClientTeleportConfirmPacket.java | 4 +- ...lientUpdateCommandBlockMinecartPacket.java | 4 +- .../play/ClientUpdateCommandBlockPacket.java | 4 +- .../client/play/ClientUpdateSignPacket.java | 4 +- .../client/play/ClientUseItemPacket.java | 4 +- .../client/play/ClientVehicleMovePacket.java | 4 +- .../play/ClientWindowConfirmationPacket.java | 4 +- .../status/LegacyServerListPingPacket.java | 4 +- .../packet/client/status/PingPacket.java | 4 +- .../client/status/StatusRequestPacket.java | 4 +- .../network/packet/server/ServerPacket.java | 4 +- .../server/handshake/ResponsePacket.java | 4 +- .../server/login/EncryptionRequestPacket.java | 4 +- .../packet/server/login/JoinGamePacket.java | 4 +- .../packet/server/login/LoginDisconnect.java | 4 +- .../server/login/LoginSuccessPacket.java | 4 +- .../server/login/SetCompressionPacket.java | 4 +- .../play/AcknowledgePlayerDiggingPacket.java | 4 +- .../server/play/AdvancementsPacket.java | 20 +-- .../server/play/AttachEntityPacket.java | 4 +- .../packet/server/play/BlockActionPacket.java | 4 +- .../play/BlockBreakAnimationPacket.java | 4 +- .../packet/server/play/BlockChangePacket.java | 4 +- .../packet/server/play/BossBarPacket.java | 4 +- .../packet/server/play/CameraPacket.java | 4 +- .../server/play/ChangeGameStatePacket.java | 4 +- .../packet/server/play/ChatMessagePacket.java | 4 +- .../packet/server/play/ChunkDataPacket.java | 6 +- .../packet/server/play/CloseWindowPacket.java | 4 +- .../packet/server/play/CollectItemPacket.java | 4 +- .../packet/server/play/CombatEventPacket.java | 4 +- .../server/play/CraftRecipeResponse.java | 4 +- .../server/play/DeclareCommandsPacket.java | 8 +- .../server/play/DeclareRecipesPacket.java | 8 +- .../server/play/DestroyEntitiesPacket.java | 4 +- .../packet/server/play/DisconnectPacket.java | 4 +- .../server/play/DisplayScoreboardPacket.java | 4 +- .../packet/server/play/EffectPacket.java | 4 +- .../server/play/EntityAnimationPacket.java | 4 +- .../server/play/EntityEffectPacket.java | 4 +- .../server/play/EntityEquipmentPacket.java | 4 +- .../server/play/EntityHeadLookPacket.java | 4 +- .../server/play/EntityMetaDataPacket.java | 6 +- .../packet/server/play/EntityPacket.java | 4 +- .../play/EntityPositionAndRotationPacket.java | 4 +- .../server/play/EntityPositionPacket.java | 4 +- .../server/play/EntityPropertiesPacket.java | 6 +- .../server/play/EntityRotationPacket.java | 4 +- .../packet/server/play/EntitySoundEffect.java | 4 +- .../server/play/EntityStatusPacket.java | 4 +- .../server/play/EntityTeleportPacket.java | 4 +- .../server/play/EntityVelocityPacket.java | 4 +- .../packet/server/play/ExplosionPacket.java | 4 +- .../packet/server/play/FacePlayerPacket.java | 4 +- .../server/play/HeldItemChangePacket.java | 4 +- .../packet/server/play/KeepAlivePacket.java | 4 +- .../packet/server/play/MapDataPacket.java | 6 +- .../server/play/MultiBlockChangePacket.java | 4 +- .../server/play/NamedSoundEffectPacket.java | 4 +- .../packet/server/play/OpenBookPacket.java | 4 +- .../server/play/OpenHorseWindowPacket.java | 4 +- .../server/play/OpenSignEditorPacket.java | 4 +- .../packet/server/play/OpenWindowPacket.java | 4 +- .../packet/server/play/ParticlePacket.java | 6 +- .../server/play/PlayerAbilitiesPacket.java | 4 +- .../packet/server/play/PlayerInfoPacket.java | 18 +-- .../play/PlayerListHeaderAndFooterPacket.java | 4 +- .../play/PlayerPositionAndLookPacket.java | 4 +- .../server/play/PluginMessagePacket.java | 6 +- .../server/play/RemoveEntityEffectPacket.java | 4 +- .../server/play/ResourcePackSendPacket.java | 4 +- .../packet/server/play/RespawnPacket.java | 4 +- .../play/ScoreboardObjectivePacket.java | 4 +- .../server/play/ServerDifficultyPacket.java | 4 +- .../packet/server/play/SetCooldownPacket.java | 4 +- .../server/play/SetExperiencePacket.java | 4 +- .../server/play/SetPassengersPacket.java | 4 +- .../packet/server/play/SetSlotPacket.java | 4 +- .../packet/server/play/SoundEffectPacket.java | 4 +- .../packet/server/play/SpawnEntityPacket.java | 4 +- .../server/play/SpawnExperienceOrbPacket.java | 4 +- .../server/play/SpawnLivingEntityPacket.java | 4 +- .../server/play/SpawnPaintingPacket.java | 4 +- .../packet/server/play/SpawnPlayerPacket.java | 4 +- .../server/play/SpawnPositionPacket.java | 4 +- .../packet/server/play/StatisticsPacket.java | 6 +- .../packet/server/play/StopSoundPacket.java | 4 +- .../packet/server/play/TabCompletePacket.java | 4 +- .../packet/server/play/TagsPacket.java | 6 +- .../packet/server/play/TeamsPacket.java | 6 +- .../packet/server/play/TimeUpdatePacket.java | 4 +- .../packet/server/play/TitlePacket.java | 4 +- .../packet/server/play/TradeListPacket.java | 6 +- .../packet/server/play/UnloadChunkPacket.java | 4 +- .../server/play/UnlockRecipesPacket.java | 4 +- .../server/play/UpdateHealthPacket.java | 4 +- .../packet/server/play/UpdateLightPacket.java | 4 +- .../packet/server/play/UpdateScorePacket.java | 4 +- .../server/play/UpdateViewPositionPacket.java | 4 +- .../packet/server/play/VehicleMovePacket.java | 4 +- .../server/play/WindowConfirmationPacket.java | 4 +- .../packet/server/play/WindowItemsPacket.java | 4 +- .../server/play/WindowPropertyPacket.java | 4 +- .../packet/server/play/WorldBorderPacket.java | 18 +-- .../packet/server/status/PongPacket.java | 4 +- .../server/particle/ParticleCreator.java | 4 +- .../minestom/server/reader/ChunkReader.java | 47 ++++--- .../minestom/server/reader/DataReader.java | 37 ++--- .../server/resourcepack/ResourcePack.java | 4 +- .../server/storage/StorageFolder.java | 52 +++---- .../net/minestom/server/utils/NBTUtils.java | 8 +- .../minestom/server/utils/PacketUtils.java | 4 +- .../java/net/minestom/server/utils/Utils.java | 6 +- .../binary/BinaryReader.java} | 36 +++-- .../binary/BinaryWriter.java} | 133 ++++++++++++++++-- 210 files changed, 865 insertions(+), 788 deletions(-) rename src/main/java/net/minestom/server/{network/packet/PacketReader.java => utils/binary/BinaryReader.java} (78%) rename src/main/java/net/minestom/server/{network/packet/PacketWriter.java => utils/binary/BinaryWriter.java} (55%) diff --git a/src/main/java/fr/themode/demo/PlayerInit.java b/src/main/java/fr/themode/demo/PlayerInit.java index 6b426060b..2419afa47 100644 --- a/src/main/java/fr/themode/demo/PlayerInit.java +++ b/src/main/java/fr/themode/demo/PlayerInit.java @@ -1,6 +1,6 @@ package fr.themode.demo; -import fr.themode.demo.entity.ChickenCreature; +import fr.themode.demo.blocks.StoneBlock; import fr.themode.demo.generator.ChunkGeneratorDemo; import fr.themode.demo.generator.NoiseTestGenerator; import net.minestom.server.MinecraftServer; @@ -8,6 +8,7 @@ import net.minestom.server.benchmark.BenchmarkManager; import net.minestom.server.benchmark.ThreadResult; import net.minestom.server.chat.ChatColor; import net.minestom.server.chat.ColoredText; +import net.minestom.server.data.Data; import net.minestom.server.entity.*; import net.minestom.server.entity.damage.DamageType; import net.minestom.server.event.entity.EntityAttackEvent; @@ -20,6 +21,7 @@ import net.minestom.server.instance.Instance; import net.minestom.server.instance.InstanceContainer; import net.minestom.server.instance.WorldBorder; import net.minestom.server.instance.block.Block; +import net.minestom.server.instance.block.CustomBlock; import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.InventoryType; import net.minestom.server.item.ItemStack; @@ -28,11 +30,13 @@ import net.minestom.server.item.metadata.MapMeta; import net.minestom.server.network.ConnectionManager; import net.minestom.server.ping.ResponseDataConsumer; import net.minestom.server.scoreboard.Sidebar; +import net.minestom.server.storage.StorageFolder; +import net.minestom.server.storage.StorageOptions; +import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.Position; import net.minestom.server.utils.Vector; import net.minestom.server.utils.time.TimeUnit; -import net.minestom.server.world.DimensionType; import java.util.Map; import java.util.UUID; @@ -44,11 +48,11 @@ public class PlayerInit { private static volatile Inventory inventory; static { - //StorageFolder storageFolder = MinecraftServer.getStorageManager().getFolder("instance_data", new StorageOption().setCompression(true)); + StorageFolder storageFolder = MinecraftServer.getStorageManager().getFolder("instance_data", new StorageOptions().setCompression(true)); ChunkGeneratorDemo chunkGeneratorDemo = new ChunkGeneratorDemo(); NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator(); - //instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(storageFolder); - instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(DimensionType.OVERWORLD); + instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(storageFolder); + //instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(DimensionType.OVERWORLD); instanceContainer.enableAutoChunkLoad(true); //instanceContainer.setChunkDecider((x,y) -> (pos) -> pos.getY()>40?(short)0:(short)1); instanceContainer.setChunkGenerator(noiseTestGenerator); @@ -153,10 +157,10 @@ public class PlayerInit { p.teleport(player.getPosition()); }*/ - for (int i = 0; i < 100; i++) { + /*for (int i = 0; i < 100; i++) { ChickenCreature chickenCreature = new ChickenCreature(player.getPosition()); chickenCreature.setInstance(player.getInstance()); - } + }*/ /*EntityZombie zombie = new EntityZombie(player.getPosition()); zombie.setAttribute(Attribute.MOVEMENT_SPEED, 0.25f); @@ -183,6 +187,17 @@ public class PlayerInit { if (event.getHand() != Player.Hand.MAIN) return; + final Instance instance = player.getInstance(); + final BlockPosition blockPosition = event.getBlockPosition(); + + final CustomBlock customBlock = instance.getCustomBlock(blockPosition); + if (customBlock instanceof StoneBlock) { + final Data data = instance.getBlockData(blockPosition); + if (data != null) { + player.sendMessage("test: " + data.get("test")); + } + } + final short blockStateId = player.getInstance().getBlockStateId(event.getBlockPosition()); final Block block = Block.fromStateId(blockStateId); player.sendMessage("You clicked at the block " + block); diff --git a/src/main/java/fr/themode/demo/commands/SimpleCommand.java b/src/main/java/fr/themode/demo/commands/SimpleCommand.java index 3ba732748..dc9a27f7b 100644 --- a/src/main/java/fr/themode/demo/commands/SimpleCommand.java +++ b/src/main/java/fr/themode/demo/commands/SimpleCommand.java @@ -67,6 +67,8 @@ public class SimpleCommand implements CommandProcessor { NotificationCenter.send(notification, player); NotificationCenter.send(notification, player); + player.getInstance().saveChunksToStorageFolder(() -> System.out.println("end save")); + return true; } diff --git a/src/main/java/fr/themode/demo/generator/NoiseTestGenerator.java b/src/main/java/fr/themode/demo/generator/NoiseTestGenerator.java index 9272f91c5..114c7c018 100644 --- a/src/main/java/fr/themode/demo/generator/NoiseTestGenerator.java +++ b/src/main/java/fr/themode/demo/generator/NoiseTestGenerator.java @@ -3,12 +3,12 @@ package fr.themode.demo.generator; import de.articdive.jnoise.JNoise; import de.articdive.jnoise.interpolation.InterpolationType; import net.minestom.server.MinecraftServer; -import net.minestom.server.world.biomes.Biome; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.ChunkGenerator; import net.minestom.server.instance.ChunkPopulator; import net.minestom.server.instance.batch.ChunkBatch; import net.minestom.server.instance.block.Block; +import net.minestom.server.world.biomes.Biome; import java.util.Arrays; import java.util.List; @@ -28,7 +28,7 @@ public class NoiseTestGenerator extends ChunkGenerator { if (random.nextInt(100) > 10) { batch.setBlock(x, y, z, Block.DIAMOND_BLOCK); } else { - batch.setBlock(x, y, z, Block.GOLD_BLOCK); + batch.setCustomBlock(x, y, z, "custom_block"); } } } diff --git a/src/main/java/net/minestom/server/data/DataManager.java b/src/main/java/net/minestom/server/data/DataManager.java index 8e08ac05c..fd8b3d8ec 100644 --- a/src/main/java/net/minestom/server/data/DataManager.java +++ b/src/main/java/net/minestom/server/data/DataManager.java @@ -79,7 +79,8 @@ public final class DataManager { * @throws NullPointerException if none is found */ public DataType getDataType(Class clazz) { - return dataTypeMap.get(PrimitiveConversion.getObjectClass(clazz)); + clazz = PrimitiveConversion.getObjectClass(clazz); + return dataTypeMap.get(clazz); } } diff --git a/src/main/java/net/minestom/server/data/DataType.java b/src/main/java/net/minestom/server/data/DataType.java index 73fb1e3b5..b4c1897ef 100644 --- a/src/main/java/net/minestom/server/data/DataType.java +++ b/src/main/java/net/minestom/server/data/DataType.java @@ -1,24 +1,24 @@ package net.minestom.server.data; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public abstract class DataType { /** * Encode the data type * - * @param packetWriter the data writer - * @param value the value to encode + * @param writer the data writer + * @param value the value to encode */ - public abstract void encode(PacketWriter packetWriter, T value); + public abstract void encode(BinaryWriter writer, T value); /** * Decode the data type * - * @param packetReader the data reader + * @param reader the data reader * @return the decoded value */ - public abstract T decode(PacketReader packetReader); + public abstract T decode(BinaryReader reader); } \ No newline at end of file diff --git a/src/main/java/net/minestom/server/data/SerializableData.java b/src/main/java/net/minestom/server/data/SerializableData.java index 5ca848d81..b42fb41e4 100644 --- a/src/main/java/net/minestom/server/data/SerializableData.java +++ b/src/main/java/net/minestom/server/data/SerializableData.java @@ -1,13 +1,9 @@ package net.minestom.server.data; import net.minestom.server.MinecraftServer; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.PrimitiveConversion; +import net.minestom.server.utils.binary.BinaryWriter; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class SerializableData extends Data { @@ -52,36 +48,28 @@ public class SerializableData extends Data { * to convert it back * * @return the array representation of this data object - * @throws IOException if an error occur when serializing the data */ - public byte[] getSerializedData() throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(output); + public byte[] getSerializedData() { + BinaryWriter binaryWriter = new BinaryWriter(); - for (Map.Entry entry : data.entrySet()) { - final String key = entry.getKey(); + data.forEach((key, value) -> { final Class type = dataType.get(key); - final Object value = entry.getValue(); final DataType dataType = DATA_MANAGER.getDataType(type); - final byte[] encodedType = PrimitiveConversion.getObjectClassString(type.getName()).getBytes(); // Data type (fix for primitives) - dos.writeShort(encodedType.length); - dos.write(encodedType); + // Write the data type + final String encodedType = PrimitiveConversion.getObjectClassString(type.getName()); // Data type (fix for primitives) + binaryWriter.writeSizedString(encodedType); - final byte[] encodedName = key.getBytes(); // Data name - dos.writeShort(encodedName.length); - dos.write(encodedName); + // Write the data key + binaryWriter.writeSizedString(key); - PacketWriter packetWriter = new PacketWriter(); - dataType.encode(packetWriter, value); // Encode - final byte[] encodedValue = packetWriter.toByteArray(); // Retrieve bytes - dos.writeInt(encodedValue.length); - dos.write(encodedValue); - } + // Write the data (no length) + dataType.encode(binaryWriter, value); + }); - dos.writeShort(0xff); // End of data object + binaryWriter.writeVarInt(0); // End of data object - return output.toByteArray(); + return binaryWriter.toByteArray(); } } diff --git a/src/main/java/net/minestom/server/data/type/BooleanData.java b/src/main/java/net/minestom/server/data/type/BooleanData.java index 5cac25bae..6c6dcf5cd 100644 --- a/src/main/java/net/minestom/server/data/type/BooleanData.java +++ b/src/main/java/net/minestom/server/data/type/BooleanData.java @@ -1,17 +1,17 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class BooleanData extends DataType { @Override - public void encode(PacketWriter packetWriter, Boolean value) { - packetWriter.writeBoolean(value); + public void encode(BinaryWriter binaryWriter, Boolean value) { + binaryWriter.writeBoolean(value); } @Override - public Boolean decode(PacketReader packetReader) { - return packetReader.readBoolean(); + public Boolean decode(BinaryReader binaryReader) { + return binaryReader.readBoolean(); } } diff --git a/src/main/java/net/minestom/server/data/type/ByteData.java b/src/main/java/net/minestom/server/data/type/ByteData.java index 6236a1b0b..60a783ec1 100644 --- a/src/main/java/net/minestom/server/data/type/ByteData.java +++ b/src/main/java/net/minestom/server/data/type/ByteData.java @@ -1,17 +1,17 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class ByteData extends DataType { @Override - public void encode(PacketWriter packetWriter, Byte value) { - packetWriter.writeByte(value); + public void encode(BinaryWriter binaryWriter, Byte value) { + binaryWriter.writeByte(value); } @Override - public Byte decode(PacketReader packetReader) { - return packetReader.readByte(); + public Byte decode(BinaryReader binaryReader) { + return binaryReader.readByte(); } } diff --git a/src/main/java/net/minestom/server/data/type/CharacterData.java b/src/main/java/net/minestom/server/data/type/CharacterData.java index 4dfd0017b..b209a73ff 100644 --- a/src/main/java/net/minestom/server/data/type/CharacterData.java +++ b/src/main/java/net/minestom/server/data/type/CharacterData.java @@ -1,18 +1,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class CharacterData extends DataType { @Override - public void encode(PacketWriter packetWriter, Character value) { - packetWriter.writeChar(value); + public void encode(BinaryWriter binaryWriter, Character value) { + binaryWriter.writeChar(value); } @Override - public Character decode(PacketReader packetReader) { - return packetReader.readChar(); + public Character decode(BinaryReader binaryReader) { + return binaryReader.readChar(); } } diff --git a/src/main/java/net/minestom/server/data/type/DoubleData.java b/src/main/java/net/minestom/server/data/type/DoubleData.java index b0b767852..282274813 100644 --- a/src/main/java/net/minestom/server/data/type/DoubleData.java +++ b/src/main/java/net/minestom/server/data/type/DoubleData.java @@ -1,18 +1,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class DoubleData extends DataType { @Override - public void encode(PacketWriter packetWriter, Double value) { - packetWriter.writeDouble(value); + public void encode(BinaryWriter binaryWriter, Double value) { + binaryWriter.writeDouble(value); } @Override - public Double decode(PacketReader packetReader) { - return packetReader.readDouble(); + public Double decode(BinaryReader binaryReader) { + return binaryReader.readDouble(); } } diff --git a/src/main/java/net/minestom/server/data/type/FloatData.java b/src/main/java/net/minestom/server/data/type/FloatData.java index 21ce8977f..d2eee8b1f 100644 --- a/src/main/java/net/minestom/server/data/type/FloatData.java +++ b/src/main/java/net/minestom/server/data/type/FloatData.java @@ -1,18 +1,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class FloatData extends DataType { @Override - public void encode(PacketWriter packetWriter, Float value) { - packetWriter.writeFloat(value); + public void encode(BinaryWriter binaryWriter, Float value) { + binaryWriter.writeFloat(value); } @Override - public Float decode(PacketReader packetReader) { - return packetReader.readFloat(); + public Float decode(BinaryReader binaryReader) { + return binaryReader.readFloat(); } } diff --git a/src/main/java/net/minestom/server/data/type/IntegerData.java b/src/main/java/net/minestom/server/data/type/IntegerData.java index 9191035fa..1cc5a7ae6 100644 --- a/src/main/java/net/minestom/server/data/type/IntegerData.java +++ b/src/main/java/net/minestom/server/data/type/IntegerData.java @@ -1,18 +1,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class IntegerData extends DataType { @Override - public void encode(PacketWriter packetWriter, Integer value) { - packetWriter.writeVarInt(value); + public void encode(BinaryWriter binaryWriter, Integer value) { + binaryWriter.writeVarInt(value); } @Override - public Integer decode(PacketReader packetReader) { - return packetReader.readVarInt(); + public Integer decode(BinaryReader binaryReader) { + return binaryReader.readVarInt(); } } \ No newline at end of file diff --git a/src/main/java/net/minestom/server/data/type/InventoryData.java b/src/main/java/net/minestom/server/data/type/InventoryData.java index d1d9f56be..3540d36a8 100644 --- a/src/main/java/net/minestom/server/data/type/InventoryData.java +++ b/src/main/java/net/minestom/server/data/type/InventoryData.java @@ -3,37 +3,37 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.InventoryType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class InventoryData extends DataType { @Override - public void encode(PacketWriter packetWriter, Inventory value) { + public void encode(BinaryWriter binaryWriter, Inventory value) { final InventoryType inventoryType = value.getInventoryType(); final int size = inventoryType.getAdditionalSlot(); // Inventory title & type - packetWriter.writeSizedString(value.getTitle()); - packetWriter.writeSizedString(inventoryType.name()); + binaryWriter.writeSizedString(value.getTitle()); + binaryWriter.writeSizedString(inventoryType.name()); // Write all item stacks for (int i = 0; i < size; i++) { - packetWriter.writeItemStack(value.getItemStack(i)); + binaryWriter.writeItemStack(value.getItemStack(i)); } } @Override - public Inventory decode(PacketReader packetReader) { - final String title = packetReader.readSizedString(); - final InventoryType inventoryType = InventoryType.valueOf(packetReader.readSizedString()); + public Inventory decode(BinaryReader binaryReader) { + final String title = binaryReader.readSizedString(); + final InventoryType inventoryType = InventoryType.valueOf(binaryReader.readSizedString()); final int size = inventoryType.getAdditionalSlot(); Inventory inventory = new Inventory(inventoryType, title); // Read all item stacks for (int i = 0; i < size; i++) { - inventory.setItemStack(i, packetReader.readSlot()); + inventory.setItemStack(i, binaryReader.readSlot()); } return inventory; diff --git a/src/main/java/net/minestom/server/data/type/ItemStackData.java b/src/main/java/net/minestom/server/data/type/ItemStackData.java index f29327fc0..61ff61c49 100644 --- a/src/main/java/net/minestom/server/data/type/ItemStackData.java +++ b/src/main/java/net/minestom/server/data/type/ItemStackData.java @@ -2,17 +2,17 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class ItemStackData extends DataType { @Override - public void encode(PacketWriter packetWriter, ItemStack value) { - packetWriter.writeItemStack(value); + public void encode(BinaryWriter binaryWriter, ItemStack value) { + binaryWriter.writeItemStack(value); } @Override - public ItemStack decode(PacketReader packetReader) { - return packetReader.readSlot(); + public ItemStack decode(BinaryReader binaryReader) { + return binaryReader.readSlot(); } } diff --git a/src/main/java/net/minestom/server/data/type/LongData.java b/src/main/java/net/minestom/server/data/type/LongData.java index 410306dc0..a28b6a135 100644 --- a/src/main/java/net/minestom/server/data/type/LongData.java +++ b/src/main/java/net/minestom/server/data/type/LongData.java @@ -1,17 +1,17 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class LongData extends DataType { @Override - public void encode(PacketWriter packetWriter, Long value) { - packetWriter.writeLong(value); + public void encode(BinaryWriter binaryWriter, Long value) { + binaryWriter.writeLong(value); } @Override - public Long decode(PacketReader packetReader) { - return packetReader.readLong(); + public Long decode(BinaryReader binaryReader) { + return binaryReader.readLong(); } } diff --git a/src/main/java/net/minestom/server/data/type/SerializableDataData.java b/src/main/java/net/minestom/server/data/type/SerializableDataData.java index c3211dea7..4b08e03c0 100644 --- a/src/main/java/net/minestom/server/data/type/SerializableDataData.java +++ b/src/main/java/net/minestom/server/data/type/SerializableDataData.java @@ -2,27 +2,20 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.data.SerializableData; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.reader.DataReader; - -import java.io.IOException; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; // Pretty weird name huh? public class SerializableDataData extends DataType { @Override - public void encode(PacketWriter packetWriter, SerializableData value) { - try { - packetWriter.writeBytes(value.getSerializedData()); - } catch (IOException e) { - e.printStackTrace(); - throw new IllegalArgumentException("error while writing the data"); - } + public void encode(BinaryWriter binaryWriter, SerializableData value) { + binaryWriter.writeBytes(value.getSerializedData()); } @Override - public SerializableData decode(PacketReader packetReader) { - return DataReader.readData(packetReader.getBuffer()); + public SerializableData decode(BinaryReader binaryReader) { + return DataReader.readData(binaryReader); } } diff --git a/src/main/java/net/minestom/server/data/type/ShortData.java b/src/main/java/net/minestom/server/data/type/ShortData.java index e7d902b59..720549ee9 100644 --- a/src/main/java/net/minestom/server/data/type/ShortData.java +++ b/src/main/java/net/minestom/server/data/type/ShortData.java @@ -1,18 +1,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class ShortData extends DataType { @Override - public void encode(PacketWriter packetWriter, Short value) { - packetWriter.writeShort(value); + public void encode(BinaryWriter binaryWriter, Short value) { + binaryWriter.writeShort(value); } @Override - public Short decode(PacketReader packetReader) { - return packetReader.readShort(); + public Short decode(BinaryReader binaryReader) { + return binaryReader.readShort(); } } diff --git a/src/main/java/net/minestom/server/data/type/StringData.java b/src/main/java/net/minestom/server/data/type/StringData.java index 6901bd489..2f3f83bd9 100644 --- a/src/main/java/net/minestom/server/data/type/StringData.java +++ b/src/main/java/net/minestom/server/data/type/StringData.java @@ -1,18 +1,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class StringData extends DataType { @Override - public void encode(PacketWriter packetWriter, String value) { - packetWriter.writeSizedString(value); + public void encode(BinaryWriter binaryWriter, String value) { + binaryWriter.writeSizedString(value); } @Override - public String decode(PacketReader packetReader) { - return packetReader.readSizedString(); + public String decode(BinaryReader binaryReader) { + return binaryReader.readSizedString(); } } diff --git a/src/main/java/net/minestom/server/data/type/UuidType.java b/src/main/java/net/minestom/server/data/type/UuidType.java index d037f8524..e777c5e5a 100644 --- a/src/main/java/net/minestom/server/data/type/UuidType.java +++ b/src/main/java/net/minestom/server/data/type/UuidType.java @@ -1,19 +1,19 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.UUID; public class UuidType extends DataType { @Override - public void encode(PacketWriter packetWriter, UUID value) { - packetWriter.writeUuid(value); + public void encode(BinaryWriter binaryWriter, UUID value) { + binaryWriter.writeUuid(value); } @Override - public UUID decode(PacketReader packetReader) { - return packetReader.readUuid(); + public UUID decode(BinaryReader binaryReader) { + return binaryReader.readUuid(); } } diff --git a/src/main/java/net/minestom/server/data/type/array/BooleanArrayData.java b/src/main/java/net/minestom/server/data/type/array/BooleanArrayData.java index 0a8627825..51197188f 100644 --- a/src/main/java/net/minestom/server/data/type/array/BooleanArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/BooleanArrayData.java @@ -1,24 +1,24 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class BooleanArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, boolean[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, boolean[] value) { + binaryWriter.writeVarInt(value.length); for (boolean val : value) { - packetWriter.writeBoolean(val); + binaryWriter.writeBoolean(val); } } @Override - public boolean[] decode(PacketReader packetReader) { - boolean[] array = new boolean[packetReader.readVarInt()]; + public boolean[] decode(BinaryReader binaryReader) { + boolean[] array = new boolean[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readBoolean(); + array[i] = binaryReader.readBoolean(); } return array; } 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 56513c0a0..b71925361 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 @@ -1,31 +1,31 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class ByteArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, byte[] value) { - encodeByteArray(packetWriter, value); + public void encode(BinaryWriter binaryWriter, byte[] value) { + encodeByteArray(binaryWriter, value); } @Override - public byte[] decode(PacketReader packetReader) { - return decodeByteArray(packetReader); + public byte[] decode(BinaryReader binaryReader) { + return decodeByteArray(binaryReader); } - public static void encodeByteArray(PacketWriter packetWriter, byte[] value) { - packetWriter.writeVarInt(value.length); + public static void encodeByteArray(BinaryWriter binaryWriter, byte[] value) { + binaryWriter.writeVarInt(value.length); for (byte val : value) { - packetWriter.writeByte(val); + binaryWriter.writeByte(val); } } - public static byte[] decodeByteArray(PacketReader packetReader) { - byte[] array = new byte[packetReader.readVarInt()]; + public static byte[] decodeByteArray(BinaryReader binaryReader) { + byte[] array = new byte[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readByte(); + array[i] = binaryReader.readByte(); } return array; } diff --git a/src/main/java/net/minestom/server/data/type/array/CharacterArrayData.java b/src/main/java/net/minestom/server/data/type/array/CharacterArrayData.java index d8c434785..d58278deb 100644 --- a/src/main/java/net/minestom/server/data/type/array/CharacterArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/CharacterArrayData.java @@ -1,23 +1,23 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class CharacterArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, char[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, char[] value) { + binaryWriter.writeVarInt(value.length); for (char val : value) { - packetWriter.writeChar(val); + binaryWriter.writeChar(val); } } @Override - public char[] decode(PacketReader packetReader) { - char[] array = new char[packetReader.readVarInt()]; + public char[] decode(BinaryReader binaryReader) { + char[] array = new char[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readChar(); + array[i] = binaryReader.readChar(); } return array; } diff --git a/src/main/java/net/minestom/server/data/type/array/DoubleArrayData.java b/src/main/java/net/minestom/server/data/type/array/DoubleArrayData.java index 85d471637..33b5a92f2 100644 --- a/src/main/java/net/minestom/server/data/type/array/DoubleArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/DoubleArrayData.java @@ -1,24 +1,24 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class DoubleArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, double[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, double[] value) { + binaryWriter.writeVarInt(value.length); for (double val : value) { - packetWriter.writeDouble(val); + binaryWriter.writeDouble(val); } } @Override - public double[] decode(PacketReader packetReader) { - double[] array = new double[packetReader.readVarInt()]; + public double[] decode(BinaryReader binaryReader) { + double[] array = new double[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readDouble(); + array[i] = binaryReader.readDouble(); } return array; } diff --git a/src/main/java/net/minestom/server/data/type/array/FloatArrayData.java b/src/main/java/net/minestom/server/data/type/array/FloatArrayData.java index c1cf83d70..8af81c956 100644 --- a/src/main/java/net/minestom/server/data/type/array/FloatArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/FloatArrayData.java @@ -1,24 +1,24 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class FloatArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, float[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, float[] value) { + binaryWriter.writeVarInt(value.length); for (float val : value) { - packetWriter.writeFloat(val); + binaryWriter.writeFloat(val); } } @Override - public float[] decode(PacketReader packetReader) { - float[] array = new float[packetReader.readVarInt()]; + public float[] decode(BinaryReader binaryReader) { + float[] array = new float[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readFloat(); + array[i] = binaryReader.readFloat(); } return array; } diff --git a/src/main/java/net/minestom/server/data/type/array/IntegerArrayData.java b/src/main/java/net/minestom/server/data/type/array/IntegerArrayData.java index 0361895e1..d77c57b60 100644 --- a/src/main/java/net/minestom/server/data/type/array/IntegerArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/IntegerArrayData.java @@ -1,24 +1,24 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class IntegerArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, int[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, int[] value) { + binaryWriter.writeVarInt(value.length); for (int val : value) { - packetWriter.writeInt(val); + binaryWriter.writeInt(val); } } @Override - public int[] decode(PacketReader packetReader) { - int[] array = new int[packetReader.readVarInt()]; + public int[] decode(BinaryReader binaryReader) { + int[] array = new int[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readInteger(); + array[i] = binaryReader.readInteger(); } return array; } diff --git a/src/main/java/net/minestom/server/data/type/array/ItemStackArrayData.java b/src/main/java/net/minestom/server/data/type/array/ItemStackArrayData.java index 4e8a4563d..713e98152 100644 --- a/src/main/java/net/minestom/server/data/type/array/ItemStackArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/ItemStackArrayData.java @@ -2,23 +2,23 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class ItemStackArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, ItemStack[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, ItemStack[] value) { + binaryWriter.writeVarInt(value.length); for (ItemStack itemStack : value) { - packetWriter.writeItemStack(itemStack); + binaryWriter.writeItemStack(itemStack); } } @Override - public ItemStack[] decode(PacketReader packetReader) { - ItemStack[] items = new ItemStack[packetReader.readVarInt()]; + public ItemStack[] decode(BinaryReader binaryReader) { + ItemStack[] items = new ItemStack[binaryReader.readVarInt()]; for (int i = 0; i < items.length; i++) { - items[i] = packetReader.readSlot(); + items[i] = binaryReader.readSlot(); } return items; } diff --git a/src/main/java/net/minestom/server/data/type/array/LongArrayData.java b/src/main/java/net/minestom/server/data/type/array/LongArrayData.java index e0e60e0e7..da6d8beeb 100644 --- a/src/main/java/net/minestom/server/data/type/array/LongArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/LongArrayData.java @@ -1,24 +1,24 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class LongArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, long[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, long[] value) { + binaryWriter.writeVarInt(value.length); for (long val : value) { - packetWriter.writeLong(val); + binaryWriter.writeLong(val); } } @Override - public long[] decode(PacketReader packetReader) { - long[] array = new long[packetReader.readVarInt()]; + public long[] decode(BinaryReader binaryReader) { + long[] array = new long[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readLong(); + array[i] = binaryReader.readLong(); } return array; } diff --git a/src/main/java/net/minestom/server/data/type/array/ShortArrayData.java b/src/main/java/net/minestom/server/data/type/array/ShortArrayData.java index fb8baedda..dbb683411 100644 --- a/src/main/java/net/minestom/server/data/type/array/ShortArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/ShortArrayData.java @@ -1,24 +1,24 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class ShortArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, short[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, short[] value) { + binaryWriter.writeVarInt(value.length); for (short val : value) { - packetWriter.writeShort(val); + binaryWriter.writeShort(val); } } @Override - public short[] decode(PacketReader packetReader) { - short[] array = new short[packetReader.readVarInt()]; + public short[] decode(BinaryReader binaryReader) { + short[] array = new short[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readShort(); + array[i] = binaryReader.readShort(); } return array; } diff --git a/src/main/java/net/minestom/server/data/type/array/StringArrayData.java b/src/main/java/net/minestom/server/data/type/array/StringArrayData.java index 282451c59..5a63571be 100644 --- a/src/main/java/net/minestom/server/data/type/array/StringArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/StringArrayData.java @@ -1,24 +1,24 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; public class StringArrayData extends DataType { @Override - public void encode(PacketWriter packetWriter, String[] value) { - packetWriter.writeVarInt(value.length); + public void encode(BinaryWriter binaryWriter, String[] value) { + binaryWriter.writeVarInt(value.length); for (String val : value) { - packetWriter.writeSizedString(val); + binaryWriter.writeSizedString(val); } } @Override - public String[] decode(PacketReader packetReader) { - String[] array = new String[packetReader.readVarInt()]; + public String[] decode(BinaryReader binaryReader) { + String[] array = new String[binaryReader.readVarInt()]; for (int i = 0; i < array.length; i++) { - array[i] = packetReader.readSizedString(); + array[i] = binaryReader.readSizedString(); } return array; } diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index d89324880..dfec7afbb 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -19,12 +19,12 @@ import net.minestom.server.instance.Instance; import net.minestom.server.instance.InstanceManager; import net.minestom.server.instance.WorldBorder; import net.minestom.server.instance.block.CustomBlock; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.play.*; import net.minestom.server.utils.ArrayUtils; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.Position; import net.minestom.server.utils.Vector; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.entity.EntityUtils; import net.minestom.server.utils.player.PlayerUtils; @@ -1195,7 +1195,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer { * * @return The consumer used to write {@link EntityMetaDataPacket} in {@link #getMetadataPacket()} */ - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { fillMetadataIndex(packet, 0); fillMetadataIndex(packet, 1); @@ -1209,7 +1209,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer { /** * Send a {@link EntityMetaDataPacket} containing only the specified index - * The index is wrote using {@link #fillMetadataIndex(PacketWriter, int)} + * The index is wrote using {@link #fillMetadataIndex(BinaryWriter, int)} * * @param index the metadata index */ @@ -1229,7 +1229,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer { * @param packet the packet writer * @param index the index to fill/write */ - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { switch (index) { case 0: fillStateMetadata(packet); @@ -1255,7 +1255,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer { } } - private void fillStateMetadata(PacketWriter packet) { + private void fillStateMetadata(BinaryWriter packet) { packet.writeByte((byte) 0); packet.writeByte(METADATA_BYTE); byte index0 = 0; @@ -1278,13 +1278,13 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer { packet.writeByte(index0); } - private void fillAirTickMetaData(PacketWriter packet) { + private void fillAirTickMetaData(BinaryWriter packet) { packet.writeByte((byte) 1); packet.writeByte(METADATA_VARINT); packet.writeVarInt(air); } - private void fillCustomNameMetaData(PacketWriter packet) { + private void fillCustomNameMetaData(BinaryWriter packet) { boolean hasCustomName = customName != null; packet.writeByte((byte) 2); @@ -1295,25 +1295,25 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer { } } - private void fillCustomNameVisibleMetaData(PacketWriter packet) { + private void fillCustomNameVisibleMetaData(BinaryWriter packet) { packet.writeByte((byte) 3); packet.writeByte(METADATA_BOOLEAN); packet.writeBoolean(customNameVisible); } - private void fillSilentMetaData(PacketWriter packet) { + private void fillSilentMetaData(BinaryWriter packet) { packet.writeByte((byte) 4); packet.writeByte(METADATA_BOOLEAN); packet.writeBoolean(silent); } - private void fillNoGravityMetaData(PacketWriter packet) { + private void fillNoGravityMetaData(BinaryWriter packet) { packet.writeByte((byte) 5); packet.writeByte(METADATA_BOOLEAN); packet.writeBoolean(noGravity); } - private void fillPoseMetaData(PacketWriter packet) { + private void fillPoseMetaData(BinaryWriter packet) { packet.writeByte((byte) 6); packet.writeByte(METADATA_POSE); packet.writeVarInt(pose.ordinal()); diff --git a/src/main/java/net/minestom/server/entity/ItemEntity.java b/src/main/java/net/minestom/server/entity/ItemEntity.java index c2dddd553..a93730061 100644 --- a/src/main/java/net/minestom/server/entity/ItemEntity.java +++ b/src/main/java/net/minestom/server/entity/ItemEntity.java @@ -4,8 +4,8 @@ import net.minestom.server.event.entity.EntityItemMergeEvent; import net.minestom.server.instance.Chunk; import net.minestom.server.item.ItemStack; import net.minestom.server.item.StackingRule; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.time.CooldownUtils; import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.UpdateOption; @@ -118,7 +118,7 @@ public class ItemEntity extends ObjectEntity { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 7); @@ -126,7 +126,7 @@ public class ItemEntity extends ObjectEntity { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 7) { packet.writeByte((byte) 7); diff --git a/src/main/java/net/minestom/server/entity/LivingEntity.java b/src/main/java/net/minestom/server/entity/LivingEntity.java index aa62b1608..a36e6a329 100644 --- a/src/main/java/net/minestom/server/entity/LivingEntity.java +++ b/src/main/java/net/minestom/server/entity/LivingEntity.java @@ -10,7 +10,6 @@ import net.minestom.server.event.item.PickupItemEvent; import net.minestom.server.instance.Chunk; import net.minestom.server.inventory.EquipmentHandler; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.play.CollectItemPacket; import net.minestom.server.network.packet.server.play.EntityAnimationPacket; import net.minestom.server.network.packet.server.play.EntityPropertiesPacket; @@ -19,6 +18,7 @@ import net.minestom.server.scoreboard.Team; import net.minestom.server.sound.Sound; import net.minestom.server.sound.SoundCategory; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.time.TimeUnit; import java.util.Set; @@ -119,7 +119,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 7); @@ -129,7 +129,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 7) { packet.writeByte((byte) 7); diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index ec16baeb9..b399a8a2f 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -24,7 +24,6 @@ import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.PlayerInventory; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.login.JoinGamePacket; @@ -43,6 +42,7 @@ import net.minestom.server.utils.ArrayUtils; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.validate.Check; import net.minestom.server.world.DimensionType; @@ -579,7 +579,7 @@ public class Player extends LivingEntity implements CommandSender { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 14); @@ -588,7 +588,7 @@ public class Player extends LivingEntity implements CommandSender { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 14) { packet.writeByte((byte) 14); @@ -622,7 +622,7 @@ public class Player extends LivingEntity implements CommandSender { */ public void sendPluginMessage(String channel, String message) { // Write the data - PacketWriter writer = new PacketWriter(); + BinaryWriter writer = new BinaryWriter(); writer.writeSizedString(message); // Retrieve the data final byte[] data = writer.toByteArray(); diff --git a/src/main/java/net/minestom/server/entity/type/ambient/EntityBat.java b/src/main/java/net/minestom/server/entity/type/ambient/EntityBat.java index 7ad26edbc..9890949bc 100644 --- a/src/main/java/net/minestom/server/entity/type/ambient/EntityBat.java +++ b/src/main/java/net/minestom/server/entity/type/ambient/EntityBat.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.ambient; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Animal; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -18,7 +18,7 @@ public class EntityBat extends EntityCreature implements Animal { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -26,7 +26,7 @@ public class EntityBat extends EntityCreature implements Animal { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/animal/EntityMooshroom.java b/src/main/java/net/minestom/server/entity/type/animal/EntityMooshroom.java index 0d2feb7ba..a50a36632 100644 --- a/src/main/java/net/minestom/server/entity/type/animal/EntityMooshroom.java +++ b/src/main/java/net/minestom/server/entity/type/animal/EntityMooshroom.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.animal; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Animal; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -19,7 +19,7 @@ public class EntityMooshroom extends EntityCreature implements Animal { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 16); @@ -27,7 +27,7 @@ public class EntityMooshroom extends EntityCreature implements Animal { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 16) { packet.writeByte((byte) 16); diff --git a/src/main/java/net/minestom/server/entity/type/animal/EntityPig.java b/src/main/java/net/minestom/server/entity/type/animal/EntityPig.java index b86c9fb96..5e2a7645e 100644 --- a/src/main/java/net/minestom/server/entity/type/animal/EntityPig.java +++ b/src/main/java/net/minestom/server/entity/type/animal/EntityPig.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.animal; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Animal; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -18,7 +18,7 @@ public class EntityPig extends EntityCreature implements Animal { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 16); @@ -26,7 +26,7 @@ public class EntityPig extends EntityCreature implements Animal { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 16) { packet.writeByte((byte) 16); diff --git a/src/main/java/net/minestom/server/entity/type/animal/EntityPolarBear.java b/src/main/java/net/minestom/server/entity/type/animal/EntityPolarBear.java index 5817b78c0..f2f5987df 100644 --- a/src/main/java/net/minestom/server/entity/type/animal/EntityPolarBear.java +++ b/src/main/java/net/minestom/server/entity/type/animal/EntityPolarBear.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.animal; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Animal; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -18,7 +18,7 @@ public class EntityPolarBear extends EntityCreature implements Animal { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 16); @@ -26,7 +26,7 @@ public class EntityPolarBear extends EntityCreature implements Animal { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 16) { packet.writeByte((byte) 16); diff --git a/src/main/java/net/minestom/server/entity/type/animal/EntityRabbit.java b/src/main/java/net/minestom/server/entity/type/animal/EntityRabbit.java index bb6150154..99425c49c 100644 --- a/src/main/java/net/minestom/server/entity/type/animal/EntityRabbit.java +++ b/src/main/java/net/minestom/server/entity/type/animal/EntityRabbit.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.animal; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Animal; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -18,7 +18,7 @@ public class EntityRabbit extends EntityCreature implements Animal { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 16); @@ -26,7 +26,7 @@ public class EntityRabbit extends EntityCreature implements Animal { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 16) { packet.writeByte((byte) 16); diff --git a/src/main/java/net/minestom/server/entity/type/decoration/EntityArmorStand.java b/src/main/java/net/minestom/server/entity/type/decoration/EntityArmorStand.java index 07f8737ab..f907a4e80 100644 --- a/src/main/java/net/minestom/server/entity/type/decoration/EntityArmorStand.java +++ b/src/main/java/net/minestom/server/entity/type/decoration/EntityArmorStand.java @@ -6,10 +6,10 @@ import net.minestom.server.entity.Player; import net.minestom.server.event.item.ArmorEquipEvent; import net.minestom.server.inventory.EquipmentHandler; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.play.EntityEquipmentPacket; import net.minestom.server.utils.Position; import net.minestom.server.utils.Vector; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.item.ItemStackUtils; import java.util.function.Consumer; @@ -73,7 +73,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 14); @@ -87,7 +87,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 14) { packet.writeByte((byte) 14); diff --git a/src/main/java/net/minestom/server/entity/type/decoration/EntityItemFrame.java b/src/main/java/net/minestom/server/entity/type/decoration/EntityItemFrame.java index f0597525c..415c3194a 100644 --- a/src/main/java/net/minestom/server/entity/type/decoration/EntityItemFrame.java +++ b/src/main/java/net/minestom/server/entity/type/decoration/EntityItemFrame.java @@ -3,9 +3,9 @@ package net.minestom.server.entity.type.decoration; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.ObjectEntity; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; import net.minestom.server.utils.Rotation; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.item.ItemStackUtils; import java.util.function.Consumer; @@ -27,7 +27,7 @@ public class EntityItemFrame extends ObjectEntity { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 7); @@ -36,7 +36,7 @@ public class EntityItemFrame extends ObjectEntity { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 7) { packet.writeByte((byte) 7); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntityBlaze.java b/src/main/java/net/minestom/server/entity/type/monster/EntityBlaze.java index 6984e851a..8507fa009 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntityBlaze.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntityBlaze.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -16,7 +16,7 @@ public class EntityBlaze extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -24,7 +24,7 @@ public class EntityBlaze extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntityCreeper.java b/src/main/java/net/minestom/server/entity/type/monster/EntityCreeper.java index 6732e7b02..219d79578 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntityCreeper.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntityCreeper.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -20,7 +20,7 @@ public class EntityCreeper extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -28,7 +28,7 @@ public class EntityCreeper extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntityGhast.java b/src/main/java/net/minestom/server/entity/type/monster/EntityGhast.java index f876531f2..20361fdfd 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntityGhast.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntityGhast.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -19,7 +19,7 @@ public class EntityGhast extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -27,7 +27,7 @@ public class EntityGhast extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntityGuardian.java b/src/main/java/net/minestom/server/entity/type/monster/EntityGuardian.java index 9e8652b57..c9c522005 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntityGuardian.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntityGuardian.java @@ -4,8 +4,8 @@ import net.minestom.server.entity.Entity; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -20,7 +20,7 @@ public class EntityGuardian extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -29,7 +29,7 @@ public class EntityGuardian extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntityPhantom.java b/src/main/java/net/minestom/server/entity/type/monster/EntityPhantom.java index 559cd19c5..604faa117 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntityPhantom.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntityPhantom.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -18,7 +18,7 @@ public class EntityPhantom extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -26,7 +26,7 @@ public class EntityPhantom extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntitySlime.java b/src/main/java/net/minestom/server/entity/type/monster/EntitySlime.java index 910e6e37c..f30f7ff0b 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntitySlime.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntitySlime.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -18,7 +18,7 @@ public class EntitySlime extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -26,7 +26,7 @@ public class EntitySlime extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntitySpider.java b/src/main/java/net/minestom/server/entity/type/monster/EntitySpider.java index 420611dba..1531f0eda 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntitySpider.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntitySpider.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -19,7 +19,7 @@ public class EntitySpider extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -27,7 +27,7 @@ public class EntitySpider extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntityWitch.java b/src/main/java/net/minestom/server/entity/type/monster/EntityWitch.java index b3d1db93c..e84accb7f 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntityWitch.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntityWitch.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -19,7 +19,7 @@ public class EntityWitch extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 16); @@ -27,7 +27,7 @@ public class EntityWitch extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 16) { packet.writeByte((byte) 16); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntityZombie.java b/src/main/java/net/minestom/server/entity/type/monster/EntityZombie.java index 15f299ea1..3b2fca3cb 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntityZombie.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntityZombie.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -19,7 +19,7 @@ public class EntityZombie extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -28,7 +28,7 @@ public class EntityZombie extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/monster/EntityZombifiedPiglin.java b/src/main/java/net/minestom/server/entity/type/monster/EntityZombifiedPiglin.java index ddcdd2ac9..a5b3de960 100644 --- a/src/main/java/net/minestom/server/entity/type/monster/EntityZombifiedPiglin.java +++ b/src/main/java/net/minestom/server/entity/type/monster/EntityZombifiedPiglin.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.monster; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Monster; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -19,7 +19,7 @@ public class EntityZombifiedPiglin extends EntityCreature implements Monster { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -28,7 +28,7 @@ public class EntityZombifiedPiglin extends EntityCreature implements Monster { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/other/EntityAreaEffectCloud.java b/src/main/java/net/minestom/server/entity/type/other/EntityAreaEffectCloud.java index eed2067c9..9cda4b0b6 100644 --- a/src/main/java/net/minestom/server/entity/type/other/EntityAreaEffectCloud.java +++ b/src/main/java/net/minestom/server/entity/type/other/EntityAreaEffectCloud.java @@ -2,15 +2,15 @@ package net.minestom.server.entity.type.other; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.ObjectEntity; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.particle.Particle; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; public class EntityAreaEffectCloud extends ObjectEntity { - public Consumer particleDataConsumer; + public Consumer particleDataConsumer; private float radius; private int color; private boolean ignoreRadius; @@ -27,7 +27,7 @@ public class EntityAreaEffectCloud extends ObjectEntity { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 7); @@ -38,7 +38,7 @@ public class EntityAreaEffectCloud extends ObjectEntity { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 7) { packet.writeByte((byte) 7); @@ -102,7 +102,7 @@ public class EntityAreaEffectCloud extends ObjectEntity { sendMetadataIndex(10); } - public Consumer getParticleDataConsumer() { + public Consumer getParticleDataConsumer() { return particleDataConsumer; } @@ -112,7 +112,7 @@ public class EntityAreaEffectCloud extends ObjectEntity { * @param particleDataConsumer the particle data consumer * @see @see Particle data */ - public void setParticleDataConsumer(Consumer particleDataConsumer) { + public void setParticleDataConsumer(Consumer particleDataConsumer) { this.particleDataConsumer = particleDataConsumer; } } diff --git a/src/main/java/net/minestom/server/entity/type/other/EntityIronGolem.java b/src/main/java/net/minestom/server/entity/type/other/EntityIronGolem.java index 6cfee7d27..8e665fc48 100644 --- a/src/main/java/net/minestom/server/entity/type/other/EntityIronGolem.java +++ b/src/main/java/net/minestom/server/entity/type/other/EntityIronGolem.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.other; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Constructable; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -18,7 +18,7 @@ public class EntityIronGolem extends EntityCreature implements Constructable { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -26,7 +26,7 @@ public class EntityIronGolem extends EntityCreature implements Constructable { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/other/EntitySnowman.java b/src/main/java/net/minestom/server/entity/type/other/EntitySnowman.java index bc7d87938..774be6850 100644 --- a/src/main/java/net/minestom/server/entity/type/other/EntitySnowman.java +++ b/src/main/java/net/minestom/server/entity/type/other/EntitySnowman.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.other; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.type.Constructable; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -18,7 +18,7 @@ public class EntitySnowman extends EntityCreature implements Constructable { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 15); @@ -26,7 +26,7 @@ public class EntitySnowman extends EntityCreature implements Constructable { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 15) { packet.writeByte((byte) 15); diff --git a/src/main/java/net/minestom/server/entity/type/projectile/EntityEyeOfEnder.java b/src/main/java/net/minestom/server/entity/type/projectile/EntityEyeOfEnder.java index f2a360311..071fd960c 100644 --- a/src/main/java/net/minestom/server/entity/type/projectile/EntityEyeOfEnder.java +++ b/src/main/java/net/minestom/server/entity/type/projectile/EntityEyeOfEnder.java @@ -5,8 +5,8 @@ import net.minestom.server.entity.ObjectEntity; import net.minestom.server.entity.type.Projectile; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -19,7 +19,7 @@ public class EntityEyeOfEnder extends ObjectEntity implements Projectile { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 7); @@ -27,7 +27,7 @@ public class EntityEyeOfEnder extends ObjectEntity implements Projectile { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 7) { packet.writeByte((byte) 7); diff --git a/src/main/java/net/minestom/server/entity/type/projectile/EntityPotion.java b/src/main/java/net/minestom/server/entity/type/projectile/EntityPotion.java index ce6cb0f74..8bd6356aa 100644 --- a/src/main/java/net/minestom/server/entity/type/projectile/EntityPotion.java +++ b/src/main/java/net/minestom/server/entity/type/projectile/EntityPotion.java @@ -4,8 +4,8 @@ import net.minestom.server.entity.EntityType; import net.minestom.server.entity.ObjectEntity; import net.minestom.server.entity.type.Projectile; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -20,7 +20,7 @@ public class EntityPotion extends ObjectEntity implements Projectile { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 7); @@ -28,7 +28,7 @@ public class EntityPotion extends ObjectEntity implements Projectile { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 7) { packet.writeByte((byte) 7); diff --git a/src/main/java/net/minestom/server/entity/type/vehicle/EntityBoat.java b/src/main/java/net/minestom/server/entity/type/vehicle/EntityBoat.java index 47bff20d6..2ba8a096b 100644 --- a/src/main/java/net/minestom/server/entity/type/vehicle/EntityBoat.java +++ b/src/main/java/net/minestom/server/entity/type/vehicle/EntityBoat.java @@ -3,8 +3,8 @@ package net.minestom.server.entity.type.vehicle; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.ObjectEntity; import net.minestom.server.entity.type.Vehicle; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.Position; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.validate.Check; import java.util.function.Consumer; @@ -27,7 +27,7 @@ public class EntityBoat extends ObjectEntity implements Vehicle { } @Override - public Consumer getMetadataConsumer() { + public Consumer getMetadataConsumer() { return packet -> { super.getMetadataConsumer().accept(packet); fillMetadataIndex(packet, 10); @@ -39,7 +39,7 @@ public class EntityBoat extends ObjectEntity implements Vehicle { } @Override - protected void fillMetadataIndex(PacketWriter packet, int index) { + protected void fillMetadataIndex(BinaryWriter packet, int index) { super.fillMetadataIndex(packet, index); if (index == 10) { packet.writeByte((byte) 10); diff --git a/src/main/java/net/minestom/server/instance/Chunk.java b/src/main/java/net/minestom/server/instance/Chunk.java index 5f005c46a..fe535c102 100644 --- a/src/main/java/net/minestom/server/instance/Chunk.java +++ b/src/main/java/net/minestom/server/instance/Chunk.java @@ -26,7 +26,6 @@ import net.minestom.server.utils.time.UpdateOption; import net.minestom.server.utils.validate.Check; import net.minestom.server.world.biomes.Biome; -import java.io.IOException; import java.util.*; import java.util.concurrent.CopyOnWriteArraySet; import java.util.function.Consumer; @@ -229,9 +228,8 @@ public abstract class Chunk implements Viewable { * Serialize the chunk * * @return the serialized chunk - * @throws IOException */ - protected abstract byte[] getSerializedData() throws IOException; + protected abstract byte[] getSerializedData(); /** * Get a {@link ChunkDataPacket} which should contain the full chunk diff --git a/src/main/java/net/minestom/server/instance/DynamicChunk.java b/src/main/java/net/minestom/server/instance/DynamicChunk.java index d2054d73b..7121b82e5 100644 --- a/src/main/java/net/minestom/server/instance/DynamicChunk.java +++ b/src/main/java/net/minestom/server/instance/DynamicChunk.java @@ -9,11 +9,9 @@ import net.minestom.server.instance.block.CustomBlock; import net.minestom.server.instance.block.UpdateConsumer; import net.minestom.server.network.packet.server.play.ChunkDataPacket; import net.minestom.server.utils.MathUtils; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.world.biomes.Biome; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; import java.util.concurrent.CopyOnWriteArraySet; public class DynamicChunk extends Chunk { @@ -146,12 +144,13 @@ public class DynamicChunk extends Chunk { } @Override - protected byte[] getSerializedData() throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(output); + protected byte[] getSerializedData() { + BinaryWriter binaryWriter = new BinaryWriter(); + // Write the biomes id for (int i = 0; i < BIOME_COUNT; i++) { - dos.writeByte(biomes[i].getId()); + final byte id = (byte) biomes[i].getId(); + binaryWriter.writeByte(id); } for (byte x = 0; x < CHUNK_SIZE_X; x++) { @@ -162,33 +161,32 @@ public class DynamicChunk extends Chunk { final short blockStateId = blocksStateId[index]; final short customBlockId = customBlocksId[index]; + // No block at the position if (blockStateId == 0 && customBlockId == 0) continue; - final Data data = blocksData.get(index); - // Chunk coordinates - dos.writeInt(x); - dos.writeInt(y); - dos.writeInt(z); + binaryWriter.writeByte(x); + binaryWriter.writeShort(y); + binaryWriter.writeByte(z); - // Id - dos.writeShort(blockStateId); - dos.writeShort(customBlockId); + // Block ids + binaryWriter.writeShort(blockStateId); + binaryWriter.writeShort(customBlockId); // Data + final Data data = blocksData.get(index); final boolean hasData = data instanceof SerializableData; - dos.writeBoolean(hasData); + binaryWriter.writeBoolean(hasData); if (hasData) { - final byte[] d = ((SerializableData) data).getSerializedData(); - dos.writeInt(d.length); - dos.write(d); + final byte[] serializedData = ((SerializableData) data).getSerializedData(); + binaryWriter.writeBytes(serializedData); } } } } - return output.toByteArray(); + return binaryWriter.toByteArray(); } @Override diff --git a/src/main/java/net/minestom/server/instance/MinestomBasicChunkLoader.java b/src/main/java/net/minestom/server/instance/MinestomBasicChunkLoader.java index cb64c6df9..33d2962cf 100644 --- a/src/main/java/net/minestom/server/instance/MinestomBasicChunkLoader.java +++ b/src/main/java/net/minestom/server/instance/MinestomBasicChunkLoader.java @@ -5,7 +5,6 @@ import net.minestom.server.storage.StorageFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; import java.util.function.Consumer; public class MinestomBasicChunkLoader implements IChunkLoader { @@ -27,18 +26,14 @@ public class MinestomBasicChunkLoader implements IChunkLoader { final int chunkX = chunk.getChunkX(); final int chunkZ = chunk.getChunkZ(); - try { - final String key = getChunkKey(chunkX, chunkZ); - final byte[] data = chunk.getSerializedData(); - if (data == null) - return; - storageFolder.set(key, data); + final String key = getChunkKey(chunkX, chunkZ); + final byte[] data = chunk.getSerializedData(); + if (data == null) + return; + storageFolder.set(key, data); - if (callback != null) - callback.run(); - } catch (IOException e) { - e.printStackTrace(); - } + if (callback != null) + callback.run(); } @Override diff --git a/src/main/java/net/minestom/server/network/PacketProcessor.java b/src/main/java/net/minestom/server/network/PacketProcessor.java index 4fcb91e2b..33d25b09f 100644 --- a/src/main/java/net/minestom/server/network/PacketProcessor.java +++ b/src/main/java/net/minestom/server/network/PacketProcessor.java @@ -5,7 +5,6 @@ import io.netty.channel.socket.SocketChannel; import net.minestom.server.MinecraftServer; import net.minestom.server.entity.Player; import net.minestom.server.network.netty.packet.InboundPacket; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.network.packet.client.ClientPreplayPacket; import net.minestom.server.network.packet.client.handler.ClientLoginPacketsHandler; @@ -14,6 +13,7 @@ import net.minestom.server.network.packet.client.handler.ClientStatusPacketsHand import net.minestom.server.network.packet.client.handshake.HandshakePacket; import net.minestom.server.network.player.NettyPlayerConnection; import net.minestom.server.network.player.PlayerConnection; +import net.minestom.server.utils.binary.BinaryReader; import java.util.Arrays; import java.util.List; @@ -55,13 +55,13 @@ public class PacketProcessor { //System.out.println("RECEIVED ID: 0x" + Integer.toHexString(id) + " State: " + connectionState); //} - PacketReader packetReader = new PacketReader(packet.body); + BinaryReader binaryReader = new BinaryReader(packet.body); if (connectionState == ConnectionState.UNKNOWN) { // Should be handshake packet if (packet.packetId == 0) { HandshakePacket handshakePacket = new HandshakePacket(); - handshakePacket.read(packetReader); + handshakePacket.read(binaryReader); handshakePacket.process(playerConnection, connectionManager); } return; @@ -71,17 +71,17 @@ public class PacketProcessor { case PLAY: final Player player = playerConnection.getPlayer(); ClientPlayPacket playPacket = (ClientPlayPacket) playPacketsHandler.getPacketInstance(packet.packetId); - playPacket.read(packetReader); + playPacket.read(binaryReader); player.addPacketToQueue(playPacket); break; case LOGIN: final ClientPreplayPacket loginPacket = (ClientPreplayPacket) loginPacketsHandler.getPacketInstance(packet.packetId); - loginPacket.read(packetReader); + loginPacket.read(binaryReader); loginPacket.process(playerConnection, connectionManager); break; case STATUS: final ClientPreplayPacket statusPacket = (ClientPreplayPacket) statusPacketsHandler.getPacketInstance(packet.packetId); - statusPacket.read(packetReader); + statusPacket.read(binaryReader); statusPacket.process(playerConnection, connectionManager); break; diff --git a/src/main/java/net/minestom/server/network/packet/client/ClientPacket.java b/src/main/java/net/minestom/server/network/packet/client/ClientPacket.java index 9b62dee5e..b7b81d02e 100644 --- a/src/main/java/net/minestom/server/network/packet/client/ClientPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/ClientPacket.java @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.client; -import net.minestom.server.network.packet.PacketReader; +import net.minestom.server.utils.binary.BinaryReader; public interface ClientPacket { - void read(PacketReader reader); + void read(BinaryReader reader); } diff --git a/src/main/java/net/minestom/server/network/packet/client/handshake/HandshakePacket.java b/src/main/java/net/minestom/server/network/packet/client/handshake/HandshakePacket.java index efe9a6a68..89c84ec92 100644 --- a/src/main/java/net/minestom/server/network/packet/client/handshake/HandshakePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/handshake/HandshakePacket.java @@ -5,10 +5,10 @@ import net.minestom.server.chat.ChatColor; import net.minestom.server.chat.ColoredText; import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.ConnectionState; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPreplayPacket; import net.minestom.server.network.packet.server.login.LoginDisconnect; import net.minestom.server.network.player.PlayerConnection; +import net.minestom.server.utils.binary.BinaryReader; public class HandshakePacket implements ClientPreplayPacket { @@ -18,7 +18,7 @@ public class HandshakePacket implements ClientPreplayPacket { private int nextState; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.protocolVersion = reader.readVarInt(); this.serverAddress = reader.readSizedString(); this.serverPort = reader.readUnsignedShort(); diff --git a/src/main/java/net/minestom/server/network/packet/client/login/EncryptionResponsePacket.java b/src/main/java/net/minestom/server/network/packet/client/login/EncryptionResponsePacket.java index 7268b8dac..660d6d2a2 100644 --- a/src/main/java/net/minestom/server/network/packet/client/login/EncryptionResponsePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/login/EncryptionResponsePacket.java @@ -7,11 +7,11 @@ import net.minestom.server.data.type.array.ByteArrayData; import net.minestom.server.extras.mojangAuth.MojangCrypt; import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.ConnectionState; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPreplayPacket; import net.minestom.server.network.packet.server.login.LoginSuccessPacket; import net.minestom.server.network.player.NettyPlayerConnection; import net.minestom.server.network.player.PlayerConnection; +import net.minestom.server.utils.binary.BinaryReader; import javax.crypto.SecretKey; import java.math.BigInteger; @@ -58,7 +58,7 @@ public class EncryptionResponsePacket implements ClientPreplayPacket { } @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { sharedSecret = ByteArrayData.decodeByteArray(reader); verifyToken = ByteArrayData.decodeByteArray(reader); } diff --git a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java index 8d16896bc..4f8086fa7 100644 --- a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java @@ -6,12 +6,12 @@ import net.minestom.server.chat.ColoredText; import net.minestom.server.extras.MojangAuth; import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.ConnectionState; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPreplayPacket; import net.minestom.server.network.packet.server.login.EncryptionRequestPacket; import net.minestom.server.network.packet.server.login.LoginDisconnect; import net.minestom.server.network.packet.server.login.LoginSuccessPacket; import net.minestom.server.network.player.PlayerConnection; +import net.minestom.server.utils.binary.BinaryReader; import java.util.UUID; @@ -53,7 +53,7 @@ public class LoginStartPacket implements ClientPreplayPacket { } @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.username = reader.readSizedString(); } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientAdvancementTabPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientAdvancementTabPacket.java index 02c2123a0..8fe71a9cf 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientAdvancementTabPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientAdvancementTabPacket.java @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.advancements.AdvancementAction; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientAdvancementTabPacket extends ClientPlayPacket { @@ -10,7 +10,7 @@ public class ClientAdvancementTabPacket extends ClientPlayPacket { public String tabIdentifier; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.action = AdvancementAction.values()[reader.readVarInt()]; if (action == AdvancementAction.OPENED_TAB) { diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientAnimationPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientAnimationPacket.java index 4c5eda5aa..4647f7e1a 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientAnimationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientAnimationPacket.java @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.entity.Player; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientAnimationPacket extends ClientPlayPacket { public Player.Hand hand; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.hand = Player.Hand.values()[reader.readVarInt()]; } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientChatMessagePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientChatMessagePacket.java index eb1467e8d..af407b8bd 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientChatMessagePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientChatMessagePacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientChatMessagePacket extends ClientPlayPacket { public String message; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.message = reader.readSizedString(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowButtonPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowButtonPacket.java index d0de8ab10..e681e2aa6 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowButtonPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowButtonPacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientClickWindowButtonPacket extends ClientPlayPacket { @@ -9,7 +9,7 @@ public class ClientClickWindowButtonPacket extends ClientPlayPacket { public byte buttonId; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.windowId = reader.readByte(); this.buttonId = reader.readByte(); } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowPacket.java index 1d094337b..0ee976971 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowPacket.java @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientClickWindowPacket extends ClientPlayPacket { @@ -14,7 +14,7 @@ public class ClientClickWindowPacket extends ClientPlayPacket { public ItemStack item; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.windowId = reader.readByte(); this.slot = reader.readShort(); this.button = reader.readByte(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientCloseWindow.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientCloseWindow.java index 7798eeeea..14b5c9caf 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientCloseWindow.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientCloseWindow.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientCloseWindow extends ClientPlayPacket { public int windowId; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.windowId = reader.readVarInt(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientCraftRecipeRequest.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientCraftRecipeRequest.java index b19517993..2d238c952 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientCraftRecipeRequest.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientCraftRecipeRequest.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientCraftRecipeRequest extends ClientPlayPacket { @@ -10,7 +10,7 @@ public class ClientCraftRecipeRequest extends ClientPlayPacket { public boolean makeAll; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.windowId = reader.readByte(); this.recipe = reader.readSizedString(); this.makeAll = reader.readBoolean(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientCreativeInventoryActionPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientCreativeInventoryActionPacket.java index 6f5783b9f..59da51cf6 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientCreativeInventoryActionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientCreativeInventoryActionPacket.java @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientCreativeInventoryActionPacket extends ClientPlayPacket { @@ -10,7 +10,7 @@ public class ClientCreativeInventoryActionPacket extends ClientPlayPacket { public ItemStack item; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.slot = reader.readShort(); this.item = reader.readSlot(); } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientEntityActionPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientEntityActionPacket.java index 2008b996c..247358f74 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientEntityActionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientEntityActionPacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientEntityActionPacket extends ClientPlayPacket { @@ -10,7 +10,7 @@ public class ClientEntityActionPacket extends ClientPlayPacket { public int horseJumpBoost; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.playerId = reader.readVarInt(); this.action = Action.values()[reader.readVarInt()]; this.horseJumpBoost = reader.readVarInt(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientHeldItemChangePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientHeldItemChangePacket.java index 8120cdd66..cb2368e9d 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientHeldItemChangePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientHeldItemChangePacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientHeldItemChangePacket extends ClientPlayPacket { public short slot; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.slot = reader.readShort(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientInteractEntityPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientInteractEntityPacket.java index 21b34c613..23e84079a 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientInteractEntityPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientInteractEntityPacket.java @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.entity.Player; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientInteractEntityPacket extends ClientPlayPacket { @@ -15,7 +15,7 @@ public class ClientInteractEntityPacket extends ClientPlayPacket { public boolean sneaking; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.targetId = reader.readVarInt(); this.type = Type.values()[reader.readVarInt()]; diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientKeepAlivePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientKeepAlivePacket.java index 0f848d2e6..24fbc4a47 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientKeepAlivePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientKeepAlivePacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientKeepAlivePacket extends ClientPlayPacket { public long id; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.id = reader.readLong(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientNameItemPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientNameItemPacket.java index caf6774f2..abd27da24 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientNameItemPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientNameItemPacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientNameItemPacket extends ClientPlayPacket { public String itemName; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.itemName = reader.readSizedString(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPickItemPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPickItemPacket.java index f0c575bf7..6dc0661ee 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPickItemPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPickItemPacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPickItemPacket extends ClientPlayPacket { public int slotToUse; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.slotToUse = reader.readVarInt(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerAbilitiesPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerAbilitiesPacket.java index b7d8121cc..c59d4baa9 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerAbilitiesPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerAbilitiesPacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPlayerAbilitiesPacket extends ClientPlayPacket { public byte flags; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.flags = reader.readByte(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerBlockPlacementPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerBlockPlacementPacket.java index 4b07496fb..d72b4340f 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerBlockPlacementPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerBlockPlacementPacket.java @@ -2,9 +2,9 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.entity.Player; import net.minestom.server.instance.block.BlockFace; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.utils.BlockPosition; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPlayerBlockPlacementPacket extends ClientPlayPacket { @@ -15,7 +15,7 @@ public class ClientPlayerBlockPlacementPacket extends ClientPlayPacket { public boolean insideBlock; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.hand = Player.Hand.values()[reader.readVarInt()]; this.blockPosition = reader.readBlockPosition(); this.blockFace = BlockFace.values()[reader.readVarInt()]; diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerDiggingPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerDiggingPacket.java index cff6327f6..f26b1cd0f 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerDiggingPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerDiggingPacket.java @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.instance.block.BlockFace; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.utils.BlockPosition; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPlayerDiggingPacket extends ClientPlayPacket { @@ -12,7 +12,7 @@ public class ClientPlayerDiggingPacket extends ClientPlayPacket { public BlockFace blockFace; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.status = Status.values()[reader.readVarInt()]; this.blockPosition = reader.readBlockPosition(); this.blockFace = BlockFace.values()[reader.readVarInt()]; diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPacket.java index fcc0bdd2f..dd6c19ce4 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPlayerPacket extends ClientPlayPacket { public boolean onGround; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.onGround = reader.readBoolean(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPositionAndRotationPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPositionAndRotationPacket.java index d5e051306..ccc238d06 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPositionAndRotationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPositionAndRotationPacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPlayerPositionAndRotationPacket extends ClientPlayPacket { @@ -10,7 +10,7 @@ public class ClientPlayerPositionAndRotationPacket extends ClientPlayPacket { public boolean onGround; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.x = reader.readDouble(); this.y = reader.readDouble(); this.z = reader.readDouble(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPositionPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPositionPacket.java index 1a02e3555..456a02edf 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPositionPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerPositionPacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPlayerPositionPacket extends ClientPlayPacket { @@ -9,7 +9,7 @@ public class ClientPlayerPositionPacket extends ClientPlayPacket { public boolean onGround; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.x = reader.readDouble(); this.y = reader.readDouble(); this.z = reader.readDouble(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerRotationPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerRotationPacket.java index fe5e422a7..54ad9a564 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerRotationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPlayerRotationPacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPlayerRotationPacket extends ClientPlayPacket { @@ -9,7 +9,7 @@ public class ClientPlayerRotationPacket extends ClientPlayPacket { public boolean onGround; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.yaw = reader.readFloat(); this.pitch = reader.readFloat(); this.onGround = reader.readBoolean(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientPluginMessagePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientPluginMessagePacket.java index 11fb15e72..a136a858c 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientPluginMessagePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientPluginMessagePacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientPluginMessagePacket extends ClientPlayPacket { @@ -9,7 +9,7 @@ public class ClientPluginMessagePacket extends ClientPlayPacket { public byte[] data; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.channel = reader.readSizedString(); this.data = reader.getRemainingBytes(); } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientRecipeBookData.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientRecipeBookData.java index 14ce2f32d..f4ee00e37 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientRecipeBookData.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientRecipeBookData.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientRecipeBookData extends ClientPlayPacket { @@ -19,7 +19,7 @@ public class ClientRecipeBookData extends ClientPlayPacket { public boolean smokingRecipeFilterActive; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.type = reader.readVarInt(); switch (type) { diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientResourcePackStatusPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientResourcePackStatusPacket.java index 2a5fb3de8..98be3ef53 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientResourcePackStatusPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientResourcePackStatusPacket.java @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.resourcepack.ResourcePackStatus; +import net.minestom.server.utils.binary.BinaryReader; public class ClientResourcePackStatusPacket extends ClientPlayPacket { public ResourcePackStatus result; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.result = ResourcePackStatus.values()[reader.readVarInt()]; } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientSelectTradePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientSelectTradePacket.java index c93e077f3..351ab40ff 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientSelectTradePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientSelectTradePacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientSelectTradePacket extends ClientPlayPacket { public int selectedSlot; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.selectedSlot = reader.readVarInt(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientSettingsPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientSettingsPacket.java index df0d81dc3..e521ea519 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientSettingsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientSettingsPacket.java @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.entity.Player; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientSettingsPacket extends ClientPlayPacket { @@ -14,7 +14,7 @@ public class ClientSettingsPacket extends ClientPlayPacket { public Player.MainHand mainHand; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.locale = reader.readSizedString(); this.viewDistance = reader.readByte(); this.chatMode = Player.ChatMode.values()[reader.readVarInt()]; diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientSpectatePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientSpectatePacket.java index 8408ec6e9..d0b9dfe7e 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientSpectatePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientSpectatePacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; import java.util.UUID; @@ -10,7 +10,7 @@ public class ClientSpectatePacket extends ClientPlayPacket { public UUID targetUuid; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { // TODO reader uuid } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientStatusPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientStatusPacket.java index f2b0b8ec7..6c020cc7b 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientStatusPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientStatusPacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientStatusPacket extends ClientPlayPacket { public Action action; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.action = Action.values()[reader.readVarInt()]; } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientSteerBoatPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientSteerBoatPacket.java index 272693471..4c49d3390 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientSteerBoatPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientSteerBoatPacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientSteerBoatPacket extends ClientPlayPacket { @@ -9,7 +9,7 @@ public class ClientSteerBoatPacket extends ClientPlayPacket { public boolean rightPaddleTurning; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.leftPaddleTurning = reader.readBoolean(); this.rightPaddleTurning = reader.readBoolean(); } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientSteerVehiclePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientSteerVehiclePacket.java index 66742a4b2..8332885ca 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientSteerVehiclePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientSteerVehiclePacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientSteerVehiclePacket extends ClientPlayPacket { @@ -10,7 +10,7 @@ public class ClientSteerVehiclePacket extends ClientPlayPacket { public byte flags; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.sideways = reader.readFloat(); this.forward = reader.readFloat(); this.flags = reader.readByte(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientTabCompletePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientTabCompletePacket.java index f92d6c25b..a76f9e7cb 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientTabCompletePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientTabCompletePacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientTabCompletePacket extends ClientPlayPacket { @@ -9,7 +9,7 @@ public class ClientTabCompletePacket extends ClientPlayPacket { public String text; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.transactionId = reader.readVarInt(); this.text = reader.readSizedString(); } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientTeleportConfirmPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientTeleportConfirmPacket.java index 5f485b6c5..30e348efa 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientTeleportConfirmPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientTeleportConfirmPacket.java @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientTeleportConfirmPacket extends ClientPlayPacket { public int teleportId; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.teleportId = reader.readVarInt(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateCommandBlockMinecartPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateCommandBlockMinecartPacket.java index 35fd7cae0..0143e3980 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateCommandBlockMinecartPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateCommandBlockMinecartPacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientUpdateCommandBlockMinecartPacket extends ClientPlayPacket { @@ -10,7 +10,7 @@ public class ClientUpdateCommandBlockMinecartPacket extends ClientPlayPacket { public boolean trackOutput; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.entityId = reader.readVarInt(); this.command = reader.readSizedString(); this.trackOutput = reader.readBoolean(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateCommandBlockPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateCommandBlockPacket.java index 23ea4f86e..3eebc7a17 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateCommandBlockPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateCommandBlockPacket.java @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.utils.BlockPosition; +import net.minestom.server.utils.binary.BinaryReader; public class ClientUpdateCommandBlockPacket extends ClientPlayPacket { @@ -12,7 +12,7 @@ public class ClientUpdateCommandBlockPacket extends ClientPlayPacket { public byte flags; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.blockPosition = reader.readBlockPosition(); this.command = reader.readSizedString(); this.mode = Mode.values()[reader.readVarInt()]; diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateSignPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateSignPacket.java index 2c4e00e0a..adf0b15b7 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateSignPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientUpdateSignPacket.java @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.utils.BlockPosition; +import net.minestom.server.utils.binary.BinaryReader; public class ClientUpdateSignPacket extends ClientPlayPacket { @@ -13,7 +13,7 @@ public class ClientUpdateSignPacket extends ClientPlayPacket { public String line4; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.blockPosition = reader.readBlockPosition(); this.line1 = reader.readSizedString(); this.line2 = reader.readSizedString(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientUseItemPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientUseItemPacket.java index 62cede393..3e30c50d8 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientUseItemPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientUseItemPacket.java @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.client.play; import net.minestom.server.entity.Player; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientUseItemPacket extends ClientPlayPacket { public Player.Hand hand; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.hand = Player.Hand.values()[reader.readVarInt()]; } } diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientVehicleMovePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientVehicleMovePacket.java index 6f9a2e62e..f130d6be8 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientVehicleMovePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientVehicleMovePacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientVehicleMovePacket extends ClientPlayPacket { @@ -9,7 +9,7 @@ public class ClientVehicleMovePacket extends ClientPlayPacket { public float yaw, pitch; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.x = reader.readDouble(); this.y = reader.readDouble(); this.z = reader.readDouble(); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientWindowConfirmationPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientWindowConfirmationPacket.java index 3a3c20af3..ac205b62e 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientWindowConfirmationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientWindowConfirmationPacket.java @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.client.play; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; public class ClientWindowConfirmationPacket extends ClientPlayPacket { @@ -10,7 +10,7 @@ public class ClientWindowConfirmationPacket extends ClientPlayPacket { public boolean accepted; @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.windowId = reader.readByte(); this.actionNumber = reader.readShort(); this.accepted = reader.readBoolean(); diff --git a/src/main/java/net/minestom/server/network/packet/client/status/LegacyServerListPingPacket.java b/src/main/java/net/minestom/server/network/packet/client/status/LegacyServerListPingPacket.java index 79966bf5e..21a20d8bb 100644 --- a/src/main/java/net/minestom/server/network/packet/client/status/LegacyServerListPingPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/status/LegacyServerListPingPacket.java @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.client.status; import net.minestom.server.network.ConnectionManager; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPreplayPacket; import net.minestom.server.network.player.PlayerConnection; +import net.minestom.server.utils.binary.BinaryReader; public class LegacyServerListPingPacket implements ClientPreplayPacket { @@ -15,7 +15,7 @@ public class LegacyServerListPingPacket implements ClientPreplayPacket { } @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.payload = reader.readByte(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/status/PingPacket.java b/src/main/java/net/minestom/server/network/packet/client/status/PingPacket.java index 2709f79e8..8771f8a3f 100644 --- a/src/main/java/net/minestom/server/network/packet/client/status/PingPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/status/PingPacket.java @@ -1,10 +1,10 @@ package net.minestom.server.network.packet.client.status; import net.minestom.server.network.ConnectionManager; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPreplayPacket; import net.minestom.server.network.packet.server.status.PongPacket; import net.minestom.server.network.player.PlayerConnection; +import net.minestom.server.utils.binary.BinaryReader; public class PingPacket implements ClientPreplayPacket { @@ -18,7 +18,7 @@ public class PingPacket implements ClientPreplayPacket { } @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { this.number = reader.readLong(); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/status/StatusRequestPacket.java b/src/main/java/net/minestom/server/network/packet/client/status/StatusRequestPacket.java index 39a52d3fb..78cbfc377 100644 --- a/src/main/java/net/minestom/server/network/packet/client/status/StatusRequestPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/status/StatusRequestPacket.java @@ -2,12 +2,12 @@ package net.minestom.server.network.packet.client.status; import net.minestom.server.MinecraftServer; import net.minestom.server.network.ConnectionManager; -import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPreplayPacket; import net.minestom.server.network.packet.server.handshake.ResponsePacket; import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.ping.ResponseData; import net.minestom.server.ping.ResponseDataConsumer; +import net.minestom.server.utils.binary.BinaryReader; public class StatusRequestPacket implements ClientPreplayPacket { @@ -34,7 +34,7 @@ public class StatusRequestPacket implements ClientPreplayPacket { } @Override - public void read(PacketReader reader) { + public void read(BinaryReader reader) { // Empty } } 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 e3771d1c4..cfe05c655 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 @@ -1,10 +1,10 @@ package net.minestom.server.network.packet.server; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryWriter; public interface ServerPacket { - void write(PacketWriter writer); + void write(BinaryWriter writer); int getId(); 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 930f5d630..8b06dd1ea 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 @@ -1,14 +1,14 @@ package net.minestom.server.network.packet.server.handshake; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.utils.binary.BinaryWriter; public class ResponsePacket implements ServerPacket { public String jsonResponse; @Override - public void write(PacketWriter writer) { + public void write(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 6a0f428a3..1788e1ea7 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 @@ -2,9 +2,9 @@ package net.minestom.server.network.packet.server.login; import net.minestom.server.MinecraftServer; import net.minestom.server.data.type.array.ByteArrayData; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.player.PlayerConnection; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.concurrent.ThreadLocalRandom; @@ -18,7 +18,7 @@ public class EncryptionRequestPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeSizedString(""); byte[] publicKey = MinecraftServer.getKeyPair().getPublic().getEncoded(); ByteArrayData.encodeByteArray(writer, publicKey); 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 b01e76f28..a02f264c1 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 @@ -2,9 +2,9 @@ package net.minestom.server.network.packet.server.login; import net.minestom.server.MinecraftServer; import net.minestom.server.entity.GameMode; -import net.minestom.server.network.packet.PacketWriter; 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.jglrxavpok.hephaistos.nbt.NBTCompound; @@ -22,7 +22,7 @@ public class JoinGamePacket implements ServerPacket { public boolean enableRespawnScreen = true; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { int gameModeId = gameMode.getId(); if (gameMode.isHardcore()) gameModeId |= 8; 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 25d053b61..7b9e1d29d 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 @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.server.login; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.utils.binary.BinaryWriter; public class LoginDisconnect implements ServerPacket { private String kickMessage; @@ -11,7 +11,7 @@ public class LoginDisconnect implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(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 701d5d174..67d79bd2b 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 @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.server.login; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.UUID; @@ -16,7 +16,7 @@ public class LoginSuccessPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(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 08fe1d850..4088dc234 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 @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.server.login; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.utils.binary.BinaryWriter; public class SetCompressionPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class SetCompressionPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(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 8abb2bf56..adff1382f 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 @@ -1,10 +1,10 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.client.play.ClientPlayerDiggingPacket; 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; public class AcknowledgePlayerDiggingPacket implements ServerPacket { @@ -14,7 +14,7 @@ public class AcknowledgePlayerDiggingPacket implements ServerPacket { public boolean successful; @Override - public void write(PacketWriter writer) { + public void write(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 682ec621e..823918e61 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 @@ -3,9 +3,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.advancements.FrameType; import net.minestom.server.chat.ColoredText; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class AdvancementsPacket implements ServerPacket { @@ -15,7 +15,7 @@ public class AdvancementsPacket implements ServerPacket { public ProgressMapping[] progressMappings; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeBoolean(resetAdvancements); writer.writeVarInt(advancementMappings.length); @@ -43,7 +43,7 @@ public class AdvancementsPacket implements ServerPacket { public String key; public Advancement value; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeSizedString(key); value.write(writer); } @@ -56,7 +56,7 @@ public class AdvancementsPacket implements ServerPacket { public String[] criterions; public Requirement[] requirements; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { // hasParent writer.writeBoolean(parentIdentifier != null); if (parentIdentifier != null) { @@ -89,7 +89,7 @@ public class AdvancementsPacket implements ServerPacket { public float x; public float y; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeSizedString(title.toString()); writer.writeSizedString(description.toString()); writer.writeItemStack(icon); @@ -108,7 +108,7 @@ public class AdvancementsPacket implements ServerPacket { public String[] requirements; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeVarInt(requirements.length); for (String requirement : requirements) { writer.writeSizedString(requirement); @@ -120,7 +120,7 @@ public class AdvancementsPacket implements ServerPacket { public String key; public AdvancementProgress value; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeSizedString(key); value.write(writer); } @@ -129,7 +129,7 @@ public class AdvancementsPacket implements ServerPacket { public static class AdvancementProgress { public Criteria[] criteria; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeVarInt(criteria.length); for (Criteria criterion : criteria) { criterion.write(writer); @@ -141,7 +141,7 @@ public class AdvancementsPacket implements ServerPacket { public String criterionIdentifier; public CriterionProgress criterionProgress; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeSizedString(criterionIdentifier); criterionProgress.write(writer); } @@ -151,7 +151,7 @@ public class AdvancementsPacket implements ServerPacket { public boolean achieved; public long dateOfAchieving; - private void write(PacketWriter writer) { + private 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 51c6525f6..7813b7713 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class AttachEntityPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class AttachEntityPacket implements ServerPacket { public int holdingEntityId; // Or -1 to detach @Override - public void write(PacketWriter writer) { + public void write(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 e79ef1af0..4d9571e1b 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class BlockActionPacket implements ServerPacket { @@ -13,7 +13,7 @@ public class BlockActionPacket implements ServerPacket { public int blockId; @Override - public void write(PacketWriter writer) { + public void write(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 0ff8dfc16..ec02cb23b 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class BlockBreakAnimationPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class BlockBreakAnimationPacket implements ServerPacket { public byte destroyStage; @Override - public void write(PacketWriter writer) { + public void write(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 6e5e9fec6..d31caaade 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class BlockChangePacket implements ServerPacket { @@ -11,7 +11,7 @@ public class BlockChangePacket implements ServerPacket { public int blockStateId; @Override - public void write(PacketWriter writer) { + public void write(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 0639fdf9d..8df51c76a 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 @@ -3,9 +3,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.bossbar.BarColor; import net.minestom.server.bossbar.BarDivision; import net.minestom.server.chat.ColoredText; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.UUID; @@ -22,7 +22,7 @@ public class BossBarPacket implements ServerPacket { @Override - public void write(PacketWriter writer) { + public void write(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 3253e82f2..8d579a805 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 @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class CameraPacket implements ServerPacket { public int cameraId; @Override - public void write(PacketWriter writer) { + public void write(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 25d7963ca..dbdd8eda1 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class ChangeGameStatePacket implements ServerPacket { @@ -10,7 +10,7 @@ public class ChangeGameStatePacket implements ServerPacket { public float value; @Override - public void write(PacketWriter writer) { + public void write(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 da5a069ec..8b5eee521 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.UUID; @@ -23,7 +23,7 @@ public class ChatMessagePacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(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 7c17a0e5f..545a54dd4 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 @@ -3,18 +3,18 @@ package net.minestom.server.network.packet.server.play; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minestom.server.MinecraftServer; import net.minestom.server.data.Data; -import net.minestom.server.world.biomes.Biome; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.block.BlockManager; import net.minestom.server.instance.block.CustomBlock; -import net.minestom.server.network.packet.PacketWriter; 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.Utils; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.buffer.BufferUtils; import net.minestom.server.utils.buffer.BufferWrapper; import net.minestom.server.utils.chunk.ChunkUtils; +import net.minestom.server.world.biomes.Biome; import org.jglrxavpok.hephaistos.nbt.NBTCompound; import java.util.Set; @@ -41,7 +41,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(PacketWriter writer) { + public void write(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 50d34ed73..b9e0c7f2a 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 @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class CloseWindowPacket implements ServerPacket { public byte windowId; @Override - public void write(PacketWriter writer) { + public void write(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 e356d8695..60150045d 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class CollectItemPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class CollectItemPacket implements ServerPacket { public int pickupItemCount; @Override - public void write(PacketWriter writer) { + public void write(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 5765d601e..6d3238f86 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 @@ -3,9 +3,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.chat.ColoredText; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Player; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.Optional; @@ -48,7 +48,7 @@ public class CombatEventPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(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 3e7ab7a81..589b2663e 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class CraftRecipeResponse implements ServerPacket { @@ -10,7 +10,7 @@ public class CraftRecipeResponse implements ServerPacket { public String recipe; @Override - public void write(PacketWriter writer) { + public void write(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 1b8915d22..ca5558ecf 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -13,7 +13,7 @@ public class DeclareCommandsPacket implements ServerPacket { public int rootIndex; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(nodes.length); for (Node node : nodes) { node.write(writer); @@ -33,10 +33,10 @@ public class DeclareCommandsPacket implements ServerPacket { public int redirectedNode; // Only if flags & 0x08 public String name; // Only for literal and argument public String parser; // Only for argument - public Consumer properties; // Only for argument + public Consumer properties; // Only for argument public String suggestionsType; // Only if flags 0x10 - private void write(PacketWriter writer) { + private 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 e3601fbb6..7e7ddfb0a 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; 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.validate.Check; public class DeclareRecipesPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class DeclareRecipesPacket implements ServerPacket { public Recipe[] recipes; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { Check.notNull(recipes, "Recipes cannot be null!"); writer.writeVarInt(recipes.length); @@ -56,7 +56,7 @@ public class DeclareRecipesPacket implements ServerPacket { public ItemStack result; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeSizedString(recipeType); writer.writeSizedString(recipeId); @@ -104,7 +104,7 @@ public class DeclareRecipesPacket implements ServerPacket { // The count of each item should be 1 public ItemStack[] items; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeVarInt(items.length); for (ItemStack itemStack : items) { writer.writeItemStack(itemStack); 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 da2e90274..167c3ffe9 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 @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class DestroyEntitiesPacket implements ServerPacket { public int[] entityIds; @Override - public void write(PacketWriter writer) { + public void write(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 30054dacb..af3ff4c0d 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 @@ -1,16 +1,16 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.chat.ColoredText; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class DisconnectPacket implements ServerPacket { public ColoredText message; @Override - public void write(PacketWriter writer) { + public void write(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 6d9ccf5cd..491d21c78 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class DisplayScoreboardPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class DisplayScoreboardPacket implements ServerPacket { public String scoreName; @Override - public void write(PacketWriter writer) { + public void write(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 8616422d4..7b8be55de 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class EffectPacket implements ServerPacket { @@ -13,7 +13,7 @@ public class EffectPacket implements ServerPacket { public boolean disableRelativeVolume; @Override - public void write(PacketWriter writer) { + public void write(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 39c1ae498..0f8b52ae3 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityAnimationPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class EntityAnimationPacket implements ServerPacket { public Animation animation; @Override - public void write(PacketWriter writer) { + public void write(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 a739045e6..6b7db8448 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityEffectPacket implements ServerPacket { @@ -13,7 +13,7 @@ public class EntityEffectPacket implements ServerPacket { public byte flags; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeByte(effectId); 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 5c44cf250..52ea68526 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 @@ -2,9 +2,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.event.item.ArmorEquipEvent; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityEquipmentPacket implements ServerPacket { @@ -13,7 +13,7 @@ public class EntityEquipmentPacket implements ServerPacket { public ItemStack[] itemStacks; @Override - public void write(PacketWriter writer) { + public void write(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 2273b21b6..f42652888 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityHeadLookPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class EntityHeadLookPacket implements ServerPacket { public float yaw; @Override - public void write(PacketWriter writer) { + public void write(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 61b39a8d3..732d6595d 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 @@ -1,18 +1,18 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; public class EntityMetaDataPacket implements ServerPacket { public int entityId; - public Consumer consumer; + public Consumer consumer; @Override - public void write(PacketWriter writer) { + public void write(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 c19eb9e34..6a4f02ad9 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 @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityPacket implements ServerPacket { public int entityId; @Override - public void write(PacketWriter writer) { + public void write(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 afb3eaa4a..0f0f208df 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityPositionAndRotationPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class EntityPositionAndRotationPacket implements ServerPacket { public boolean onGround; @Override - public void write(PacketWriter writer) { + public void write(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 673f7ab53..7819c36b5 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityPositionPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class EntityPositionPacket implements ServerPacket { public boolean onGround; @Override - public void write(PacketWriter writer) { + public void write(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 6c964886b..e2bbe2297 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.attribute.Attribute; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityPropertiesPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class EntityPropertiesPacket implements ServerPacket { @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeInt(properties.length); for (Property property : properties) { @@ -30,7 +30,7 @@ public class EntityPropertiesPacket implements ServerPacket { public Attribute attribute; public double value; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { float maxValue = attribute.getMaxVanillaValue(); // Bypass vanilla limit client-side if needed (by sending the max value allowed) 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 b28aec6c4..1992e0c38 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityRotationPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class EntityRotationPacket implements ServerPacket { public boolean onGround; @Override - public void write(PacketWriter writer) { + public void write(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 892a90606..58f6b1c70 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class EntitySoundEffect implements ServerPacket { @@ -14,7 +14,7 @@ public class EntitySoundEffect implements ServerPacket { public float pitch; @Override - public void write(PacketWriter writer) { + public void write(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 6ef067543..c2569b39b 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityStatusPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class EntityStatusPacket implements ServerPacket { public byte status; @Override - public void write(PacketWriter writer) { + public void write(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 feda469f5..a68984f7f 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class EntityTeleportPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class EntityTeleportPacket implements ServerPacket { public boolean onGround; @Override - public void write(PacketWriter writer) { + public void write(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 6cb626de8..1f45c26c6 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class EntityVelocityPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class EntityVelocityPacket implements ServerPacket { public short velocityX, velocityY, velocityZ; @Override - public void write(PacketWriter writer) { + public void write(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 25cb5af19..056c80804 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class ExplosionPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class ExplosionPacket implements ServerPacket { public float playerMotionX, playerMotionY, playerMotionZ; @Override - public void write(PacketWriter writer) { + public void write(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 bd390afe3..7efe9caac 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class FacePlayerPacket implements ServerPacket { @@ -13,7 +13,7 @@ public class FacePlayerPacket implements ServerPacket { @Override - public void write(PacketWriter writer) { + public void write(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 85e8cc204..ce4b7225a 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 @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class HeldItemChangePacket implements ServerPacket { public byte slot; @Override - public void write(PacketWriter writer) { + public void write(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 941eef6be..2b1e70f0d 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class KeepAlivePacket implements ServerPacket { @@ -13,7 +13,7 @@ public class KeepAlivePacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(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 e3b87ab81..4592a229b 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.chat.ColoredText; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class MapDataPacket implements ServerPacket { @@ -21,7 +21,7 @@ public class MapDataPacket implements ServerPacket { public byte[] data; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(mapId); writer.writeByte(scale); writer.writeBoolean(trackingPosition); @@ -64,7 +64,7 @@ public class MapDataPacket implements ServerPacket { public byte direction; public ColoredText displayName; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeVarInt(type); writer.writeByte(x); writer.writeByte(z); 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 77f353ecb..0f2efebb2 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class MultiBlockChangePacket implements ServerPacket { @@ -15,7 +15,7 @@ public class MultiBlockChangePacket implements ServerPacket { public BlockChange[] blockChanges; @Override - public void write(PacketWriter writer) { + public void write(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 b7203c533..644b035db 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class NamedSoundEffectPacket implements ServerPacket { @@ -14,7 +14,7 @@ public class NamedSoundEffectPacket implements ServerPacket { public float pitch; @Override - public void write(PacketWriter writer) { + public void write(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 4f8fa2396..88c9f0b54 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 @@ -1,16 +1,16 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.entity.Player; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class OpenBookPacket implements ServerPacket { public Player.Hand hand; @Override - public void write(PacketWriter writer) { + public void write(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 50f40fbd3..edb7fcf0c 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class OpenHorseWindowPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class OpenHorseWindowPacket implements ServerPacket { public int entityId; @Override - public void write(PacketWriter writer) { + public void write(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 61a4373b6..72bd53ef1 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class OpenSignEditorPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class OpenSignEditorPacket implements ServerPacket { public BlockPosition signPosition; @Override - public void write(PacketWriter writer) { + public void write(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 f139a1301..3ff8ab2c4 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class OpenWindowPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class OpenWindowPacket implements ServerPacket { public String title; @Override - public void write(PacketWriter writer) { + public void write(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 1ea10ea3d..88c9f25b2 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -15,10 +15,10 @@ public class ParticlePacket implements ServerPacket { public float particleData; public int particleCount; - public Consumer dataConsumer; + public Consumer dataConsumer; @Override - public void write(PacketWriter writer) { + public void write(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 15c494ebf..49073eb9e 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class PlayerAbilitiesPacket implements ServerPacket { @@ -17,7 +17,7 @@ public class PlayerAbilitiesPacket implements ServerPacket { public float walkingSpeed; @Override - public void write(PacketWriter writer) { + public void write(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 90351f347..ccd9e95ae 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 @@ -2,9 +2,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.chat.ColoredText; import net.minestom.server.entity.GameMode; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.ArrayList; import java.util.UUID; @@ -20,7 +20,7 @@ public class PlayerInfoPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(action.ordinal()); writer.writeVarInt(playerInfos.size()); @@ -63,7 +63,7 @@ public class PlayerInfoPacket implements ServerPacket { this.uuid = uuid; } - public abstract void write(PacketWriter writer); + public abstract void write(BinaryWriter writer); } public static class AddPlayer extends PlayerInfo { @@ -83,7 +83,7 @@ public class PlayerInfoPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeSizedString(name); writer.writeVarInt(properties.size()); for (Property property : properties) { @@ -114,7 +114,7 @@ public class PlayerInfoPacket implements ServerPacket { this(name, value, null); } - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeSizedString(name); writer.writeSizedString(value); @@ -136,7 +136,7 @@ public class PlayerInfoPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(gameMode.getId()); } } @@ -151,7 +151,7 @@ public class PlayerInfoPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(ping); } } @@ -166,7 +166,7 @@ public class PlayerInfoPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { final boolean hasDisplayName = displayName != null; writer.writeBoolean(hasDisplayName); if (hasDisplayName) @@ -181,7 +181,7 @@ public class PlayerInfoPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { } } } 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 b916ab29d..47183eb59 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.chat.ColoredText; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class PlayerListHeaderAndFooterPacket implements ServerPacket { @@ -17,7 +17,7 @@ public class PlayerListHeaderAndFooterPacket implements ServerPacket { @Override - public void write(PacketWriter writer) { + public void write(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 09a12f40f..490669337 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class PlayerPositionAndLookPacket implements ServerPacket { @@ -13,7 +13,7 @@ public class PlayerPositionAndLookPacket implements ServerPacket { @Override - public void write(PacketWriter writer) { + public void write(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 5d2da8164..09b35d1bc 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.MinecraftServer; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class PluginMessagePacket implements ServerPacket { @@ -11,7 +11,7 @@ public class PluginMessagePacket implements ServerPacket { public byte[] data; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeSizedString(channel); writer.writeBytes(data); } @@ -32,7 +32,7 @@ public class PluginMessagePacket implements ServerPacket { PluginMessagePacket brandMessage = new PluginMessagePacket(); brandMessage.channel = "minecraft:brand"; - PacketWriter writer = new PacketWriter(); + BinaryWriter writer = new BinaryWriter(); writer.writeSizedString(MinecraftServer.getBrandName()); brandMessage.data = writer.toByteArray(); 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 379d9ddd1..f7a661fd7 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class RemoveEntityEffectPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class RemoveEntityEffectPacket implements ServerPacket { public byte effectId; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(entityId); writer.writeByte(effectId); } 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 9b35a58b2..5f4e620b1 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class ResourcePackSendPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class ResourcePackSendPacket implements ServerPacket { public String hash; // Size 40 @Override - public void write(PacketWriter writer) { + public void write(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 4eed81405..1af55e873 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.entity.GameMode; -import net.minestom.server.network.packet.PacketWriter; 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; @@ -15,7 +15,7 @@ public class RespawnPacket implements ServerPacket { public LevelType levelType; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { //TODO add api writer.writeSizedString(dimensionType.getName().toString()); 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 46f4969be..3be0a275c 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.chat.ColoredText; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class ScoreboardObjectivePacket implements ServerPacket { @@ -27,7 +27,7 @@ public class ScoreboardObjectivePacket implements ServerPacket { public Type type; @Override - public void write(PacketWriter writer) { + public void write(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 10a819e3e..36de5506f 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class ServerDifficultyPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class ServerDifficultyPacket implements ServerPacket { public boolean locked; @Override - public void write(PacketWriter writer) { + public void write(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 b6b967035..f742de589 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class SetCooldownPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class SetCooldownPacket implements ServerPacket { public int cooldownTicks; @Override - public void write(PacketWriter writer) { + public void write(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 c8b62bb4f..78e51d430 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class SetExperiencePacket implements ServerPacket { @@ -11,7 +11,7 @@ public class SetExperiencePacket implements ServerPacket { public int totalExperience; @Override - public void write(PacketWriter writer) { + public void write(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 c25b1a358..e0ee017de 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class SetPassengersPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class SetPassengersPacket implements ServerPacket { public int[] passengersId; @Override - public void write(PacketWriter writer) { + public void write(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 d0513e35f..aad49ecbd 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class SetSlotPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class SetSlotPacket implements ServerPacket { public ItemStack itemStack; @Override - public void write(PacketWriter writer) { + public void write(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 b876c2bd4..7dfb7d1cb 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 @@ -1,10 +1,10 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; 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; public class SoundEffectPacket implements ServerPacket { @@ -28,7 +28,7 @@ public class SoundEffectPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(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 b6ad1ae41..b54f92259 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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 java.util.UUID; @@ -17,7 +17,7 @@ public class SpawnEntityPacket implements ServerPacket { public short velocityX, velocityY, velocityZ; @Override - public void write(PacketWriter writer) { + public void write(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 57d034b56..e708c9c6b 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class SpawnExperienceOrbPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class SpawnExperienceOrbPacket implements ServerPacket { public short expCount; @Override - public void write(PacketWriter writer) { + public void write(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 529ff1f5c..be8e6b0f0 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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 java.util.UUID; @@ -17,7 +17,7 @@ public class SpawnLivingEntityPacket implements ServerPacket { public short velocityX, velocityY, velocityZ; @Override - public void write(PacketWriter writer) { + public void write(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 d8f4bec7d..00392b3f4 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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 java.util.UUID; @@ -16,7 +16,7 @@ public class SpawnPaintingPacket implements ServerPacket { public byte direction; @Override - public void write(PacketWriter writer) { + public void write(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 1347e20d8..b3e8bdba1 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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 java.util.UUID; @@ -14,7 +14,7 @@ public class SpawnPlayerPacket implements ServerPacket { public Position position; @Override - public void write(PacketWriter writer) { + public void write(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 0a9f7cc3f..f5b648baa 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 @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class SpawnPositionPacket implements ServerPacket { public int x, y, z; @Override - public void write(PacketWriter writer) { + public void write(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 606b4619f..3db1b71a2 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 @@ -1,16 +1,16 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; 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; public class StatisticsPacket implements ServerPacket { public Statistic[] statistics; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(statistics.length); for (Statistic statistic : statistics) { statistic.write(writer); @@ -28,7 +28,7 @@ public class StatisticsPacket implements ServerPacket { public int statisticId; public int value; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { writer.writeVarInt(category.ordinal()); writer.writeVarInt(statisticId); writer.writeVarInt(value); 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 e13f52383..7c1fb88ca 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class StopSoundPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class StopSoundPacket implements ServerPacket { public String sound; @Override - public void write(PacketWriter writer) { + public void write(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 4dcc96b3c..5fa478b0f 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.chat.ColoredText; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class TabCompletePacket implements ServerPacket { @@ -13,7 +13,7 @@ public class TabCompletePacket implements ServerPacket { public Match[] matches; @Override - public void write(PacketWriter writer) { + public void write(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 2f97da3ba..07427ea82 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 @@ -1,11 +1,11 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.gamedata.tags.Tag; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; 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 java.util.LinkedList; import java.util.List; @@ -20,14 +20,14 @@ public class TagsPacket implements ServerPacket { public List entityTags = new LinkedList<>(); @Override - public void write(PacketWriter writer) { + public void write(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()); writeTags(writer, entityTags, name -> Registries.getEntityType(name).ordinal()); } - private void writeTags(PacketWriter writer, List tags, Function idSupplier) { + private void writeTags(BinaryWriter writer, List tags, Function idSupplier) { writer.writeVarInt(tags.size()); for (Tag tag : tags) { // name 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 7ece592d9..5f43338de 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; /** * The packet creates or updates teams @@ -52,12 +52,12 @@ public class TeamsPacket implements ServerPacket { public String[] entities; /** - * Writes data into the {@link PacketWriter} + * Writes data into the {@link BinaryWriter} * * @param writer The writer to writes */ @Override - public void write(PacketWriter writer) { + public void write(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 2e8ff9ef0..82c11adf5 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class TimeUpdatePacket implements ServerPacket { @@ -10,7 +10,7 @@ public class TimeUpdatePacket implements ServerPacket { public long timeOfDay; @Override - public void write(PacketWriter writer) { + public void write(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 dfa41ef22..dab96275f 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.chat.ColoredText; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class TitlePacket implements ServerPacket { @@ -20,7 +20,7 @@ public class TitlePacket implements ServerPacket { public int fadeOut; @Override - public void write(PacketWriter writer) { + public void write(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 99865c0b1..bbfaf1c23 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class TradeListPacket implements ServerPacket { @@ -15,7 +15,7 @@ public class TradeListPacket implements ServerPacket { public boolean canRestock; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(windowId); writer.writeByte((byte) trades.length); for (Trade trade : trades) { @@ -46,7 +46,7 @@ public class TradeListPacket implements ServerPacket { public int demand; - private void write(PacketWriter writer) { + private void write(BinaryWriter writer) { boolean hasSecondItem = inputItem2 != null; writer.writeItemStack(inputItem1); 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 6d8258456..20d91947b 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 @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class UnloadChunkPacket implements ServerPacket { public int chunkX, chunkZ; @Override - public void write(PacketWriter writer) { + public void write(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 92252d51c..58d466807 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class UnlockRecipesPacket implements ServerPacket { @@ -19,7 +19,7 @@ public class UnlockRecipesPacket implements ServerPacket { public String[] initRecipesId; @Override - public void write(PacketWriter writer) { + public void write(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 a1fb85d22..be300bfa4 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class UpdateHealthPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class UpdateHealthPacket implements ServerPacket { public float foodSaturation; @Override - public void write(PacketWriter writer) { + public void write(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 3c59c8e66..c16935752 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.List; @@ -23,7 +23,7 @@ public class UpdateLightPacket implements ServerPacket { public List blockLight; @Override - public void write(PacketWriter writer) { + public void write(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 88400e55d..c59600f99 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class UpdateScorePacket implements ServerPacket { @@ -12,7 +12,7 @@ public class UpdateScorePacket implements ServerPacket { public int value; @Override - public void write(PacketWriter writer) { + public void write(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 e0a063445..f13c1d65f 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 @@ -1,15 +1,15 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class UpdateViewPositionPacket implements ServerPacket { public int chunkX, chunkZ; @Override - public void write(PacketWriter writer) { + public void write(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 aff06e76c..f84128e2e 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class VehicleMovePacket implements ServerPacket { @@ -10,7 +10,7 @@ public class VehicleMovePacket implements ServerPacket { public float yaw, pitch; @Override - public void write(PacketWriter writer) { + public void write(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 1fc11db89..e342143af 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class WindowConfirmationPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class WindowConfirmationPacket implements ServerPacket { public boolean accepted; @Override - public void write(PacketWriter writer) { + public void write(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 8b64632fe..a2cf1dd6b 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 @@ -1,9 +1,9 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.item.ItemStack; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class WindowItemsPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class WindowItemsPacket implements ServerPacket { public ItemStack[] items; @Override - public void write(PacketWriter writer) { + public void write(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 de87d49d5..15cb21d48 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class WindowPropertyPacket implements ServerPacket { @@ -11,7 +11,7 @@ public class WindowPropertyPacket implements ServerPacket { public short value; @Override - public void write(PacketWriter writer) { + public void write(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 e14d11e8e..d2da5fd27 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 @@ -1,8 +1,8 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; public class WorldBorderPacket implements ServerPacket { @@ -10,7 +10,7 @@ public class WorldBorderPacket implements ServerPacket { public WBAction wbAction; @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(action.ordinal()); wbAction.write(writer); } @@ -30,7 +30,7 @@ public class WorldBorderPacket implements ServerPacket { } public static abstract class WBAction { - public abstract void write(PacketWriter writer); + public abstract void write(BinaryWriter writer); } public static class WBSetSize extends WBAction { @@ -42,7 +42,7 @@ public class WorldBorderPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeDouble(diameter); } } @@ -60,7 +60,7 @@ public class WorldBorderPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeDouble(oldDiameter); writer.writeDouble(newDiameter); writer.writeVarLong(speed); @@ -77,7 +77,7 @@ public class WorldBorderPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeDouble(x); writer.writeDouble(z); } @@ -106,7 +106,7 @@ public class WorldBorderPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeDouble(x); writer.writeDouble(z); writer.writeDouble(oldDiameter); @@ -127,7 +127,7 @@ public class WorldBorderPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(warningTime); } } @@ -141,7 +141,7 @@ public class WorldBorderPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeVarInt(warningBlocks); } } 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 2b0494d5c..a0cbf76c1 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 @@ -1,7 +1,7 @@ package net.minestom.server.network.packet.server.status; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.utils.binary.BinaryWriter; public class PongPacket implements ServerPacket { @@ -12,7 +12,7 @@ public class PongPacket implements ServerPacket { } @Override - public void write(PacketWriter writer) { + public void write(BinaryWriter writer) { writer.writeLong(number); } diff --git a/src/main/java/net/minestom/server/particle/ParticleCreator.java b/src/main/java/net/minestom/server/particle/ParticleCreator.java index 0a6eab60b..06866189b 100644 --- a/src/main/java/net/minestom/server/particle/ParticleCreator.java +++ b/src/main/java/net/minestom/server/particle/ParticleCreator.java @@ -1,7 +1,7 @@ package net.minestom.server.particle; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.play.ParticlePacket; +import net.minestom.server.utils.binary.BinaryWriter; import java.util.function.Consumer; @@ -13,7 +13,7 @@ public class ParticleCreator { public static ParticlePacket createParticlePacket(Particle particle, boolean distance, double x, double y, double z, float offsetX, float offsetY, float offsetZ, - float particleData, int count, Consumer dataWriter) { + float particleData, int count, Consumer dataWriter) { ParticlePacket particlePacket = new ParticlePacket(); particlePacket.particleId = particle.getId(); particlePacket.longDistance = distance; diff --git a/src/main/java/net/minestom/server/reader/ChunkReader.java b/src/main/java/net/minestom/server/reader/ChunkReader.java index d3ee417a1..e52c9699d 100644 --- a/src/main/java/net/minestom/server/reader/ChunkReader.java +++ b/src/main/java/net/minestom/server/reader/ChunkReader.java @@ -1,31 +1,31 @@ package net.minestom.server.reader; -import io.netty.buffer.Unpooled; import net.minestom.server.MinecraftServer; import net.minestom.server.data.Data; -import net.minestom.server.instance.DynamicChunk; -import net.minestom.server.world.biomes.Biome; import net.minestom.server.instance.Chunk; +import net.minestom.server.instance.DynamicChunk; import net.minestom.server.instance.Instance; import net.minestom.server.instance.batch.ChunkBatch; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.world.biomes.Biome; +import net.minestom.server.world.biomes.BiomeManager; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.EOFException; -import java.io.IOException; import java.util.function.Consumer; public class ChunkReader { + private static final BiomeManager BIOME_MANAGER = MinecraftServer.getBiomeManager(); + public static void readChunk(byte[] b, Instance instance, int chunkX, int chunkZ, Consumer callback) { - DataInputStream stream = new DataInputStream(new ByteArrayInputStream(b)); + BinaryReader binaryReader = new BinaryReader(b); ChunkBatch chunkBatch = null; try { Biome[] biomes = new Biome[Chunk.BIOME_COUNT]; for (int i = 0; i < biomes.length; i++) { - biomes[i] = MinecraftServer.getBiomeManager().getById(stream.readByte()); + final byte id = binaryReader.readByte(); + biomes[i] = BIOME_MANAGER.getById(id); } final Chunk chunk = new DynamicChunk(biomes, chunkX, chunkZ); @@ -33,21 +33,24 @@ public class ChunkReader { chunkBatch = instance.createChunkBatch(chunk); while (true) { - final int x = stream.readInt(); - final int y = stream.readInt(); - final int z = stream.readInt(); + // Position + final byte x = binaryReader.readByte(); + final short y = binaryReader.readShort(); + final byte z = binaryReader.readByte(); - final short blockStateId = stream.readShort(); - final short customBlockId = stream.readShort(); + // Block type + final short blockStateId = binaryReader.readShort(); + final short customBlockId = binaryReader.readShort(); - final boolean hasData = stream.readBoolean(); + // Data Data data = null; + { + final boolean hasData = binaryReader.readBoolean(); - // Data deserializer - if (hasData) { - final int dataLength = stream.readInt(); - final byte[] dataArray = stream.readNBytes(dataLength); - data = DataReader.readData(Unpooled.wrappedBuffer(dataArray)); + // Data deserializer + if (hasData) { + data = DataReader.readData(binaryReader); + } } if (customBlockId != 0) { @@ -56,10 +59,8 @@ public class ChunkReader { chunkBatch.setBlockStateId(x, y, z, blockStateId, data); } } - } catch (EOFException e) { + } catch (IndexOutOfBoundsException e) { // Finished reading - } catch (IOException e) { - e.printStackTrace(); } chunkBatch.flush(c -> callback.accept(c)); // Success, null if file isn't properly encoded diff --git a/src/main/java/net/minestom/server/reader/DataReader.java b/src/main/java/net/minestom/server/reader/DataReader.java index b747378ee..5441b7d0a 100644 --- a/src/main/java/net/minestom/server/reader/DataReader.java +++ b/src/main/java/net/minestom/server/reader/DataReader.java @@ -1,11 +1,9 @@ package net.minestom.server.reader; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import net.minestom.server.MinecraftServer; import net.minestom.server.data.DataManager; import net.minestom.server.data.SerializableData; -import net.minestom.server.network.packet.PacketReader; +import net.minestom.server.utils.binary.BinaryReader; /** * Class used to convert an array of bytes to a {@link SerializableData} @@ -21,39 +19,32 @@ public class DataReader { *

* WARNING: the {@link DataManager} needs to have all the required types as the {@link SerializableData} has * - * @param buffer the data + * @param reader the reader * @return a {@link SerializableData} based on the data input */ - public static SerializableData readData(ByteBuf buffer) { + public static SerializableData readData(BinaryReader reader) { SerializableData data = new SerializableData(); try { while (true) { - final short typeLength = buffer.readShort(); + final int typeLength = reader.readVarInt(); - if (typeLength == 0xff) { + if (typeLength == 0) { // End of data break; } - byte[] typeCache = new byte[typeLength]; - for (int i = 0; i < typeLength; i++) { - typeCache[i] = buffer.readByte(); + final String className; + { + final byte[] typeCache = reader.readBytes(typeLength); + + className = new String(typeCache); } - final String className = new String(typeCache); final Class type = Class.forName(className); - short nameLength = buffer.readShort(); - byte[] nameCache = new byte[nameLength]; - for (int i = 0; i < nameLength; i++) { - nameCache[i] = buffer.readByte(); - } + final String name = reader.readSizedString(); - final ByteBuf valueCache = buffer.readBytes(buffer.readInt()); - - final String name = new String(nameCache); - PacketReader packetReader = new PacketReader(valueCache); - final Object value = DATA_MANAGER.getDataType(type).decode(packetReader); + final Object value = DATA_MANAGER.getDataType(type).decode(reader); data.set(name, value, type); } @@ -69,10 +60,10 @@ public class DataReader { * * @param data the data * @return a {@link SerializableData} based on the data input - * @see #readData(ByteBuf) + * @see #readData(BinaryReader) */ public static SerializableData readData(byte[] data) { - return readData(Unpooled.wrappedBuffer(data)); + return readData(new BinaryReader(data)); } } diff --git a/src/main/java/net/minestom/server/resourcepack/ResourcePack.java b/src/main/java/net/minestom/server/resourcepack/ResourcePack.java index 0a52d94aa..352776462 100644 --- a/src/main/java/net/minestom/server/resourcepack/ResourcePack.java +++ b/src/main/java/net/minestom/server/resourcepack/ResourcePack.java @@ -7,8 +7,8 @@ import net.minestom.server.utils.validate.Check; */ public class ResourcePack { - private String url; - private String hash; + private final String url; + private final String hash; public ResourcePack(String url, String hash) { Check.notNull(url, "The resource pack url cannot be null"); diff --git a/src/main/java/net/minestom/server/storage/StorageFolder.java b/src/main/java/net/minestom/server/storage/StorageFolder.java index 874aa0393..d7dd0191e 100644 --- a/src/main/java/net/minestom/server/storage/StorageFolder.java +++ b/src/main/java/net/minestom/server/storage/StorageFolder.java @@ -1,17 +1,15 @@ package net.minestom.server.storage; -import io.netty.buffer.Unpooled; import net.minestom.server.MinecraftServer; import net.minestom.server.data.DataContainer; import net.minestom.server.data.DataManager; import net.minestom.server.data.DataType; import net.minestom.server.data.SerializableData; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.reader.DataReader; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.validate.Check; -import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -53,9 +51,9 @@ public class StorageFolder { final DataType dataType = DATA_MANAGER.getDataType(type); Check.notNull(dataType, "You can only save registered DataType type!"); - PacketWriter packetWriter = new PacketWriter(); - dataType.encode(packetWriter, object); // Encode - final byte[] encodedValue = packetWriter.toByteArray(); // Retrieve bytes + BinaryWriter binaryWriter = new BinaryWriter(); + dataType.encode(binaryWriter, object); // Encode + final byte[] encodedValue = binaryWriter.toByteArray(); // Retrieve bytes set(key, encodedValue); } @@ -68,8 +66,8 @@ public class StorageFolder { if (data == null) return null; - PacketReader packetReader = new PacketReader(data); - return dataType.decode(packetReader); + BinaryReader binaryReader = new BinaryReader(data); + return dataType.decode(binaryReader); } public T getOrDefault(String key, Class type, T defaultValue) { @@ -98,7 +96,7 @@ public class StorageFolder { SerializableData data; if (bytes != null) { - data = DataReader.readData(Unpooled.wrappedBuffer(bytes)); + data = DataReader.readData(new BinaryReader(bytes)); } else { data = new SerializableData(); } @@ -131,7 +129,7 @@ public class StorageFolder { SerializableData data; if (bytes != null) { - data = DataReader.readData(Unpooled.wrappedBuffer(bytes)); + data = DataReader.readData(new BinaryReader(bytes)); } else { data = new SerializableData(); } @@ -154,11 +152,8 @@ public class StorageFolder { if (serializableData == null) return; - try { - set(key, serializableData.getSerializedData()); - } catch (IOException e) { - e.printStackTrace(); - } + // Save the data + set(key, serializableData.getSerializedData()); // Remove from map this.cachedData.remove(key); @@ -169,17 +164,10 @@ public class StorageFolder { * Save the whole cached data */ public void saveCachedData() { - try { - synchronized (cachedData) { - for (Map.Entry entry : cachedData.entrySet()) { - final String key = entry.getKey(); - final SerializableData data = entry.getValue(); - - set(key, data.getSerializedData()); - } - } - } catch (IOException e) { - e.printStackTrace(); + synchronized (cachedData) { + cachedData.forEach((key, data) -> { + set(key, data.getSerializedData()); + }); } } @@ -189,13 +177,9 @@ public class StorageFolder { * @param key the data key */ public void saveCachedData(String key) { - try { - synchronized (cachedData) { - final SerializableData data = cachedData.get(key); - set(key, data.getSerializedData()); - } - } catch (IOException e) { - e.printStackTrace(); + synchronized (cachedData) { + final SerializableData data = cachedData.get(key); + set(key, data.getSerializedData()); } } diff --git a/src/main/java/net/minestom/server/utils/NBTUtils.java b/src/main/java/net/minestom/server/utils/NBTUtils.java index 12fb9145d..93b29ea1d 100644 --- a/src/main/java/net/minestom/server/utils/NBTUtils.java +++ b/src/main/java/net/minestom/server/utils/NBTUtils.java @@ -12,9 +12,9 @@ import net.minestom.server.item.NBTConsumer; import net.minestom.server.item.attribute.AttributeSlot; import net.minestom.server.item.attribute.ItemAttribute; import net.minestom.server.item.metadata.ItemMeta; -import net.minestom.server.network.packet.PacketReader; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.registry.Registries; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; import org.jglrxavpok.hephaistos.nbt.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -86,7 +86,7 @@ public final class NBTUtils { nbt.set(listName, enchantList); } - public static ItemStack readItemStack(PacketReader reader) { + public static ItemStack readItemStack(BinaryReader reader) { final boolean present = reader.readBoolean(); if (!present) { @@ -189,7 +189,7 @@ public final class NBTUtils { } } - public static void writeItemStack(PacketWriter packet, ItemStack itemStack) { + public static void writeItemStack(BinaryWriter packet, ItemStack itemStack) { if (itemStack == null || itemStack.isAir()) { packet.writeBoolean(false); } else { diff --git a/src/main/java/net/minestom/server/utils/PacketUtils.java b/src/main/java/net/minestom/server/utils/PacketUtils.java index e7f3bd242..3c261fa22 100644 --- a/src/main/java/net/minestom/server/utils/PacketUtils.java +++ b/src/main/java/net/minestom/server/utils/PacketUtils.java @@ -2,8 +2,8 @@ package net.minestom.server.utils; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.utils.binary.BinaryWriter; /** * Class used to write packets @@ -21,7 +21,7 @@ public final class PacketUtils { * @param packet the packet to write into {@code buf} */ public static void writePacket(ByteBuf buf, ServerPacket packet) { - PacketWriter writer = new PacketWriter(); + BinaryWriter writer = new BinaryWriter(); Utils.writeVarIntBuf(buf, packet.getId()); packet.write(writer); diff --git a/src/main/java/net/minestom/server/utils/Utils.java b/src/main/java/net/minestom/server/utils/Utils.java index 21b75ae5c..bac4cf108 100644 --- a/src/main/java/net/minestom/server/utils/Utils.java +++ b/src/main/java/net/minestom/server/utils/Utils.java @@ -2,7 +2,7 @@ package net.minestom.server.utils; import io.netty.buffer.ByteBuf; import net.minestom.server.instance.Chunk; -import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.buffer.BufferWrapper; public final class Utils { @@ -41,7 +41,7 @@ public final class Utils { } while (value != 0); } - public static void writeVarInt(PacketWriter writer, int value) { + public static void writeVarInt(BinaryWriter writer, int value) { do { byte temp = (byte) (value & 0b01111111); value >>>= 7; @@ -70,7 +70,7 @@ public final class Utils { return result; } - public static void writeVarLong(PacketWriter writer, long value) { + public static void writeVarLong(BinaryWriter writer, long value) { do { byte temp = (byte) (value & 0b01111111); value >>>= 7; diff --git a/src/main/java/net/minestom/server/network/packet/PacketReader.java b/src/main/java/net/minestom/server/utils/binary/BinaryReader.java similarity index 78% rename from src/main/java/net/minestom/server/network/packet/PacketReader.java rename to src/main/java/net/minestom/server/utils/binary/BinaryReader.java index cae009a4d..7da26c1ad 100644 --- a/src/main/java/net/minestom/server/network/packet/PacketReader.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryReader.java @@ -1,4 +1,4 @@ -package net.minestom.server.network.packet; +package net.minestom.server.utils.binary; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -15,16 +15,16 @@ import java.io.IOException; import java.io.InputStream; import java.util.UUID; -public class PacketReader extends InputStream { +public class BinaryReader extends InputStream { private final ByteBuf buffer; private final NBTReader nbtReader = new NBTReader(this, false); - public PacketReader(ByteBuf buffer) { + public BinaryReader(ByteBuf buffer) { this.buffer = buffer; } - public PacketReader(byte[] bytes) { + public BinaryReader(byte[] bytes) { this(Unpooled.wrappedBuffer(bytes)); } @@ -69,39 +69,37 @@ public class PacketReader extends InputStream { } public String readSizedString() { - int length = readVarInt(); - ByteBuf buf = buffer.readBytes(length); - byte[] bytes = new byte[buf.readableBytes()]; - buf.readBytes(bytes); - buf.release(); + final int length = readVarInt(); + final byte[] bytes = readBytes(length); return new String(bytes); } public String readShortSizedString() { - short length = readShort(); - ByteBuf buf = buffer.readBytes(length); - byte[] bytes = new byte[buf.readableBytes()]; - buf.readBytes(bytes); - buf.release(); + final short length = readShort(); + final byte[] bytes = readBytes(length); return new String(bytes); } - public byte[] getRemainingBytes() { - ByteBuf buf = buffer.readBytes(buffer.readableBytes()); + public byte[] readBytes(int length) { + ByteBuf buf = buffer.readBytes(length); byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); buf.release(); return bytes; } + public byte[] getRemainingBytes() { + return readBytes(buffer.readableBytes()); + } + public BlockPosition readBlockPosition() { - long value = buffer.readLong(); + final long value = buffer.readLong(); return SerializerUtils.longToBlockPosition(value); } public UUID readUuid() { - long most = readLong(); - long least = readLong(); + final long most = readLong(); + final long least = readLong(); return new UUID(most, least); } diff --git a/src/main/java/net/minestom/server/network/packet/PacketWriter.java b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java similarity index 55% rename from src/main/java/net/minestom/server/network/packet/PacketWriter.java rename to src/main/java/net/minestom/server/utils/binary/BinaryWriter.java index 33e62c7e1..26581acc7 100644 --- a/src/main/java/net/minestom/server/network/packet/PacketWriter.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java @@ -1,4 +1,4 @@ -package net.minestom.server.network.packet; +package net.minestom.server.utils.binary; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -18,65 +18,150 @@ import java.nio.charset.StandardCharsets; import java.util.UUID; import java.util.function.Consumer; -public class PacketWriter extends OutputStream { +public class BinaryWriter extends OutputStream { - private final ByteBuf buffer = Unpooled.buffer(); + private final ByteBuf buffer; private final NBTWriter nbtWriter = new NBTWriter(this, false); + /** + * Create a {@link BinaryWriter} with a custom initial capacity + * + * @param initialCapacity + */ + public BinaryWriter(int initialCapacity) { + this.buffer = Unpooled.buffer(initialCapacity); + } + + /** + * Create a {@link BinaryWriter} with a "reasonably small initial capacity" + */ + public BinaryWriter() { + this.buffer = Unpooled.buffer(); + } + + /** + * Write a single boolean to the buffer + * + * @param b the boolean to write + */ public void writeBoolean(boolean b) { buffer.writeBoolean(b); } + /** + * Write a single byte to the buffer + * + * @param b the byte to write + */ public void writeByte(byte b) { buffer.writeByte(b); } - public void writeChar(char s) { - buffer.writeChar(s); + /** + * Write a single char to the buffer + * + * @param c the char to write + */ + public void writeChar(char c) { + buffer.writeChar(c); } + /** + * Write a single short to the buffer + * + * @param s the short to write + */ public void writeShort(short s) { buffer.writeShort(s); } + /** + * Write a single int to the buffer + * + * @param i the int to write + */ public void writeInt(int i) { buffer.writeInt(i); } + /** + * Write a single long to the buffer + * + * @param l the long to write + */ public void writeLong(long l) { buffer.writeLong(l); } + /** + * Write a single float to the buffer + * + * @param f the float to write + */ public void writeFloat(float f) { buffer.writeFloat(f); } + /** + * Write a single double to the buffer + * + * @param d the double to write + */ public void writeDouble(double d) { buffer.writeDouble(d); } + /** + * Write a single var-int to the buffer + * + * @param i the int to write + */ public void writeVarInt(int i) { Utils.writeVarInt(this, i); } + /** + * Write a single var-long to the buffer + * + * @param l the long to write + */ public void writeVarLong(long l) { Utils.writeVarLong(this, l); } + /** + * Write a string to the buffer + *

+ * The size is a var-int type + * + * @param string the string to write + */ public void writeSizedString(String string) { - byte[] bytes; - bytes = string.getBytes(StandardCharsets.UTF_8); + final byte[] bytes = string.getBytes(StandardCharsets.UTF_8); writeVarInt(bytes.length); writeBytes(bytes); } + /** + * Write a string to the buffer + *

+ * The size is a short type + * + * @param string the string to write + */ public void writeShortSizedString(String string) { - byte[] bytes; - bytes = string.getBytes(StandardCharsets.UTF_8); + final byte[] bytes = string.getBytes(StandardCharsets.UTF_8); writeShort((short) bytes.length); writeBytes(bytes); } + /** + * Write a var-int array to the buffer + *

+ * It is sized by another var-int at the beginning + * + * @param array the integers to write + */ public void writeVarIntArray(int[] array) { if (array == null) { writeVarInt(0); @@ -88,10 +173,22 @@ public class PacketWriter extends OutputStream { } } + /** + * Write a byte array + * + * @param bytes the byte array to write + */ public void writeBytes(byte[] bytes) { buffer.writeBytes(bytes); } + /** + * Write a string to the buffer + *

+ * The array is sized by a var-int and all strings are wrote using {@link #writeSizedString(String)} + * + * @param array the string array to write + */ public void writeStringArray(String[] array) { if (array == null) { writeVarInt(0); @@ -103,7 +200,12 @@ public class PacketWriter extends OutputStream { } } - public void write(Consumer consumer) { + /** + * Consumer this object to write at a different time + * + * @param consumer the writer consumer + */ + public void write(Consumer consumer) { if (consumer != null) consumer.accept(this); } @@ -117,6 +219,12 @@ public class PacketWriter extends OutputStream { buffer.free(); } + /** + * Write an {@link UUID} + * It is done by writing both long, the most & least significant bits + * + * @param uuid the {@link UUID} to write + */ public void writeUuid(UUID uuid) { writeLong(uuid.getMostSignificantBits()); writeLong(uuid.getLeastSignificantBits()); @@ -143,6 +251,11 @@ public class PacketWriter extends OutputStream { } } + /** + * Convert the internal buffer to a byte array + * + * @return the byte array containing all the {@link BinaryWriter} data + */ public byte[] toByteArray() { byte[] bytes = new byte[buffer.readableBytes()]; final int readerIndex = buffer.readerIndex();