Search in sources :

Example 16 with ConfigurationManager

use of com.sk89q.worldguard.config.ConfigurationManager in project MyPet by xXKeyleXx.

the class WorldGuardHook method fixMissingEntityType.

public void fixMissingEntityType(World world, boolean apply) {
    if (is7) {
        try {
            ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
            com.sk89q.worldedit.world.World w = BukkitAdapter.adapt(world);
            BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(w);
            if (apply) {
                if (missingEntityTypeFixValue.containsKey(world.getName())) {
                    fixMissingEntityType(world, false);
                }
                missingEntityTypeFixValue.put(world.getName(), wcfg.blockPluginSpawning);
                wcfg.blockPluginSpawning = false;
            } else if (missingEntityTypeFixValue.containsKey(world.getName())) {
                wcfg.blockPluginSpawning = missingEntityTypeFixValue.get(world.getName());
                missingEntityTypeFixValue.remove(world.getName());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager)

Example 17 with ConfigurationManager

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

the class WorldGuardBlockListener method onBlockFromTo.

/*
     * Called when fluids flow.
     */
@EventHandler(ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
    World world = event.getBlock().getWorld();
    Block blockFrom = event.getBlock();
    Block blockTo = event.getToBlock();
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    Material fromType = blockFrom.getType();
    boolean isWater = Materials.isWater(fromType);
    boolean isLava = fromType == Material.LAVA;
    boolean isAir = fromType == Material.AIR;
    WorldConfiguration wcfg = getWorldConfig(world);
    if (wcfg.simulateSponge && isWater) {
        int ox = blockTo.getX();
        int oy = blockTo.getY();
        int oz = blockTo.getZ();
        for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
            for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
                for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
                    Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
                    if (sponge.getType() == Material.SPONGE && (!wcfg.redstoneSponges || !sponge.isBlockIndirectlyPowered())) {
                        event.setCancelled(true);
                        return;
                    }
                }
            }
        }
    }
    // If so and the target block is protected, cancel the event
    if (!wcfg.preventWaterDamage.isEmpty()) {
        Material targetId = blockTo.getType();
        if ((isAir || isWater) && wcfg.preventWaterDamage.contains(BukkitAdapter.asBlockType(targetId).getId())) {
            event.setCancelled(true);
            return;
        }
    }
    if (!wcfg.allowedLavaSpreadOver.isEmpty() && isLava) {
        Material targetId = blockTo.getRelative(0, -1, 0).getType();
        if (!wcfg.allowedLavaSpreadOver.contains(BukkitAdapter.asBlockType(targetId).getId())) {
            event.setCancelled(true);
            return;
        }
    }
    if (wcfg.highFreqFlags && (isWater || blockFrom.getBlockData() instanceof Waterlogged) && WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(blockFrom.getLocation()), (RegionAssociable) null, Flags.WATER_FLOW) == StateFlag.State.DENY) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.highFreqFlags && isLava && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(blockFrom.getLocation()), (RegionAssociable) null, Flags.LAVA_FLOW))) {
        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) Block(org.bukkit.block.Block) Material(org.bukkit.Material) Waterlogged(org.bukkit.block.data.Waterlogged) World(org.bukkit.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 18 with ConfigurationManager

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

the class WorldGuardBlockListener method onBlockBurn.

/*
     * Called when a block is destroyed from burning.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    BukkitWorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    if (wcfg.disableFireSpread) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.fireSpreadDisableToggle) {
        Block block = event.getBlock();
        event.setCancelled(true);
        checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
        return;
    }
    if (!wcfg.disableFireSpreadBlocks.isEmpty()) {
        Block block = event.getBlock();
        if (wcfg.disableFireSpreadBlocks.contains(BukkitAdapter.asBlockType(block.getType()).getId())) {
            event.setCancelled(true);
            checkAndDestroyFireAround(block.getWorld(), block.getX(), block.getY(), block.getZ());
            return;
        }
    }
    if (wcfg.isChestProtected(BukkitAdapter.adapt(event.getBlock().getLocation()))) {
        event.setCancelled(true);
        return;
    }
    if (wcfg.useRegions) {
        Block block = event.getBlock();
        int x = block.getX();
        int y = block.getY();
        int z = block.getZ();
        ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
        if (!set.testState(null, Flags.FIRE_SPREAD)) {
            checkAndDestroyFireAround(block.getWorld(), x, y, z);
            event.setCancelled(true);
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) Block(org.bukkit.block.Block) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 19 with ConfigurationManager

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

the class WorldGuardBlockListener method onBlockPhysics.

/*
     * Called when block physics occurs.
     */
@EventHandler(ignoreCancelled = true)
public void onBlockPhysics(BlockPhysicsEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    final Material id = event.getBlock().getType();
    if (id == Material.GRAVEL && wcfg.noPhysicsGravel) {
        event.setCancelled(true);
        return;
    }
    if ((id == Material.SAND || id == Material.RED_SAND) && wcfg.noPhysicsSand) {
        event.setCancelled(true);
        return;
    }
    if (id == Material.NETHER_PORTAL && wcfg.allowPortalAnywhere) {
        event.setCancelled(true);
        return;
    }
    if (id == Material.LADDER && wcfg.ropeLadders) {
        if (event.getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Material(org.bukkit.Material) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 20 with ConfigurationManager

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

the class WorldGuardBlockListener method onBlockSpread.

/*
     * Called when a block spreads based on world conditions.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockSpread(BlockSpreadEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
    // craftbukkit randomly gives AIR as event.getSource even if that block is not air
    Material newType = event.getNewState().getType();
    if (Materials.isMushroom(newType)) {
        if (wcfg.disableMushroomSpread) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.MUSHROOMS))) {
            event.setCancelled(true);
            return;
        }
    }
    if (newType == Material.GRASS_BLOCK) {
        if (wcfg.disableGrassGrowth) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.GRASS_SPREAD))) {
            event.setCancelled(true);
            return;
        }
    }
    if (newType == Material.MYCELIUM) {
        if (wcfg.disableMyceliumSpread) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.MYCELIUM_SPREAD))) {
            event.setCancelled(true);
            return;
        }
    }
    if (Materials.isVine(newType)) {
        if (wcfg.disableVineGrowth) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.VINE_GROWTH))) {
            event.setCancelled(true);
            return;
        }
    }
    if (newType == Material.BUDDING_AMETHYST || newType == Material.POINTED_DRIPSTONE) {
        if (wcfg.disableRockGrowth) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.ROCK_GROWTH))) {
            event.setCancelled(true);
            return;
        }
    }
    handleGrow(event, event.getBlock().getLocation(), newType);
}
Also used : RegionAssociable(com.sk89q.worldguard.protection.association.RegionAssociable) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Material(org.bukkit.Material) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)26 EventHandler (org.bukkit.event.EventHandler)18 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)13 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)13 LocalPlayer (com.sk89q.worldguard.LocalPlayer)10 ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)6 Player (org.bukkit.entity.Player)6 Command (com.sk89q.minecraft.util.commands.Command)4 Material (org.bukkit.Material)4 World (org.bukkit.World)4 Block (org.bukkit.block.Block)4 Entity (org.bukkit.entity.Entity)4 CommandException (com.sk89q.minecraft.util.commands.CommandException)3 RegionAssociable (com.sk89q.worldguard.protection.association.RegionAssociable)3 MigrationException (com.sk89q.worldguard.protection.managers.migration.MigrationException)3 RegionDriver (com.sk89q.worldguard.protection.managers.storage.RegionDriver)3 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)3 Logger (java.util.logging.Logger)3 HumanEntity (org.bukkit.entity.HumanEntity)3 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)2