Make PlayerUseItemOnBlockEvent.getBlockFace() return a BlockFace (#555)

This commit is contained in:
Mrln 2021-12-26 15:00:59 +01:00 committed by TheMode
parent 1a7fece34e
commit 78076e9bc8
2 changed files with 5 additions and 7 deletions

View File

@ -5,8 +5,8 @@ import net.minestom.server.entity.Player;
import net.minestom.server.event.trait.EntityInstanceEvent;
import net.minestom.server.event.trait.ItemEvent;
import net.minestom.server.event.trait.PlayerEvent;
import net.minestom.server.instance.block.BlockFace;
import net.minestom.server.item.ItemStack;
import net.minestom.server.utils.Direction;
import org.jetbrains.annotations.NotNull;
/**
@ -18,11 +18,11 @@ public class PlayerUseItemOnBlockEvent implements PlayerEvent, EntityInstanceEve
private final Player.Hand hand;
private final ItemStack itemStack;
private final Point position;
private final Direction blockFace;
private final BlockFace blockFace;
public PlayerUseItemOnBlockEvent(@NotNull Player player, @NotNull Player.Hand hand,
@NotNull ItemStack itemStack,
@NotNull Point position, @NotNull Direction blockFace) {
@NotNull Point position, @NotNull BlockFace blockFace) {
this.player = player;
this.hand = hand;
this.itemStack = itemStack;
@ -44,7 +44,7 @@ public class PlayerUseItemOnBlockEvent implements PlayerEvent, EntityInstanceEve
*
* @return the block face
*/
public @NotNull Direction getBlockFace() {
public @NotNull BlockFace getBlockFace() {
return blockFace;
}

View File

@ -23,7 +23,6 @@ import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.network.packet.client.play.ClientPlayerBlockPlacementPacket;
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.utils.validate.Check;
@ -37,7 +36,6 @@ public class BlockPlacementListener {
final Player.Hand hand = packet.hand();
final BlockFace blockFace = packet.blockFace();
final Point blockPosition = packet.blockPosition();
final Direction direction = blockFace.toDirection();
final Instance instance = player.getInstance();
if (instance == null)
@ -72,7 +70,7 @@ public class BlockPlacementListener {
final Material useMaterial = usedItem.getMaterial();
if (!useMaterial.isBlock()) {
// Player didn't try to place a block but interacted with one
PlayerUseItemOnBlockEvent event = new PlayerUseItemOnBlockEvent(player, hand, usedItem, blockPosition, direction);
PlayerUseItemOnBlockEvent event = new PlayerUseItemOnBlockEvent(player, hand, usedItem, blockPosition, blockFace);
EventDispatcher.call(event);
return;
}