From c15a795a740866c3d0002d8d10e307d2eba6d5bd Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Mon, 25 May 2020 15:42:54 +0200 Subject: [PATCH] Minor checks + FakePlayerController#finishDigging --- .../net/minestom/server/entity/fakeplayer/FakePlayer.java | 6 ++++++ .../server/entity/fakeplayer/FakePlayerController.java | 8 ++++++++ src/main/java/net/minestom/server/instance/Instance.java | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java index caeef9efd..7222a608e 100644 --- a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java +++ b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java @@ -29,6 +29,12 @@ public class FakePlayer extends Player { } } + /** + * Create a FakePlayer not registered in {@link ConnectionManager} + * + * @param uuid the player uuid + * @param username the player username + */ public FakePlayer(UUID uuid, String username) { this(uuid, username, false); } diff --git a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayerController.java b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayerController.java index 7e230de36..832926878 100644 --- a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayerController.java +++ b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayerController.java @@ -129,6 +129,14 @@ public class FakePlayerController { addToQueue(playerDiggingPacket); } + public void finishDigging(BlockPosition blockPosition) { + ClientPlayerDiggingPacket playerDiggingPacket = new ClientPlayerDiggingPacket(); + playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.FINISHED_DIGGING; + playerDiggingPacket.blockPosition = blockPosition; + playerDiggingPacket.blockFace = ClientPlayerDiggingPacket.BlockFace.BOTTOM; // TODO not hardcode + addToQueue(playerDiggingPacket); + } + /** * Make the player receives a packet * WARNING: pretty much unsafe, used internally to redirect packets here, diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java index a436660e8..bcc0deaee 100644 --- a/src/main/java/net/minestom/server/instance/Instance.java +++ b/src/main/java/net/minestom/server/instance/Instance.java @@ -114,6 +114,9 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta // protected void sendChunkUpdate(Collection players, Chunk chunk) { + if (ChunkUtils.isChunkUnloaded(this, chunk)) + return; + ByteBuf chunkData = chunk.getFullDataPacket(); players.forEach(player -> { if (!PlayerUtils.isNettyClient(player)) @@ -124,12 +127,17 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta } protected void sendChunkSectionUpdate(Chunk chunk, int section, Collection players) { + if (ChunkUtils.isChunkUnloaded(this, chunk)) + return; + PacketWriterUtils.writeAndSend(players, getChunkSectionUpdatePacket(chunk, section)); } public void sendChunkSectionUpdate(Chunk chunk, int section, Player player) { if (!PlayerUtils.isNettyClient(player)) return; + if (ChunkUtils.isChunkUnloaded(this, chunk)) + return; PacketWriterUtils.writeAndSend(player, getChunkSectionUpdatePacket(chunk, section)); }