Search in sources :

Example 1 with Flags

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;
    });
}
Also used : RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) Arrays(java.util.Arrays) Item(org.bukkit.entity.Item) Cause(com.sk89q.worldguard.bukkit.cause.Cause) Materials(com.sk89q.worldguard.bukkit.util.Materials) Event(org.bukkit.event.Event) InteropUtils(com.sk89q.worldguard.bukkit.util.InteropUtils) Player(org.bukkit.entity.Player) WGMetadata(com.sk89q.worldguard.bukkit.internal.WGMetadata) CommandUtils(com.sk89q.worldguard.commands.CommandUtils) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler) Block(org.bukkit.block.Block) Location(org.bukkit.Location) BreakBlockEvent(com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent) ItemFrame(org.bukkit.entity.ItemFrame) World(org.bukkit.World) WorldGuard(com.sk89q.worldguard.WorldGuard) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) UseBlockEvent(com.sk89q.worldguard.bukkit.event.block.UseBlockEvent) Material(org.bukkit.Material) UseEntityEvent(com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent) Entities(com.sk89q.worldguard.bukkit.util.Entities) RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) Entity(org.bukkit.entity.Entity) State(com.sk89q.worldguard.protection.flags.StateFlag.State) DestroyEntityEvent(com.sk89q.worldguard.bukkit.event.entity.DestroyEntityEvent) WorldGuardPlugin(com.sk89q.worldguard.bukkit.WorldGuardPlugin) Flags(com.sk89q.worldguard.protection.flags.Flags) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Events(com.sk89q.worldguard.bukkit.util.Events) RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) EntityType(org.bukkit.entity.EntityType) Result(org.bukkit.event.Event.Result) PlayerTakeLecternBookEvent(org.bukkit.event.player.PlayerTakeLecternBookEvent) DelegateEvent(com.sk89q.worldguard.bukkit.event.DelegateEvent) DamageEntityEvent(com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent) List(java.util.List) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ExperienceOrb(org.bukkit.entity.ExperienceOrb) Predicate(com.google.common.base.Predicate) PlaceBlockEvent(com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent) BukkitAdapter(com.sk89q.worldedit.bukkit.BukkitAdapter) DisallowedPVPEvent(com.sk89q.worldguard.bukkit.protection.events.DisallowedPVPEvent) VehicleExitEvent(org.bukkit.event.vehicle.VehicleExitEvent) ChatColor(org.bukkit.ChatColor) SpawnEntityEvent(com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent) Tameable(org.bukkit.entity.Tameable) RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) Block(org.bukkit.block.Block) Material(org.bukkit.Material) ArrayList(java.util.ArrayList) List(java.util.List) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Predicate (com.google.common.base.Predicate)1 BukkitAdapter (com.sk89q.worldedit.bukkit.BukkitAdapter)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 WorldGuard (com.sk89q.worldguard.WorldGuard)1 WorldGuardPlugin (com.sk89q.worldguard.bukkit.WorldGuardPlugin)1 Cause (com.sk89q.worldguard.bukkit.cause.Cause)1 DelegateEvent (com.sk89q.worldguard.bukkit.event.DelegateEvent)1 BreakBlockEvent (com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent)1 PlaceBlockEvent (com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent)1 UseBlockEvent (com.sk89q.worldguard.bukkit.event.block.UseBlockEvent)1 DamageEntityEvent (com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent)1 DestroyEntityEvent (com.sk89q.worldguard.bukkit.event.entity.DestroyEntityEvent)1 SpawnEntityEvent (com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent)1 UseEntityEvent (com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent)1 WGMetadata (com.sk89q.worldguard.bukkit.internal.WGMetadata)1 DisallowedPVPEvent (com.sk89q.worldguard.bukkit.protection.events.DisallowedPVPEvent)1 Entities (com.sk89q.worldguard.bukkit.util.Entities)1 Events (com.sk89q.worldguard.bukkit.util.Events)1 InteropUtils (com.sk89q.worldguard.bukkit.util.InteropUtils)1 Materials (com.sk89q.worldguard.bukkit.util.Materials)1