Search in sources :

Example 6 with ConfigurationManager

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

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

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

Example 9 with ConfigurationManager

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

the class RegionCommands method migrateDB.

/**
 * Migrate the region database.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "migratedb" }, usage = "<from> <to>", flags = "y", desc = "Migrate from one Protection Database to another.", min = 2, max = 2)
public void migrateDB(CommandContext args, Actor sender) throws CommandException {
    // Check permissions
    if (!getPermissionModel(sender).mayMigrateRegionStore()) {
        throw new CommandPermissionsException();
    }
    DriverType from = Enums.findFuzzyByValue(DriverType.class, args.getString(0));
    DriverType to = Enums.findFuzzyByValue(DriverType.class, args.getString(1));
    if (from == null) {
        throw new CommandException("The value of 'from' is not a recognized type of region data database.");
    }
    if (to == null) {
        throw new CommandException("The value of 'to' is not a recognized type of region region data database.");
    }
    if (from == to) {
        throw new CommandException("It is not possible to migrate between the same types of region data databases.");
    }
    if (!args.hasFlag('y')) {
        throw new CommandException("This command is potentially dangerous.\n" + "Please ensure you have made a backup of your data, and then re-enter the command with -y tacked on at the end to proceed.");
    }
    ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    RegionDriver fromDriver = config.regionStoreDriverMap.get(from);
    RegionDriver toDriver = config.regionStoreDriverMap.get(to);
    if (fromDriver == null) {
        throw new CommandException("The driver specified as 'from' does not seem to be supported in your version of WorldGuard.");
    }
    if (toDriver == null) {
        throw new CommandException("The driver specified as 'to' does not seem to be supported in your version of WorldGuard.");
    }
    DriverMigration migration = new DriverMigration(fromDriver, toDriver, WorldGuard.getInstance().getFlagRegistry());
    LoggerToChatHandler handler = null;
    Logger minecraftLogger = null;
    if (sender instanceof LocalPlayer) {
        handler = new LoggerToChatHandler(sender);
        handler.setLevel(Level.ALL);
        minecraftLogger = Logger.getLogger("com.sk89q.worldguard");
        minecraftLogger.addHandler(handler);
    }
    try {
        RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
        sender.print("Now performing migration... this may take a while.");
        container.migrate(migration);
        sender.print("Migration complete! This only migrated the data. If you already changed your settings to use " + "the target driver, then WorldGuard is now using the new data. If not, you have to adjust your " + "configuration to use the new driver and then restart your server.");
    } catch (MigrationException e) {
        log.log(Level.WARNING, "Failed to migrate", e);
        throw new CommandException("Error encountered while migrating: " + e.getMessage());
    } finally {
        if (minecraftLogger != null) {
            minecraftLogger.removeHandler(handler);
        }
    }
}
Also used : MigrationException(com.sk89q.worldguard.protection.managers.migration.MigrationException) LoggerToChatHandler(com.sk89q.worldguard.util.logging.LoggerToChatHandler) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) DriverMigration(com.sk89q.worldguard.protection.managers.migration.DriverMigration) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) DriverType(com.sk89q.worldguard.protection.managers.storage.DriverType) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) Logger(java.util.logging.Logger) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Command(com.sk89q.minecraft.util.commands.Command)

Example 10 with ConfigurationManager

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

the class WorldGuardEntityListener method onExplosionPrime.

/*
     * Called on explosion prime
     */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExplosionPrime(ExplosionPrimeEvent event) {
    ConfigurationManager cfg = getConfig();
    Entity ent = event.getEntity();
    if (cfg.activityHaltToggle) {
        ent.remove();
        event.setCancelled(true);
        return;
    }
    BukkitWorldConfiguration wcfg = getWorldConfig(ent.getWorld());
    if (event.getEntityType() == EntityType.WITHER) {
        if (wcfg.blockWitherExplosions) {
            event.setCancelled(true);
            return;
        }
    } else if (event.getEntityType() == EntityType.WITHER_SKULL) {
        if (wcfg.blockWitherSkullExplosions) {
            event.setCancelled(true);
            return;
        }
    } else if (event.getEntityType() == EntityType.FIREBALL) {
        if (wcfg.blockFireballExplosions) {
            event.setCancelled(true);
            return;
        }
    } else if (event.getEntityType() == EntityType.CREEPER) {
        if (wcfg.blockCreeperExplosions) {
            event.setCancelled(true);
            return;
        }
    } else if (event.getEntityType() == EntityType.PRIMED_TNT || event.getEntityType() == EntityType.MINECART_TNT) {
        if (wcfg.blockTNTExplosions) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) BukkitWorldConfiguration(com.sk89q.worldguard.bukkit.BukkitWorldConfiguration) 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