Search in sources :

Example 21 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)

Example 22 with ConfigurationManager

use of com.sk89q.worldguard.config.ConfigurationManager 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 23 with ConfigurationManager

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

the class WorldGuardEntityListener method onEntityExplode.

/*
     * Called on entity explode.
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
    ConfigurationManager cfg = getConfig();
    Entity ent = event.getEntity();
    if (cfg.activityHaltToggle) {
        ent.remove();
        event.setCancelled(true);
        return;
    }
    BukkitWorldConfiguration wcfg = getWorldConfig(event.getLocation().getWorld());
    if (ent instanceof Creeper) {
        if (wcfg.blockCreeperExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.blockCreeperBlockDamage) {
            event.blockList().clear();
            return;
        }
    } else if (ent instanceof EnderDragon) {
        if (wcfg.blockEnderDragonBlockDamage) {
            event.blockList().clear();
            return;
        }
    } else if (ent instanceof TNTPrimed || ent instanceof ExplosiveMinecart) {
        if (wcfg.blockTNTExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.blockTNTBlockDamage) {
            event.blockList().clear();
            return;
        }
    } else if (ent instanceof Fireball) {
        if (ent instanceof WitherSkull) {
            if (wcfg.blockWitherSkullExplosions) {
                event.setCancelled(true);
                return;
            }
            if (wcfg.blockWitherSkullBlockDamage) {
                event.blockList().clear();
                return;
            }
        } else {
            if (wcfg.blockFireballExplosions) {
                event.setCancelled(true);
                return;
            }
            if (wcfg.blockFireballBlockDamage) {
                event.blockList().clear();
                return;
            }
        }
        // allow wither skull blocking since there is no dedicated flag atm
        if (wcfg.useRegions) {
            for (Block block : event.blockList()) {
                if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.GHAST_FIREBALL)) {
                    event.blockList().clear();
                    if (wcfg.explosionFlagCancellation)
                        event.setCancelled(true);
                    return;
                }
            }
        }
    } else if (ent instanceof Wither) {
        if (wcfg.blockWitherExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.blockWitherBlockDamage) {
            event.blockList().clear();
            return;
        }
        if (wcfg.useRegions) {
            for (Block block : event.blockList()) {
                if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(block.getLocation()), (RegionAssociable) null, Flags.WITHER_DAMAGE))) {
                    event.blockList().clear();
                    event.setCancelled(true);
                    return;
                }
            }
        }
    } else {
        // unhandled entity
        if (wcfg.blockOtherExplosions) {
            event.setCancelled(true);
            return;
        }
        if (wcfg.useRegions) {
            for (Block block : event.blockList()) {
                if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.OTHER_EXPLOSION)) {
                    event.blockList().clear();
                    if (wcfg.explosionFlagCancellation)
                        event.setCancelled(true);
                    return;
                }
            }
        }
    }
    if (wcfg.signChestProtection) {
        for (Block block : event.blockList()) {
            if (wcfg.isChestProtected(BukkitAdapter.adapt(block.getLocation()))) {
                event.blockList().clear();
                return;
            }
        }
    }
}
Also used : ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) Wither(org.bukkit.entity.Wither) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) EnderDragon(org.bukkit.entity.EnderDragon) Fireball(org.bukkit.entity.Fireball) Creeper(org.bukkit.entity.Creeper) TNTPrimed(org.bukkit.entity.TNTPrimed) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) WitherSkull(org.bukkit.entity.WitherSkull) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 24 with ConfigurationManager

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

the class WorldGuardPlayerListener method onPlayerTeleport.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
    Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    ConfigurationManager cfg = getConfig();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    if (wcfg.useRegions && cfg.usePlayerTeleports) {
        RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
        ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(event.getTo()));
        ApplicableRegionSet setFrom = query.getApplicableRegions(BukkitAdapter.adapt(event.getFrom()));
        if (event.getCause() == TeleportCause.ENDER_PEARL) {
            if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
                boolean cancel = false;
                String message = null;
                if (!setFrom.testState(localPlayer, Flags.ENDERPEARL)) {
                    cancel = true;
                    message = setFrom.queryValue(localPlayer, Flags.EXIT_DENY_MESSAGE);
                } else if (!set.testState(localPlayer, Flags.ENDERPEARL)) {
                    cancel = true;
                    message = set.queryValue(localPlayer, Flags.ENTRY_DENY_MESSAGE);
                }
                if (cancel) {
                    if (message != null && !message.isEmpty()) {
                        player.sendMessage(message);
                    }
                    event.setCancelled(true);
                    return;
                }
            }
        } else if (event.getCause() == TeleportCause.CHORUS_FRUIT) {
            if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
                boolean cancel = false;
                String message = null;
                if (!setFrom.testState(localPlayer, Flags.CHORUS_TELEPORT)) {
                    cancel = true;
                    message = setFrom.queryValue(localPlayer, Flags.EXIT_DENY_MESSAGE);
                } else if (!set.testState(localPlayer, Flags.CHORUS_TELEPORT)) {
                    cancel = true;
                    message = set.queryValue(localPlayer, Flags.ENTRY_DENY_MESSAGE);
                }
                if (cancel) {
                    if (message != null && !message.isEmpty()) {
                        player.sendMessage(message);
                    }
                    event.setCancelled(true);
                    return;
                }
            }
        }
        if (null != WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer).testMoveTo(localPlayer, BukkitAdapter.adapt(event.getTo()), MoveType.TELEPORT)) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) EventHandler(org.bukkit.event.EventHandler)

Example 25 with ConfigurationManager

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

the class WorldGuardPlayerListener method onPlayerLogin.

@EventHandler(ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) {
    Player player = event.getPlayer();
    ConfigurationManager cfg = getConfig();
    String hostKey = cfg.hostKeys.get(player.getUniqueId().toString());
    if (hostKey == null) {
        hostKey = cfg.hostKeys.get(player.getName().toLowerCase());
    }
    if (hostKey != null) {
        String hostname = event.getHostname();
        int colonIndex = hostname.indexOf(':');
        if (colonIndex != -1) {
            hostname = hostname.substring(0, colonIndex);
        }
        if (!hostname.equals(hostKey) && !(cfg.hostKeysAllowFMLClients && (hostname.equals(hostKey + "\u0000FML\u0000") || hostname.equals(hostKey + "\u0000FML2\u0000")))) {
            event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You did not join with the valid host key!");
            log.warning("WorldGuard host key check: " + player.getName() + " joined with '" + hostname + "' but '" + hostKey + "' was expected. Kicked!");
            return;
        }
    }
    if (cfg.deopOnJoin) {
        player.setOp(false);
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)27 EventHandler (org.bukkit.event.EventHandler)18 BukkitWorldConfiguration (com.sk89q.worldguard.bukkit.BukkitWorldConfiguration)14 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