From 679030e75b340b28956c9a53e307391245182a8b Mon Sep 17 00:00:00 2001 From: TheMode Date: Mon, 14 Jun 2021 15:30:05 +0200 Subject: [PATCH] Add BlockEvent --- .../server/event/player/PlayerBlockBreakEvent.java | 4 +++- .../server/event/player/PlayerBlockInteractEvent.java | 4 +++- .../server/event/player/PlayerBlockPlaceEvent.java | 4 +++- .../server/event/player/PlayerStartDiggingEvent.java | 4 +++- .../java/net/minestom/server/event/trait/BlockEvent.java | 9 +++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/minestom/server/event/trait/BlockEvent.java diff --git a/src/main/java/net/minestom/server/event/player/PlayerBlockBreakEvent.java b/src/main/java/net/minestom/server/event/player/PlayerBlockBreakEvent.java index bd5ee3ecb..b8d86e7bd 100644 --- a/src/main/java/net/minestom/server/event/player/PlayerBlockBreakEvent.java +++ b/src/main/java/net/minestom/server/event/player/PlayerBlockBreakEvent.java @@ -1,13 +1,14 @@ package net.minestom.server.event.player; import net.minestom.server.entity.Player; +import net.minestom.server.event.trait.BlockEvent; import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.instance.block.Block; import net.minestom.server.utils.BlockPosition; import org.jetbrains.annotations.NotNull; -public class PlayerBlockBreakEvent implements PlayerEvent, CancellableEvent { +public class PlayerBlockBreakEvent implements PlayerEvent, BlockEvent, CancellableEvent { private final Player player; private final Block block; @@ -30,6 +31,7 @@ public class PlayerBlockBreakEvent implements PlayerEvent, CancellableEvent { * * @return the block */ + @Override public @NotNull Block getBlock() { return block; } diff --git a/src/main/java/net/minestom/server/event/player/PlayerBlockInteractEvent.java b/src/main/java/net/minestom/server/event/player/PlayerBlockInteractEvent.java index 76d9480f7..a1e37ce2f 100644 --- a/src/main/java/net/minestom/server/event/player/PlayerBlockInteractEvent.java +++ b/src/main/java/net/minestom/server/event/player/PlayerBlockInteractEvent.java @@ -1,6 +1,7 @@ package net.minestom.server.event.player; import net.minestom.server.entity.Player; +import net.minestom.server.event.trait.BlockEvent; import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.instance.block.Block; @@ -12,7 +13,7 @@ import org.jetbrains.annotations.NotNull; * Called when a player interacts with a block (right-click). * This is also called when a block is placed. */ -public class PlayerBlockInteractEvent implements PlayerEvent, CancellableEvent { +public class PlayerBlockInteractEvent implements PlayerEvent, BlockEvent, CancellableEvent { private final Player player; private final Player.Hand hand; @@ -51,6 +52,7 @@ public class PlayerBlockInteractEvent implements PlayerEvent, CancellableEvent { this.blocksItemUse = blocks; } + @Override public @NotNull Block getBlock() { return block; } diff --git a/src/main/java/net/minestom/server/event/player/PlayerBlockPlaceEvent.java b/src/main/java/net/minestom/server/event/player/PlayerBlockPlaceEvent.java index ce29806f9..be165212f 100644 --- a/src/main/java/net/minestom/server/event/player/PlayerBlockPlaceEvent.java +++ b/src/main/java/net/minestom/server/event/player/PlayerBlockPlaceEvent.java @@ -1,6 +1,7 @@ package net.minestom.server.event.player; import net.minestom.server.entity.Player; +import net.minestom.server.event.trait.BlockEvent; import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.instance.block.Block; @@ -10,7 +11,7 @@ import org.jetbrains.annotations.NotNull; /** * Called when a player tries placing a block. */ -public class PlayerBlockPlaceEvent implements PlayerEvent, CancellableEvent { +public class PlayerBlockPlaceEvent implements PlayerEvent, BlockEvent, CancellableEvent { private final Player player; private Block block; @@ -35,6 +36,7 @@ public class PlayerBlockPlaceEvent implements PlayerEvent, CancellableEvent { * * @return the block to place */ + @Override public @NotNull Block getBlock() { return block; } diff --git a/src/main/java/net/minestom/server/event/player/PlayerStartDiggingEvent.java b/src/main/java/net/minestom/server/event/player/PlayerStartDiggingEvent.java index d53841fbe..b6ead121b 100644 --- a/src/main/java/net/minestom/server/event/player/PlayerStartDiggingEvent.java +++ b/src/main/java/net/minestom/server/event/player/PlayerStartDiggingEvent.java @@ -1,6 +1,7 @@ package net.minestom.server.event.player; import net.minestom.server.entity.Player; +import net.minestom.server.event.trait.BlockEvent; import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.instance.block.Block; @@ -15,7 +16,7 @@ import org.jetbrains.annotations.NotNull; * (could be because of high latency or a modified client) so cancelling {@link PlayerBlockBreakEvent} is also necessary. * Could be fixed in future Minestom version. */ -public class PlayerStartDiggingEvent implements PlayerEvent, CancellableEvent { +public class PlayerStartDiggingEvent implements PlayerEvent, BlockEvent, CancellableEvent { private final Player player; private final Block block; @@ -34,6 +35,7 @@ public class PlayerStartDiggingEvent implements PlayerEvent, CancellableEvent { * * @return the block */ + @Override public @NotNull Block getBlock() { return block; } diff --git a/src/main/java/net/minestom/server/event/trait/BlockEvent.java b/src/main/java/net/minestom/server/event/trait/BlockEvent.java new file mode 100644 index 000000000..6185ee3cb --- /dev/null +++ b/src/main/java/net/minestom/server/event/trait/BlockEvent.java @@ -0,0 +1,9 @@ +package net.minestom.server.event.trait; + +import net.minestom.server.event.Event; +import net.minestom.server.instance.block.Block; +import org.jetbrains.annotations.NotNull; + +public interface BlockEvent extends Event { + @NotNull Block getBlock(); +}