Search in sources :

Example 36 with WorldConfiguration

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

the class WorldGuardBlockListener method onBlockRedstoneChange.

/*
     * Called when redstone changes.
     */
@EventHandler(priority = EventPriority.HIGH)
public void onBlockRedstoneChange(BlockRedstoneEvent event) {
    Block blockTo = event.getBlock();
    World world = blockTo.getWorld();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (wcfg.simulateSponge && wcfg.redstoneSponges) {
        int ox = blockTo.getX();
        int oy = blockTo.getY();
        int oz = blockTo.getZ();
        for (int cx = -1; cx <= 1; cx++) {
            for (int cy = -1; cy <= 1; cy++) {
                for (int cz = -1; cz <= 1; cz++) {
                    Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
                    if (sponge.getType() == Material.SPONGE && sponge.isBlockIndirectlyPowered()) {
                        SpongeUtil.clearSpongeWater(BukkitAdapter.adapt(world), ox + cx, oy + cy, oz + cz);
                    } else if (sponge.getType() == Material.SPONGE && !sponge.isBlockIndirectlyPowered()) {
                        SpongeUtil.addSpongeWater(BukkitAdapter.adapt(world), ox + cx, oy + cy, oz + cz);
                    }
                }
            }
        }
        return;
    }
}
Also used : BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) Block(org.bukkit.block.Block) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Example 37 with WorldConfiguration

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

Example 38 with WorldConfiguration

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

the class WorldGuardEntityListener method onCreatureSpawn.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    ConfigurationManager cfg = getConfig();
    if (cfg.activityHaltToggle) {
        event.setCancelled(true);
        return;
    }
    WorldConfiguration wcfg = getWorldConfig(event.getEntity().getWorld());
    // allow spawning of creatures from plugins
    if (!wcfg.blockPluginSpawning && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.CUSTOM) {
        return;
    }
    // armor stands are living entities, but we check them as blocks/non-living entities, so ignore them here
    if (Entities.isConsideredBuildingIfUsed(event.getEntity())) {
        return;
    }
    if (wcfg.allowTamedSpawns && // nullsafe check
    event.getEntity() instanceof Tameable && ((Tameable) event.getEntity()).isTamed()) {
        return;
    }
    EntityType entityType = event.getEntityType();
    com.sk89q.worldedit.world.entity.EntityType weEntityType = BukkitAdapter.adapt(entityType);
    if (weEntityType != null && wcfg.blockCreatureSpawn.contains(weEntityType)) {
        event.setCancelled(true);
        return;
    }
    Location eventLoc = event.getLocation();
    if (wcfg.useRegions && cfg.useRegionsCreatureSpawnEvent) {
        ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(eventLoc));
        if (!set.testState(null, Flags.MOB_SPAWNING)) {
            event.setCancelled(true);
            return;
        }
        Set<com.sk89q.worldedit.world.entity.EntityType> entityTypes = set.queryValue(null, Flags.DENY_SPAWN);
        if (entityTypes != null && weEntityType != null && entityTypes.contains(weEntityType)) {
            event.setCancelled(true);
            return;
        }
    }
    if (wcfg.blockGroundSlimes && entityType == EntityType.SLIME && eventLoc.getY() >= 60 && event.getSpawnReason() == SpawnReason.NATURAL) {
        event.setCancelled(true);
        return;
    }
}
Also used : Tameable(org.bukkit.entity.Tameable) EntityType(org.bukkit.entity.EntityType) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Location(org.bukkit.Location) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 39 with WorldConfiguration

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

the class WorldGuardEntityListener method onEntityTransform.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityTransform(EntityTransformEvent event) {
    final Entity entity = event.getEntity();
    WorldConfiguration wcfg = getWorldConfig(entity.getWorld());
    final EntityType type = entity.getType();
    if (wcfg.disableVillagerZap && type == EntityType.VILLAGER && event.getTransformReason() == EntityTransformEvent.TransformReason.LIGHTNING) {
        event.setCancelled(true);
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) EventHandler(org.bukkit.event.EventHandler)

Example 40 with WorldConfiguration

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

the class WorldGuardEntityListener method onPigZap.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPigZap(PigZapEvent event) {
    final Entity entity = event.getEntity();
    WorldConfiguration wcfg = getWorldConfig(entity.getWorld());
    if (wcfg.disablePigZap) {
        event.setCancelled(true);
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) 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