Search in sources :

Example 6 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class WorldGuardBlockListener method onBlockIgnite.

/*
     * Called when a block gets ignited.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockIgnite(BlockIgniteEvent event) {
    IgniteCause cause = event.getCause();
    Block block = event.getBlock();
    World world = block.getWorld();
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(world);
    boolean isFireSpread = cause == IgniteCause.SPREAD;
    if (wcfg.preventLightningFire && cause == IgniteCause.LIGHTNING) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.preventLavaFire && cause == IgniteCause.LAVA) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.disableFireSpread && isFireSpread) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.blockLighter && (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) && event.getPlayer() != null && !getPlugin().hasPermission(event.getPlayer(), "worldguard.override.lighter")) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.fireSpreadDisableToggle && isFireSpread) {
        event.setCancelled(true);
        return;
    }
    if (!wcfg.disableFireSpreadBlocks.isEmpty() && isFireSpread) {
        int x = block.getX();
        int y = block.getY();
        int z = block.getZ();
        if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y - 1, z).getType()).getId()) || wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x + 1, y, z).getType()).getId()) || wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x - 1, y, z).getType()).getId()) || wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y, z - 1).getType()).getId()) || wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(world.getBlockAt(x, y, z + 1).getType()).getId())) {
            event.setCancelled(true);
            return;
        }
    }
    if (wcfg.useRegions) {
        ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
        if (wcfg.highFreqFlags && isFireSpread && !set.testState(null, Flags.FIRE_SPREAD)) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.highFreqFlags && cause == IgniteCause.LAVA && !set.testState(null, Flags.LAVA_FIRE)) {
            event.setCancelled(true);
            return;
        }
        if (cause == IgniteCause.FIREBALL && event.getPlayer() == null) {
            // wtf bukkit, FIREBALL is supposed to be reserved to players
            if (!set.testState(null, Flags.GHAST_FIREBALL)) {
                event.setCancelled(true);
                return;
            }
        }
        if (cause == IgniteCause.LIGHTNING && !set.testState(null, Flags.LIGHTNING)) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Block(org.bukkit.block.Block) World(org.bukkit.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) IgniteCause(org.bukkit.event.block.BlockIgniteEvent.IgniteCause) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 7 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration 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)

Example 8 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class EventAbstractionListener method onBlockFromTo.

// TODO: Handle EntityPortalEnterEvent
// -------------------------------------------------------------------------
// Block self-interaction
// -------------------------------------------------------------------------
@EventHandler(ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
    WorldConfiguration config = getWorldConfig(event.getBlock().getWorld());
    // frequency events at the moment
    if (!config.useRegions || (!config.highFreqFlags && !config.checkLiquidFlow)) {
        return;
    }
    Block from = event.getBlock();
    Block to = event.getToBlock();
    Material fromType = from.getType();
    Material toType = to.getType();
    // Liquids pass this event when flowing to solid blocks
    if (Materials.isLiquid(fromType) && toType.isSolid()) {
        return;
    }
    // flow and the from/to data may not be correct.
    if ((Materials.isWater(fromType) && Materials.isWater(toType)) || (Materials.isLava(fromType) && Materials.isLava(toType))) {
        return;
    }
    Cause cause = create(from);
    // Disable since it's probably not needed
    /*if (from.getType() != Material.AIR) {
            Events.fireToCancel(event, new BreakBlockEvent(event, cause, to));
        }*/
    Events.fireToCancel(event, new PlaceBlockEvent(event, cause, to.getLocation(), from.getType()));
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Cause(com.sk89q.worldguard.bukkit.cause.Cause) FallingBlock(org.bukkit.entity.FallingBlock) Block(org.bukkit.block.Block) Material(org.bukkit.Material) PlaceBlockEvent(com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent) EventHandler(org.bukkit.event.EventHandler)

Example 9 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class BukkitRegionContainer method load.

@Override
@Nullable
protected RegionManager load(World world) {
    checkNotNull(world);
    WorldConfiguration config = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
    if (!config.useRegions) {
        return null;
    }
    RegionManager manager;
    synchronized (lock) {
        manager = container.load(world.getName());
        if (manager != null) {
            // Bias the region data for loaded chunks
            List<BlockVector2> positions = new ArrayList<>();
            for (Chunk chunk : ((BukkitWorld) world).getWorld().getLoadedChunks()) {
                positions.add(BlockVector2.at(chunk.getX(), chunk.getZ()));
            }
            manager.loadChunks(positions);
        }
    }
    return manager;
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ArrayList(java.util.ArrayList) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) Chunk(org.bukkit.Chunk) BlockVector2(com.sk89q.worldedit.math.BlockVector2) Nullable(javax.annotation.Nullable)

Example 10 with WorldConfiguration

use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.

the class BlacklistListener method onInventoryDrag.

@EventHandler(ignoreCancelled = true)
public void onInventoryDrag(InventoryDragEvent event) {
    HumanEntity entity = event.getWhoClicked();
    if (!(entity instanceof Player))
        return;
    if (event.getInventory().getType() != InventoryType.PLAYER && event.getInventory().getType() != InventoryType.CRAFTING)
        return;
    if (event.getRawSlots().stream().anyMatch(i -> i >= 5 && i <= 8)) {
        // dropped on armor slots
        Player player = (Player) entity;
        ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
        WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld()));
        LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
        if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check(new ItemEquipBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(player.getLocation()), createTarget(event.getOldCursor())), false, false)) {
            event.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ItemEquipBlacklistEvent(com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) HumanEntity(org.bukkit.entity.HumanEntity) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)59 EventHandler (org.bukkit.event.EventHandler)45 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)37 Player (org.bukkit.entity.Player)33 LocalPlayer (com.sk89q.worldguard.LocalPlayer)32 HumanEntity (org.bukkit.entity.HumanEntity)14 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)13 Entity (org.bukkit.entity.Entity)13 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)11 Material (org.bukkit.Material)11 World (org.bukkit.World)11 LivingEntity (org.bukkit.entity.LivingEntity)11 Block (org.bukkit.block.Block)10 ItemStack (org.bukkit.inventory.ItemStack)10 World (com.sk89q.worldedit.world.World)4 ItemAcquireBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent)4 ItemEquipBlacklistEvent (com.sk89q.worldguard.blacklist.event.ItemEquipBlacklistEvent)4 RegionAssociable (com.sk89q.worldguard.protection.association.RegionAssociable)4 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)4 Command (com.sk89q.minecraft.util.commands.Command)3