From ad8805b1cbe548095f12f76cf7e57bd652b77484 Mon Sep 17 00:00:00 2001 From: AlicanCopur <37244649+AlicanCopur@users.noreply.github.com> Date: Tue, 5 May 2020 12:05:30 +0300 Subject: [PATCH 1/3] Added call BlockGrowEvent (#1403) Added call BlockGrowEvent in Sugarcane --- src/main/java/cn/nukkit/block/BlockSugarcane.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/cn/nukkit/block/BlockSugarcane.java b/src/main/java/cn/nukkit/block/BlockSugarcane.java index 529700e6163..4948a709b43 100644 --- a/src/main/java/cn/nukkit/block/BlockSugarcane.java +++ b/src/main/java/cn/nukkit/block/BlockSugarcane.java @@ -104,7 +104,12 @@ public int onUpdate(int type) { for (int y = 1; y < 3; ++y) { Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z)); if (b.getId() == AIR) { - this.getLevel().setBlock(b, Block.get(BlockID.SUGARCANE_BLOCK), false); + BlockGrowEvent ev = new BlockGrowEvent(b, Block.get(BlockID.SUGARCANE_BLOCK)); + Server.getInstance().getPluginManager().callEvent(ev); + + if (!ev.isCancelled()) { + this.getLevel().setBlock(b, Block.get(BlockID.SUGARCANE_BLOCK), false); + } break; } } From a71c3525e5db0085f156101823321624b8488365 Mon Sep 17 00:00:00 2001 From: AlicanCopur <37244649+AlicanCopur@users.noreply.github.com> Date: Tue, 5 May 2020 12:33:53 +0300 Subject: [PATCH 2/3] Added PlayerJumpEvent (#1405) * Create PlayerJumpEvent.java * Call PlayerJumpEvent * Removed Cancellable --- src/main/java/cn/nukkit/Player.java | 3 +++ .../cn/nukkit/event/player/PlayerJumpEvent.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/java/cn/nukkit/event/player/PlayerJumpEvent.java diff --git a/src/main/java/cn/nukkit/Player.java b/src/main/java/cn/nukkit/Player.java index 6958440880b..5c7453935a9 100644 --- a/src/main/java/cn/nukkit/Player.java +++ b/src/main/java/cn/nukkit/Player.java @@ -27,6 +27,7 @@ import cn.nukkit.event.player.PlayerAsyncPreLoginEvent.LoginResult; import cn.nukkit.event.player.PlayerInteractEvent.Action; import cn.nukkit.event.player.PlayerTeleportEvent.TeleportCause; +import cn.nukkit.event.player.PlayerJumpEvent; import cn.nukkit.event.server.DataPacketReceiveEvent; import cn.nukkit.event.server.DataPacketSendEvent; import cn.nukkit.form.window.FormWindow; @@ -2485,6 +2486,8 @@ public void onCompletion(Server server) { this.respawn(); break; case PlayerActionPacket.ACTION_JUMP: + PlayerJumpEvent playerJumpEvent = new PlayerJumpEvent(this); + this.server.getPluginManager().callEvent(playerJumpEvent); break packetswitch; case PlayerActionPacket.ACTION_START_SPRINT: PlayerToggleSprintEvent playerToggleSprintEvent = new PlayerToggleSprintEvent(this, true); diff --git a/src/main/java/cn/nukkit/event/player/PlayerJumpEvent.java b/src/main/java/cn/nukkit/event/player/PlayerJumpEvent.java new file mode 100644 index 00000000000..b915ca1d8cb --- /dev/null +++ b/src/main/java/cn/nukkit/event/player/PlayerJumpEvent.java @@ -0,0 +1,16 @@ +package cn.nukkit.event.player; + +import cn.nukkit.Player; +import cn.nukkit.event.HandlerList; + +public class PlayerJumpEvent extends PlayerEvent { + private static final HandlerList handlers = new HandlerList(); + + public static HandlerList getHandlers() { + return handlers; + } + + public PlayerJumpEvent(Player player){ + this.player = player; + } +} From 42fac211c963cc0c07d7f2516df550788cc6027c Mon Sep 17 00:00:00 2001 From: PetteriM1 Date: Wed, 6 May 2020 11:34:48 +0300 Subject: [PATCH 3/3] Fix wrong flags in MoveEntityAbsolutePacket + set onGround (#1410) --- src/main/java/cn/nukkit/level/Level.java | 1 + .../cn/nukkit/network/protocol/MoveEntityAbsolutePacket.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/nukkit/level/Level.java b/src/main/java/cn/nukkit/level/Level.java index a14bb4d4546..1047fb2f137 100644 --- a/src/main/java/cn/nukkit/level/Level.java +++ b/src/main/java/cn/nukkit/level/Level.java @@ -3236,6 +3236,7 @@ public void addEntityMovement(Entity entity, double x, double y, double z, doubl pk.yaw = (float) yaw; pk.headYaw = (float) headYaw; pk.pitch = (float) pitch; + pk.onGround = entity.onGround; Server.broadcastPacket(entity.getViewers().values(), pk); } diff --git a/src/main/java/cn/nukkit/network/protocol/MoveEntityAbsolutePacket.java b/src/main/java/cn/nukkit/network/protocol/MoveEntityAbsolutePacket.java index f79138a8413..b4615cae370 100644 --- a/src/main/java/cn/nukkit/network/protocol/MoveEntityAbsolutePacket.java +++ b/src/main/java/cn/nukkit/network/protocol/MoveEntityAbsolutePacket.java @@ -46,10 +46,10 @@ public void encode() { this.reset(); this.putEntityRuntimeId(this.eid); byte flags = 0; - if (teleport) { + if (onGround) { flags |= 0x01; } - if (onGround) { + if (teleport) { flags |= 0x02; } this.putByte(flags);