net.minestom.server.event.player.PlayerBlockPlaceEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of minestom-snapshots Show documentation
Show all versions of minestom-snapshots Show documentation
1.20.4 Lightweight Minecraft server
package net.minestom.server.event.player;
import net.minestom.server.coordinate.BlockVec;
import net.minestom.server.coordinate.Point;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.PlayerHand;
import net.minestom.server.event.trait.BlockEvent;
import net.minestom.server.event.trait.CancellableEvent;
import net.minestom.server.event.trait.PlayerInstanceEvent;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockFace;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player tries placing a block.
*/
public class PlayerBlockPlaceEvent implements PlayerInstanceEvent, BlockEvent, CancellableEvent {
private final Player player;
private Block block;
private final BlockFace blockFace;
private final BlockVec blockPosition;
private final Point cursorPosition;
private final PlayerHand hand;
private boolean consumeBlock;
private boolean doBlockUpdates;
private boolean cancelled;
public PlayerBlockPlaceEvent(@NotNull Player player, @NotNull Block block,
@NotNull BlockFace blockFace, @NotNull BlockVec blockPosition,
@NotNull Point cursorPosition, @NotNull PlayerHand hand) {
this.player = player;
this.block = block;
this.blockFace = blockFace;
this.blockPosition = blockPosition;
this.cursorPosition = cursorPosition;
this.hand = hand;
this.consumeBlock = true;
this.doBlockUpdates = true;
}
/**
* Gets the block which will be placed.
*
* @return the block to place
*/
@Override
public @NotNull Block getBlock() {
return block;
}
/**
* Changes the block to be placed.
*
* @param block the new block
*/
public void setBlock(@NotNull Block block) {
this.block = block;
}
public @NotNull BlockFace getBlockFace() {
return blockFace;
}
/**
* Gets the block position.
*
* @return the block position
*/
@Override
public @NotNull BlockVec getBlockPosition() {
return blockPosition;
}
public @NotNull Point getCursorPosition() {
return cursorPosition;
}
/**
* Gets the hand with which the player is trying to place.
*
* @return the hand used
*/
public @NotNull PlayerHand getHand() {
return hand;
}
/**
* Should the block be consumed if not cancelled.
*
* @param consumeBlock true if the block should be consumer (-1 amount), false otherwise
*/
public void consumeBlock(boolean consumeBlock) {
this.consumeBlock = consumeBlock;
}
/**
* Should the block be consumed if not cancelled.
*
* @return true if the block will be consumed, false otherwise
*/
public boolean doesConsumeBlock() {
return consumeBlock;
}
/**
* Should the place trigger updates (on self and neighbors)
* @param doBlockUpdates true if this placement should do block updates
*/
public void setDoBlockUpdates(boolean doBlockUpdates) {
this.doBlockUpdates = doBlockUpdates;
}
/**
* Should the place trigger updates (on self and neighbors)
* @return true if this placement should do block updates
*/
public boolean shouldDoBlockUpdates() {
return doBlockUpdates;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public @NotNull Player getPlayer() {
return player;
}
}