use of com.sk89q.worldguard.protection.flags.Flags in project WorldGuard by EngineHub.
the class RegionProtectionListener method onPlaceBlock.
@EventHandler(ignoreCancelled = true)
public void onPlaceBlock(final PlaceBlockEvent 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 Material type = event.getEffectiveMaterial();
final RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
final RegionAssociable associable = createRegionAssociable(event.getCause());
// Don't check liquid flow unless it's enabled
if (event.getCause().getRootCause() instanceof Block && Materials.isLiquid(type) && !getWorldConfig(event.getWorld()).checkLiquidFlow) {
return;
}
event.filter((Predicate<Location>) target -> {
boolean canPlace;
String what;
if (Materials.isFire(type)) {
Block block = event.getCause().getFirstBlock();
boolean fire = block != null && Materials.isFire(type);
boolean lava = block != null && Materials.isLava(block.getType());
List<StateFlag> flags = new ArrayList<>();
flags.add(Flags.BLOCK_PLACE);
flags.add(Flags.LIGHTER);
if (fire)
flags.add(Flags.FIRE_SPREAD);
if (lava)
flags.add(Flags.LAVA_FIRE);
canPlace = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, flags.toArray(new StateFlag[flags.size()])));
what = "place fire";
} else if (type == Material.FROSTED_ICE) {
event.setSilent(true);
canPlace = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.BLOCK_PLACE, Flags.FROSTED_ICE_FORM));
what = "use frostwalker";
} else {
canPlace = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.BLOCK_PLACE));
what = "place that block";
}
if (!canPlace) {
tellErrorMessage(event, event.getCause(), target, what);
return false;
}
return true;
});
}
Aggregations