Search in sources :

Example 11 with ConfigurationManager

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

the class WorldGuardPlayerListener method onPlayerInteract.

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    World world = player.getWorld();
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        handleBlockRightClick(event);
    } else if (event.getAction() == Action.PHYSICAL) {
        handlePhysicalInteract(event);
    }
    ConfigurationManager cfg = getConfig();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (wcfg.removeInfiniteStacks && !getPlugin().hasPermission(player, "worldguard.override.infinite-stack")) {
        int slot = player.getInventory().getHeldItemSlot();
        ItemStack heldItem = player.getInventory().getItem(slot);
        if (heldItem != null && heldItem.getAmount() < 0) {
            player.getInventory().setItem(slot, null);
            player.sendMessage(ChatColor.RED + "Infinite stack removed.");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) World(org.bukkit.World) ItemStack(org.bukkit.inventory.ItemStack) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) EventHandler(org.bukkit.event.EventHandler)

Example 12 with ConfigurationManager

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

the class WorldGuardPlayerListener method onPlayerJoin.

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    World world = player.getWorld();
    ConfigurationManager cfg = getConfig();
    WorldConfiguration wcfg = getWorldConfig(world);
    if (cfg.activityHaltToggle) {
        player.sendMessage(ChatColor.YELLOW + "Intensive server activity has been HALTED.");
        int removed = 0;
        for (Entity entity : world.getEntities()) {
            if (Entities.isIntensiveEntity(BukkitAdapter.adapt(entity))) {
                entity.remove();
                removed++;
            }
        }
        if (removed > 10) {
            log.info("Halt-Act: " + removed + " entities (>10) auto-removed from " + player.getWorld());
        }
    }
    if (wcfg.fireSpreadDisableToggle) {
        player.sendMessage(ChatColor.YELLOW + "Fire spread is currently globally disabled for this world.");
    }
    Events.fire(new ProcessPlayerEvent(player));
    WorldGuard.getInstance().getExecutorService().submit(() -> WorldGuard.getInstance().getProfileCache().put(new Profile(player.getUniqueId(), player.getName())));
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) ProcessPlayerEvent(com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent) World(org.bukkit.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Profile(com.sk89q.worldguard.util.profile.Profile) EventHandler(org.bukkit.event.EventHandler)

Example 13 with ConfigurationManager

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

the class ToggleCommands method stopLag.

@Command(aliases = { "halt-activity", "stoplag", "haltactivity" }, usage = "[confirm]", desc = "Attempts to cease as much activity in order to stop lag", flags = "cis", max = 1)
@CommandPermissions({ "worldguard.halt-activity" })
public void stopLag(CommandContext args, Actor sender) throws CommandException {
    ConfigurationManager configManager = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    if (args.hasFlag('i')) {
        if (configManager.activityHaltToggle) {
            sender.print("ALL intensive server activity is not allowed.");
        } else {
            sender.print("ALL intensive server activity is allowed.");
        }
    } else {
        boolean activityHaltToggle = !args.hasFlag('c');
        if (activityHaltToggle && (args.argsLength() == 0 || !args.getString(0).equalsIgnoreCase("confirm"))) {
            String confirmCommand = "/" + args.getCommand() + " confirm";
            TextComponent message = TextComponent.builder("").append(ErrorFormat.wrap("This command will ")).append(ErrorFormat.wrap("PERMANENTLY").decoration(TextDecoration.BOLD, TextDecoration.State.TRUE)).append(ErrorFormat.wrap(" erase ALL animals in ALL loaded chunks in ALL loaded worlds. ")).append(TextComponent.newline()).append(TextComponent.of("[Click]", TextColor.GREEN).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, confirmCommand)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to confirm /" + args.getCommand())))).append(ErrorFormat.wrap(" or type ")).append(CodeFormat.wrap(confirmCommand).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, confirmCommand))).append(ErrorFormat.wrap(" to confirm.")).build();
            sender.print(message);
            return;
        }
        configManager.activityHaltToggle = activityHaltToggle;
        if (activityHaltToggle) {
            if (!(sender instanceof LocalPlayer)) {
                sender.print("ALL intensive server activity halted.");
            }
            if (!args.hasFlag('s')) {
                worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity halted by " + sender.getDisplayName() + "."));
            } else {
                sender.print("(Silent) ALL intensive server activity halted by " + sender.getDisplayName() + ".");
            }
            for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
                int removed = 0;
                for (Entity entity : world.getEntities()) {
                    if (Entities.isIntensiveEntity(entity)) {
                        entity.remove();
                        removed++;
                    }
                }
                if (removed > 10) {
                    sender.printRaw("" + removed + " entities (>10) auto-removed from " + world.getName());
                }
            }
        } else {
            if (!args.hasFlag('s')) {
                worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity is now allowed."));
                if (!(sender instanceof LocalPlayer)) {
                    sender.print("ALL intensive server activity is now allowed.");
                }
            } else {
                sender.print("(Silent) ALL intensive server activity is now allowed.");
            }
        }
    }
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Entity(com.sk89q.worldedit.entity.Entity) LocalPlayer(com.sk89q.worldguard.LocalPlayer) World(com.sk89q.worldedit.world.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 14 with ConfigurationManager

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

the class WorldGuardCommands method reload.

@Command(aliases = { "reload" }, desc = "Reload WorldGuard configuration", max = 0)
@CommandPermissions({ "worldguard.reload" })
public void reload(CommandContext args, Actor sender) throws CommandException {
    // TODO: This is subject to a race condition, but at least other commands are not being processed concurrently
    List<Task<?>> tasks = WorldGuard.getInstance().getSupervisor().getTasks();
    if (!tasks.isEmpty()) {
        throw new CommandException("There are currently pending tasks. Use /wg running to monitor these tasks first.");
    }
    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 {
        ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
        config.unload();
        config.load();
        for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
            config.get(world);
        }
        WorldGuard.getInstance().getPlatform().getRegionContainer().reload();
        // WGBukkit.cleanCache();
        sender.print("WorldGuard configuration reloaded.");
    } catch (Throwable t) {
        sender.printError("Error while reloading: " + t.getMessage());
    } finally {
        if (minecraftLogger != null) {
            minecraftLogger.removeHandler(handler);
        }
    }
}
Also used : FutureForwardingTask(com.sk89q.worldedit.util.task.FutureForwardingTask) Task(com.sk89q.worldedit.util.task.Task) LoggerToChatHandler(com.sk89q.worldguard.util.logging.LoggerToChatHandler) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) Logger(java.util.logging.Logger) World(com.sk89q.worldedit.world.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) NestedCommand(com.sk89q.minecraft.util.commands.NestedCommand) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 15 with ConfigurationManager

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

the class WorldGuardPlayerListener method onPlayerCommandPreprocess.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    Player player = event.getPlayer();
    LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
    ConfigurationManager cfg = getConfig();
    WorldConfiguration wcfg = getWorldConfig(player.getWorld());
    if (wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
        ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
        Set<String> allowedCommands = set.queryValue(localPlayer, Flags.ALLOWED_CMDS);
        Set<String> blockedCommands = set.queryValue(localPlayer, Flags.BLOCKED_CMDS);
        CommandFilter test = new CommandFilter(allowedCommands, blockedCommands);
        if (!test.apply(event.getMessage())) {
            String message = set.queryValue(localPlayer, Flags.DENY_MESSAGE);
            RegionProtectionListener.formatAndSendDenyMessage("use " + event.getMessage(), localPlayer, message);
            event.setCancelled(true);
            return;
        }
    }
    if (cfg.blockInGameOp) {
        if (opPattern.matcher(event.getMessage()).matches()) {
            player.sendMessage(ChatColor.RED + "/op and /deop can only be used in console (as set by a WG setting).");
            event.setCancelled(true);
            return;
        }
    }
}
Also used : CommandFilter(com.sk89q.worldguard.util.command.CommandFilter) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) 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