Add block face to PlayerBlockPlaceEvent

This commit is contained in:
TheMode 2021-07-13 18:27:45 +02:00
parent 520c85fcdb
commit eea0c7e1eb
2 changed files with 12 additions and 4 deletions

View File

@ -1,11 +1,12 @@
package net.minestom.server.event.player; package net.minestom.server.event.player;
import net.minestom.server.coordinate.Point;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
import net.minestom.server.event.trait.BlockEvent; import net.minestom.server.event.trait.BlockEvent;
import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.event.trait.CancellableEvent;
import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.event.trait.PlayerEvent;
import net.minestom.server.instance.block.Block; 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; import org.jetbrains.annotations.NotNull;
/** /**
@ -15,6 +16,7 @@ public class PlayerBlockPlaceEvent implements PlayerEvent, BlockEvent, Cancellab
private final Player player; private final Player player;
private Block block; private Block block;
private final BlockFace blockFace;
private final Point blockPosition; private final Point blockPosition;
private final Player.Hand hand; private final Player.Hand hand;
@ -23,9 +25,11 @@ public class PlayerBlockPlaceEvent implements PlayerEvent, BlockEvent, Cancellab
private boolean cancelled; private boolean cancelled;
public PlayerBlockPlaceEvent(@NotNull Player player, @NotNull Block block, public PlayerBlockPlaceEvent(@NotNull Player player, @NotNull Block block,
@NotNull BlockFace blockFace,
@NotNull Point blockPosition, @NotNull Player.Hand hand) { @NotNull Point blockPosition, @NotNull Player.Hand hand) {
this.player = player; this.player = player;
this.block = block; this.block = block;
this.blockFace = blockFace;
this.blockPosition = blockPosition; this.blockPosition = blockPosition;
this.hand = hand; this.hand = hand;
this.consumeBlock = true; this.consumeBlock = true;
@ -50,6 +54,10 @@ public class PlayerBlockPlaceEvent implements PlayerEvent, BlockEvent, Cancellab
this.block = block; this.block = block;
} }
public @NotNull BlockFace getBlockFace() {
return blockFace;
}
/** /**
* Gets the block position. * Gets the block position.
* *

View File

@ -1,6 +1,8 @@
package net.minestom.server.listener; package net.minestom.server.listener;
import net.minestom.server.MinecraftServer; 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.Entity;
import net.minestom.server.entity.EntityType; import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.GameMode; 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.network.packet.server.play.BlockChangePacket;
import net.minestom.server.utils.Direction; import net.minestom.server.utils.Direction;
import net.minestom.server.utils.chunk.ChunkUtils; 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 net.minestom.server.utils.validate.Check;
import java.util.Set; import java.util.Set;
@ -139,7 +139,7 @@ public class BlockPlacementListener {
if (!intersect) { if (!intersect) {
// BlockPlaceEvent check // 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); playerBlockPlaceEvent.consumeBlock(player.getGameMode() != GameMode.CREATIVE);
EventDispatcher.call(playerBlockPlaceEvent); EventDispatcher.call(playerBlockPlaceEvent);