Add BlockEvent

This commit is contained in:
TheMode 2021-06-14 15:30:05 +02:00
parent a70fe174bf
commit 679030e75b
5 changed files with 21 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();
}