use of org.bukkit.event.block.BlockMultiPlaceEvent in project Arclight by IzzelAliz.
the class BlockPlaceEventDispatcher method onMultiPlace.
@SubscribeEvent(receiveCanceled = true)
public void onMultiPlace(BlockEvent.EntityMultiPlaceEvent event) {
Entity entity = event.getEntity();
if (entity instanceof ServerPlayerEntity) {
ServerPlayerEntity playerEntity = (ServerPlayerEntity) entity;
Player player = ((CraftServer) Bukkit.getServer()).getPlayer(playerEntity);
Direction direction = ArclightCaptures.getPlaceEventDirection();
if (direction != null) {
Hand hand = ArclightCaptures.getPlaceEventHand(Hand.MAIN_HAND);
List<BlockState> placedBlocks = new ArrayList<>(event.getReplacedBlockSnapshots().size());
for (BlockSnapshot snapshot : event.getReplacedBlockSnapshots()) {
placedBlocks.add(ArclightBlockSnapshot.fromBlockSnapshot(snapshot, true).getState());
}
CraftBlock againstBlock = CraftBlock.at(event.getWorld(), event.getPos().offset(direction.getOpposite()));
ItemStack bukkitStack;
if (hand == Hand.MAIN_HAND) {
bukkitStack = player.getInventory().getItemInMainHand();
} else {
bukkitStack = player.getInventory().getItemInOffHand();
}
BlockPlaceEvent placeEvent = new BlockMultiPlaceEvent(placedBlocks, againstBlock, bukkitStack, player, !event.isCanceled());
placeEvent.setCancelled(event.isCanceled());
Bukkit.getPluginManager().callEvent(placeEvent);
event.setCanceled(placeEvent.isCancelled() || !placeEvent.canBuild());
}
}
}
use of org.bukkit.event.block.BlockMultiPlaceEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onBlockPlace.
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
if (event instanceof BlockMultiPlaceEvent)
return;
BlockState previousState = event.getBlockReplacedState();
// Some blocks, like tall grass and fire, get replaced
if (previousState.getType() != Material.AIR && previousState.getType() != event.getBlockReplacedState().getType()) {
Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), previousState.getLocation(), previousState.getType()));
}
if (!event.isCancelled()) {
ItemStack itemStack = new ItemStack(event.getBlockPlaced().getType(), 1);
Events.fireToCancel(event, new UseItemEvent(event, create(event.getPlayer()), event.getPlayer().getWorld(), itemStack));
}
if (!event.isCancelled()) {
Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()), event.getBlock()));
}
if (event.isCancelled()) {
playDenyEffect(event.getPlayer(), event.getBlockPlaced().getLocation().add(0.5, 0.5, 0.5));
}
}
use of org.bukkit.event.block.BlockMultiPlaceEvent in project Insights by InsightsPlugin.
the class BlockListener method onBlockPlaceMonitor.
/**
* Handles the BlockPlaceEvent for players, monitoring changes
* Chunk limitations are not applied here, they are only monitored and displayed to the player.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlaceMonitor(BlockPlaceEvent event) {
var block = event.getBlock();
var location = block.getLocation();
var material = block.getType();
var player = event.getPlayer();
// but since they already exist in the world we do not need to count them.
if (event instanceof BlockMultiPlaceEvent && material != Material.TRIPWIRE_HOOK) {
List<BlockState> replacedBlockStates = ((BlockMultiPlaceEvent) event).getReplacedBlockStates();
for (BlockState state : replacedBlockStates) {
var loc = state.getLocation();
handleModification(loc, state.getType(), material, 1);
}
} else {
handleModification(location, event.getBlockReplacedState().getType(), material, 1);
}
// No need to add any delta, cache is already updated
evaluateAddition(player, location, ScanObject.of(material), 0);
}
use of org.bukkit.event.block.BlockMultiPlaceEvent in project Insights by InsightsPlugin.
the class BlockListener method onBlockPlace.
/**
* Handles the BlockPlaceEvent for players.
* Chunk limitations are applied in here on the lowest (first) event priority.
*/
@AllowPriorityOverride
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
var block = event.getBlock();
var location = block.getLocation();
var material = block.getType();
var player = event.getPlayer();
// In case of BlockMultiPlaceEvent, we may need to take a different delta.
// A closing tripwire hook triggers a BlockMultiPlaceEvent for all attached strings,
// but since they already exist in the world we do not need to count them.
var delta = 0;
if (event instanceof BlockMultiPlaceEvent && material != Material.TRIPWIRE_HOOK) {
List<BlockState> replacedBlockStates = ((BlockMultiPlaceEvent) event).getReplacedBlockStates();
for (BlockState state : replacedBlockStates) {
if (BlockUtils.isSameChunk(location.getBlockX(), location.getBlockZ(), state.getX(), state.getZ())) {
delta++;
}
}
} else {
delta = 1;
}
if (handleAddition(player, location, ScanObject.of(material), delta, false)) {
event.setCancelled(true);
}
}
use of org.bukkit.event.block.BlockMultiPlaceEvent in project McRPG by Eunoians.
the class WorldListener method onBlockPlace.
/**
* Monitor BlockPlace events.
*
* @param event The event to watch
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
BlockState blockState = event.getBlock().getState();
Block block = blockState.getBlock();
World world = block.getWorld();
/* WORLD BLACKLIST CHECK */
if (McRPG.getInstance().getConfig().contains("Configuration.DisabledWorlds") && McRPG.getInstance().getConfig().getStringList("Configuration.DisabledWorlds").contains(world.getName())) {
return;
}
if (isWithinWorldBounds(block)) {
// NOTE: BlockMultiPlace has its own logic so don't handle anything that would overlap
if (!(event instanceof BlockMultiPlaceEvent)) {
McRPG.getPlaceStore().setTrue(blockState);
}
}
}
Aggregations