mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Add block face to PlayerBlockPlaceEvent
This commit is contained in:
parent
520c85fcdb
commit
eea0c7e1eb
@ -1,11 +1,12 @@
|
||||
package net.minestom.server.event.player;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
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.coordinate.Point;
|
||||
import net.minestom.server.instance.block.BlockFace;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@ -15,6 +16,7 @@ public class PlayerBlockPlaceEvent implements PlayerEvent, BlockEvent, Cancellab
|
||||
|
||||
private final Player player;
|
||||
private Block block;
|
||||
private final BlockFace blockFace;
|
||||
private final Point blockPosition;
|
||||
private final Player.Hand hand;
|
||||
|
||||
@ -23,9 +25,11 @@ public class PlayerBlockPlaceEvent implements PlayerEvent, BlockEvent, Cancellab
|
||||
private boolean cancelled;
|
||||
|
||||
public PlayerBlockPlaceEvent(@NotNull Player player, @NotNull Block block,
|
||||
@NotNull BlockFace blockFace,
|
||||
@NotNull Point blockPosition, @NotNull Player.Hand hand) {
|
||||
this.player = player;
|
||||
this.block = block;
|
||||
this.blockFace = blockFace;
|
||||
this.blockPosition = blockPosition;
|
||||
this.hand = hand;
|
||||
this.consumeBlock = true;
|
||||
@ -50,6 +54,10 @@ public class PlayerBlockPlaceEvent implements PlayerEvent, BlockEvent, Cancellab
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public @NotNull BlockFace getBlockFace() {
|
||||
return blockFace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block position.
|
||||
*
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.minestom.server.listener;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
@ -24,8 +26,6 @@ import net.minestom.server.network.packet.client.play.ClientPlayerBlockPlacement
|
||||
import net.minestom.server.network.packet.server.play.BlockChangePacket;
|
||||
import net.minestom.server.utils.Direction;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
|
||||
import java.util.Set;
|
||||
@ -139,7 +139,7 @@ public class BlockPlacementListener {
|
||||
|
||||
if (!intersect) {
|
||||
// BlockPlaceEvent check
|
||||
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent(player, placedBlock, placementPosition, packet.hand);
|
||||
PlayerBlockPlaceEvent playerBlockPlaceEvent = new PlayerBlockPlaceEvent(player, placedBlock, blockFace, placementPosition, packet.hand);
|
||||
playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
|
||||
|
||||
EventDispatcher.call(playerBlockPlaceEvent);
|
||||
|
Loading…
Reference in New Issue
Block a user