use of com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onBlockExplode.
@EventHandler(ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent event) {
final BreakBlockEvent eventToFire = new BreakBlockEvent(event, create(event.getBlock()), event.getBlock().getLocation().getWorld(), event.blockList(), Material.AIR);
eventToFire.getRelevantFlags().add(Flags.OTHER_EXPLOSION);
Events.fireBulkEventToCancel(event, eventToFire);
}
use of com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onEntityChangeBlock.
@EventHandler(ignoreCancelled = true)
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
Block block = event.getBlock();
Entity entity = event.getEntity();
Material toType = event.getTo();
Material fromType = block.getType();
Cause cause = create(entity);
// Fire two events: one as BREAK and one as PLACE
if (toType != Material.AIR && fromType != Material.AIR) {
BreakBlockEvent breakDelagate = new BreakBlockEvent(event, cause, block);
setDelegateEventMaterialOptions(breakDelagate, fromType, toType);
boolean denied;
if (!(denied = Events.fireToCancel(event, breakDelagate))) {
PlaceBlockEvent placeDelegate = new PlaceBlockEvent(event, cause, block.getLocation(), toType);
setDelegateEventMaterialOptions(placeDelegate, fromType, toType);
denied = Events.fireToCancel(event, placeDelegate);
}
if (denied && entity instanceof Player) {
playDenyEffect((Player) entity, block.getLocation());
}
handleFallingBlock(event, denied);
} else if (toType == Material.AIR) {
// Track the source so later we can create a proper chain of causes
if (entity instanceof FallingBlock) {
Cause.trackParentCause(entity, block);
// Switch around the event
Events.fireToCancel(event, new SpawnEntityEvent(event, create(block), entity));
} else {
entityBreakBlockDebounce.debounce(block, event.getEntity(), event, new BreakBlockEvent(event, cause, block));
}
} else {
// toType != Material.AIR && fromType == Material.AIR
boolean denied = Events.fireToCancel(event, new PlaceBlockEvent(event, cause, block.getLocation(), toType));
handleFallingBlock(event, denied);
}
}
use of com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onBlockPistonExtend.
@EventHandler(ignoreCancelled = true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
EventDebounce.Entry entry = pistonExtendDebounce.getIfNotPresent(new BlockPistonExtendKey(event), event);
if (entry != null) {
Cause cause = create(event.getBlock());
List<Block> blocks = new ArrayList<>(event.getBlocks());
int originalLength = blocks.size();
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.AIR));
if (originalLength != blocks.size()) {
event.setCancelled(true);
return;
}
BlockFace dir = event.getDirection();
for (int i = 0; i < blocks.size(); i++) {
Block existing = blocks.get(i);
if (existing.getPistonMoveReaction() == PistonMoveReaction.MOVE || existing.getPistonMoveReaction() == PistonMoveReaction.PUSH_ONLY || existing.getType() == Material.PISTON || existing.getType() == Material.STICKY_PISTON) {
blocks.set(i, existing.getRelative(dir));
}
}
Events.fireBulkEventToCancel(event, new PlaceBlockEvent(event, cause, event.getBlock().getWorld(), blocks, Material.STONE));
if (blocks.size() != originalLength) {
event.setCancelled(true);
}
entry.setCancelled(event.isCancelled());
if (event.isCancelled()) {
playDenyEffect(event.getBlock().getLocation().add(0.5, 1, 0.5));
}
}
}
use of com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onEntityExplode.
@EventHandler(ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR));
if (entity instanceof Creeper) {
Cause.untrackParentCause(entity);
}
}
use of com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent in project WorldGuard by EngineHub.
the class RegionProtectionListener method onBreakBlock.
@EventHandler(ignoreCancelled = true)
public void onBreakBlock(final BreakBlockEvent event) {
// Don't care about events that have been pre-allowed
if (event.getResult() == Result.ALLOW)
return;
// Region support disabled
if (!isRegionSupportEnabled(event.getWorld()))
return;
// Whitelisted cause
if (isWhitelisted(event.getCause(), event.getWorld(), false))
return;
final RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
if (!event.isCancelled()) {
final RegionAssociable associable = createRegionAssociable(event.getCause());
event.filter((Predicate<Location>) target -> {
boolean canBreak;
String what;
if (event.getCause().find(EntityType.PRIMED_TNT, EntityType.MINECART_TNT) != null) {
canBreak = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.BLOCK_BREAK, Flags.TNT));
what = "use dynamite";
} else {
canBreak = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.BLOCK_BREAK));
what = "break that block";
}
if (!canBreak) {
tellErrorMessage(event, event.getCause(), target, what);
return false;
}
return true;
});
}
}
Aggregations