Search in sources :

Example 1 with EntityBlockFormEvent

use of org.bukkit.event.block.EntityBlockFormEvent in project WorldGuard by EngineHub.

the class WorldGuardBlockListener method onBlockForm.

/*
     * Called when a block is formed based on world conditions.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    Material type = event.getNewState().getType();
    if (event instanceof EntityBlockFormEvent) {
        if (((EntityBlockFormEvent) event).getEntity() instanceof Snowman) {
            if (wcfg.disableSnowmanTrails) {
                event.setCancelled(true);
                return;
            }
        }
        return;
    }
    if (type == Material.ICE) {
        if (wcfg.disableIceFormation) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.ICE_FORM))) {
            event.setCancelled(true);
            return;
        }
    }
    if (type == Material.SNOW) {
        if (wcfg.disableSnowFormation) {
            event.setCancelled(true);
            return;
        }
        if (!wcfg.allowedSnowFallOver.isEmpty()) {
            Material targetId = event.getBlock().getRelative(0, -1, 0).getType();
            if (!wcfg.allowedSnowFallOver.contains(BukkitAdapter.asBlockType(targetId).getId())) {
                event.setCancelled(true);
                return;
            }
        }
        if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.SNOW_FALL))) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) EntityBlockFormEvent(org.bukkit.event.block.EntityBlockFormEvent) Snowman(org.bukkit.entity.Snowman) Material(org.bukkit.Material) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)1 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)1 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)1 RegionAssociable (com.sk89q.worldguard.protection.association.RegionAssociable)1 Material (org.bukkit.Material)1 Snowman (org.bukkit.entity.Snowman)1 EventHandler (org.bukkit.event.EventHandler)1 EntityBlockFormEvent (org.bukkit.event.block.EntityBlockFormEvent)1