From 5cb31171e64923d947616379a92c1f376651241c Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Tue, 19 May 2020 17:47:47 +0200 Subject: [PATCH] Remove ReflectASM (no more warning message) --- build.gradle | 1 - .../server/instance/InstanceContainer.java | 1 - .../server/instance/block/CustomBlock.java | 25 ++++--- .../server/network/packet/PacketReader.java | 5 ++ .../handler/ClientLoginPacketsHandler.java | 2 +- .../client/handler/ClientPacketsHandler.java | 15 ++-- .../handler/ClientPlayPacketsHandler.java | 74 +++++++++---------- .../handler/ClientStatusPacketsHandler.java | 4 +- .../server/storage/StorageFolder.java | 4 +- 9 files changed, 70 insertions(+), 61 deletions(-) diff --git a/build.gradle b/build.gradle index 0ae3688e3..1d5f1f464 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,6 @@ dependencies { api group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.0' api 'com.github.Querz:NBT:4.1' - api 'com.esotericsoftware:reflectasm:1.11.9' // https://mvnrepository.com/artifact/com.google.code.gson/gson api group: 'com.google.code.gson', name: 'gson', version: '2.8.5' diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index 90c8f83c2..0508af683 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -161,7 +161,6 @@ public class InstanceContainer extends Instance { } private short executeBlockPlacementRule(short blockId, BlockPosition blockPosition) { - BlockPlacementRule blockPlacementRule = BLOCK_MANAGER.getBlockPlacementRule(blockId); if (blockPlacementRule != null) { return blockPlacementRule.blockRefresh(this, blockPosition); diff --git a/src/main/java/net/minestom/server/instance/block/CustomBlock.java b/src/main/java/net/minestom/server/instance/block/CustomBlock.java index cfca1b26c..472e98d80 100644 --- a/src/main/java/net/minestom/server/instance/block/CustomBlock.java +++ b/src/main/java/net/minestom/server/instance/block/CustomBlock.java @@ -62,7 +62,8 @@ public abstract class CustomBlock { * Called at digging start to check for custom breaking time * Can be set to < 0 to be cancelled, in this case vanilla time will be used * - * @param player the player who is trying to break the block + * @param player the player who is trying to break the block + * @param position * @return the time in ms to break it */ public abstract int getBreakDelay(Player player, BlockPosition position); @@ -78,11 +79,13 @@ public abstract class CustomBlock { /** * Defines custom behaviour for entities touching this block. + * * @param instance * @param position the position at which the block is * @param touching the entity currently touching the block */ - public void handleContact(Instance instance, BlockPosition position, Entity touching) {} + public void handleContact(Instance instance, BlockPosition position, Entity touching) { + } public short getBlockId() { return blockId; @@ -105,19 +108,21 @@ public abstract class CustomBlock { /** * Update this block from a neighbor. By default calls 'update' if directNeighbor is true - * @param instance current instance - * @param thisPosition this block's position + * + * @param instance current instance + * @param thisPosition this block's position * @param neighborPosition the neighboring block which triggered the update - * @param directNeighbor is the neighbor directly connected to this block? (No diagonals) + * @param directNeighbor is the neighbor directly connected to this block? (No diagonals) */ public void updateFromNeighbor(Instance instance, BlockPosition thisPosition, BlockPosition neighborPosition, boolean directNeighbor) { - if(directNeighbor && hasUpdate()) { + if (directNeighbor && hasUpdate()) { update(instance, thisPosition, instance.getBlockData(thisPosition)); } } /** * Called when a scheduled update on this block happens. By default, calls 'update' + * * @param instance * @param position * @param blockData @@ -128,9 +133,11 @@ public abstract class CustomBlock { /** * Allows custom block to write block entity data to a given NBT compound - * @param instance instance of which the block lives - * @param position position of the block + * + * @param instance instance of which the block lives + * @param position position of the block * @param blockData equivalent to
instance.getBlockData(position)
*/ - public void writeBlockEntity(Instance instance, BlockPosition position, Data blockData, CompoundTag nbt) {} + public void writeBlockEntity(Instance instance, BlockPosition position, Data blockData, CompoundTag nbt) { + } } diff --git a/src/main/java/net/minestom/server/network/packet/PacketReader.java b/src/main/java/net/minestom/server/network/packet/PacketReader.java index 2c67fe377..0604c2e04 100644 --- a/src/main/java/net/minestom/server/network/packet/PacketReader.java +++ b/src/main/java/net/minestom/server/network/packet/PacketReader.java @@ -1,6 +1,7 @@ package net.minestom.server.network.packet; import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import net.minestom.server.item.ItemStack; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.SerializerUtils; @@ -14,6 +15,10 @@ public class PacketReader { this.buffer = buffer; } + public PacketReader(byte[] bytes) { + this(Unpooled.wrappedBuffer(bytes)); + } + public int readVarInt() { return Utils.readVarInt(buffer); } diff --git a/src/main/java/net/minestom/server/network/packet/client/handler/ClientLoginPacketsHandler.java b/src/main/java/net/minestom/server/network/packet/client/handler/ClientLoginPacketsHandler.java index ac20b36b4..0eae81993 100644 --- a/src/main/java/net/minestom/server/network/packet/client/handler/ClientLoginPacketsHandler.java +++ b/src/main/java/net/minestom/server/network/packet/client/handler/ClientLoginPacketsHandler.java @@ -5,7 +5,7 @@ import net.minestom.server.network.packet.client.login.LoginStartPacket; public class ClientLoginPacketsHandler extends ClientPacketsHandler { public ClientLoginPacketsHandler() { - register(0, LoginStartPacket.class); + register(0, LoginStartPacket::new); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/handler/ClientPacketsHandler.java b/src/main/java/net/minestom/server/network/packet/client/handler/ClientPacketsHandler.java index 7ab84415d..c79f965df 100644 --- a/src/main/java/net/minestom/server/network/packet/client/handler/ClientPacketsHandler.java +++ b/src/main/java/net/minestom/server/network/packet/client/handler/ClientPacketsHandler.java @@ -1,17 +1,18 @@ package net.minestom.server.network.packet.client.handler; -import com.esotericsoftware.reflectasm.ConstructorAccess; import net.minestom.server.network.packet.client.ClientPacket; +import java.util.function.Supplier; + public class ClientPacketsHandler { // Max packet id private static final int SIZE = 0x2E; - private ConstructorAccess[] constructorAccesses = new ConstructorAccess[SIZE]; + private Supplier[] supplierAccesses = new Supplier[SIZE]; - public void register(int id, Class packet) { - constructorAccesses[id] = ConstructorAccess.get(packet); + public void register(int id, Supplier packetSupplier) { + supplierAccesses[id] = packetSupplier; } public ClientPacket getPacketInstance(int id) { @@ -19,11 +20,11 @@ public class ClientPacketsHandler { if (id > SIZE) throw new IllegalStateException("Packet ID 0x" + Integer.toHexString(id) + " has been tried to be parsed, debug needed"); - ConstructorAccess constructorAccess = constructorAccesses[id]; - if (constructorAccess == null) + Supplier supplier = supplierAccesses[id]; + if (supplierAccesses == null) throw new IllegalStateException("Packet id 0x" + Integer.toHexString(id) + " isn't registered!"); - ClientPacket packet = constructorAccess.newInstance(); + ClientPacket packet = supplier.get(); return packet; } diff --git a/src/main/java/net/minestom/server/network/packet/client/handler/ClientPlayPacketsHandler.java b/src/main/java/net/minestom/server/network/packet/client/handler/ClientPlayPacketsHandler.java index 2e5e29915..07737207b 100644 --- a/src/main/java/net/minestom/server/network/packet/client/handler/ClientPlayPacketsHandler.java +++ b/src/main/java/net/minestom/server/network/packet/client/handler/ClientPlayPacketsHandler.java @@ -5,45 +5,45 @@ import net.minestom.server.network.packet.client.play.*; public class ClientPlayPacketsHandler extends ClientPacketsHandler { public ClientPlayPacketsHandler() { - register(0x00, ClientTeleportConfirmPacket.class); - register(0x03, ClientChatMessagePacket.class); - register(0x04, ClientStatusPacket.class); - register(0x05, ClientSettingsPacket.class); - register(0x06, ClientTabCompletePacket.class); - register(0x07, ClientWindowConfirmationPacket.class); - register(0x08, ClientClickWindowButtonPacket.class); // Marked as 0x07 on wiki.vg - register(0x09, ClientClickWindowPacket.class); - register(0x0A, ClientCloseWindow.class); - register(0x0B, ClientPluginMessagePacket.class); - register(0x0E, ClientInteractEntityPacket.class); - register(0x0F, ClientKeepAlivePacket.class); + register(0x00, ClientTeleportConfirmPacket::new); + register(0x03, ClientChatMessagePacket::new); + register(0x04, ClientStatusPacket::new); + register(0x05, ClientSettingsPacket::new); + register(0x06, ClientTabCompletePacket::new); + register(0x07, ClientWindowConfirmationPacket::new); + register(0x08, ClientClickWindowButtonPacket::new); // Marked as 0x07 on wiki.vg + register(0x09, ClientClickWindowPacket::new); + register(0x0A, ClientCloseWindow::new); + register(0x0B, ClientPluginMessagePacket::new); + register(0x0E, ClientInteractEntityPacket::new); + register(0x0F, ClientKeepAlivePacket::new); // 0x10 packet not used server-side - register(0x11, ClientPlayerPositionPacket.class); - register(0x12, ClientPlayerPositionAndLookPacket.class); - register(0x13, ClientPlayerLookPacket.class); - register(0x14, ClientPlayerPacket.class); - register(0x15, ClientVehicleMovePacket.class); - register(0x16, ClientSteerBoatPacket.class); - register(0x17, ClientPickItemPacket.class); - register(0x18, ClientCraftRecipeRequest.class); - register(0x19, ClientPlayerAbilitiesPacket.class); - register(0x1A, ClientPlayerDiggingPacket.class); - register(0x1B, ClientEntityActionPacket.class); - register(0x1C, ClientSteerVehiclePacket.class); - register(0x1D, ClientRecipeBookData.class); - register(0x1E, ClientNameItemPacket.class); - register(0x1F, ClientResourcePackStatusPacket.class); + register(0x11, ClientPlayerPositionPacket::new); + register(0x12, ClientPlayerPositionAndLookPacket::new); + register(0x13, ClientPlayerLookPacket::new); + register(0x14, ClientPlayerPacket::new); + register(0x15, ClientVehicleMovePacket::new); + register(0x16, ClientSteerBoatPacket::new); + register(0x17, ClientPickItemPacket::new); + register(0x18, ClientCraftRecipeRequest::new); + register(0x19, ClientPlayerAbilitiesPacket::new); + register(0x1A, ClientPlayerDiggingPacket::new); + register(0x1B, ClientEntityActionPacket::new); + register(0x1C, ClientSteerVehiclePacket::new); + register(0x1D, ClientRecipeBookData::new); + register(0x1E, ClientNameItemPacket::new); + register(0x1F, ClientResourcePackStatusPacket::new); - register(0x20, ClientAdvancementTabPacket.class); - register(0x21, ClientSelectTradePacket.class); - register(0x23, ClientHeldItemChangePacket.class); - register(0x24, ClientUpdateCommandBlockPacket.class); - register(0x25, ClientUpdateCommandBlockMinecartPacket.class); - register(0x26, ClientCreativeInventoryActionPacket.class); - register(0x29, ClientUpdateSignPacket.class); - register(0x2A, ClientAnimationPacket.class); - register(0x2C, ClientPlayerBlockPlacementPacket.class); - register(0x2D, ClientUseItemPacket.class); + register(0x20, ClientAdvancementTabPacket::new); + register(0x21, ClientSelectTradePacket::new); + register(0x23, ClientHeldItemChangePacket::new); + register(0x24, ClientUpdateCommandBlockPacket::new); + register(0x25, ClientUpdateCommandBlockMinecartPacket::new); + register(0x26, ClientCreativeInventoryActionPacket::new); + register(0x29, ClientUpdateSignPacket::new); + register(0x2A, ClientAnimationPacket::new); + register(0x2C, ClientPlayerBlockPlacementPacket::new); + register(0x2D, ClientUseItemPacket::new); } } diff --git a/src/main/java/net/minestom/server/network/packet/client/handler/ClientStatusPacketsHandler.java b/src/main/java/net/minestom/server/network/packet/client/handler/ClientStatusPacketsHandler.java index 0bdb770af..27f9869d8 100644 --- a/src/main/java/net/minestom/server/network/packet/client/handler/ClientStatusPacketsHandler.java +++ b/src/main/java/net/minestom/server/network/packet/client/handler/ClientStatusPacketsHandler.java @@ -6,8 +6,8 @@ import net.minestom.server.network.packet.client.status.StatusRequestPacket; public class ClientStatusPacketsHandler extends ClientPacketsHandler { public ClientStatusPacketsHandler() { - register(0x00, StatusRequestPacket.class); - register(0x01, PingPacket.class); + register(0x00, StatusRequestPacket::new); + register(0x01, PingPacket::new); } } diff --git a/src/main/java/net/minestom/server/storage/StorageFolder.java b/src/main/java/net/minestom/server/storage/StorageFolder.java index 2153e7541..344fc14ef 100644 --- a/src/main/java/net/minestom/server/storage/StorageFolder.java +++ b/src/main/java/net/minestom/server/storage/StorageFolder.java @@ -1,6 +1,5 @@ package net.minestom.server.storage; -import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import net.minestom.server.MinecraftServer; import net.minestom.server.data.DataContainer; @@ -70,8 +69,7 @@ public class StorageFolder { if (data == null) return null; - ByteBuf buffer = Unpooled.wrappedBuffer(data); - PacketReader packetReader = new PacketReader(buffer); + PacketReader packetReader = new PacketReader(data); T value = dataType.decode(packetReader); return value; }