Search in sources :

Example 1 with CommandPermissions

use of com.sk89q.minecraft.util.commands.CommandPermissions 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 2 with CommandPermissions

use of com.sk89q.minecraft.util.commands.CommandPermissions in project WorldGuard by EngineHub.

the class ToggleCommands method stopFire.

@Command(aliases = { "stopfire" }, usage = "[<world>]", desc = "Disables all fire spread temporarily", max = 1)
@CommandPermissions({ "worldguard.fire-toggle.stop" })
public void stopFire(CommandContext args, Actor sender) throws CommandException {
    World world;
    if (args.argsLength() == 0) {
        world = worldGuard.checkPlayer(sender).getWorld();
    } else {
        world = worldGuard.getPlatform().getMatcher().matchWorld(sender, args.getString(0));
    }
    WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
    if (!wcfg.fireSpreadDisableToggle) {
        worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("Fire spread has been globally disabled for '" + world.getName() + "' by " + sender.getDisplayName() + "."));
    } else {
        sender.print("Fire spread was already globally disabled.");
    }
    wcfg.fireSpreadDisableToggle = true;
}
Also used : WorldConfiguration(com.sk89q.worldguard.config.WorldConfiguration) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 3 with CommandPermissions

use of com.sk89q.minecraft.util.commands.CommandPermissions in project WorldGuard by EngineHub.

the class WorldGuardCommands method flushStates.

@Command(aliases = { "flushstates", "clearstates" }, usage = "[player]", desc = "Flush the state manager", max = 1)
@CommandPermissions("worldguard.flushstates")
public void flushStates(CommandContext args, Actor sender) throws CommandException {
    if (args.argsLength() == 0) {
        WorldGuard.getInstance().getPlatform().getSessionManager().resetAllStates();
        sender.print("Cleared all states.");
    } else {
        LocalPlayer player = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
        if (player != null) {
            WorldGuard.getInstance().getPlatform().getSessionManager().resetState(player);
            sender.print("Cleared states for player \"" + player.getName() + "\".");
        }
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) NestedCommand(com.sk89q.minecraft.util.commands.NestedCommand) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 4 with CommandPermissions

use of com.sk89q.minecraft.util.commands.CommandPermissions 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 5 with CommandPermissions

use of com.sk89q.minecraft.util.commands.CommandPermissions in project WorldGuard by EngineHub.

the class DebuggingCommands method fireBreakEvent.

@Command(aliases = { "testbreak" }, usage = "[player]", desc = "Simulate a block break", min = 1, max = 1, flags = "ts")
@CommandPermissions("worldguard.debug.event")
public void fireBreakEvent(CommandContext args, final Actor sender) throws CommandException {
    LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
    worldGuard.getPlatform().getDebugHandler().testBreak(sender, target, args.hasFlag('t'), args.hasFlag('s'));
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)14 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)14 LocalPlayer (com.sk89q.worldguard.LocalPlayer)11 NestedCommand (com.sk89q.minecraft.util.commands.NestedCommand)5 World (com.sk89q.worldedit.world.World)5 CommandException (com.sk89q.minecraft.util.commands.CommandException)3 FutureForwardingTask (com.sk89q.worldedit.util.task.FutureForwardingTask)3 Task (com.sk89q.worldedit.util.task.Task)3 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)3 MessageBox (com.sk89q.worldedit.util.formatting.component.MessageBox)2 TextComponentProducer (com.sk89q.worldedit.util.formatting.component.TextComponentProducer)2 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)2 ReportList (com.sk89q.worldedit.util.report.ReportList)2 SystemInfoReport (com.sk89q.worldedit.util.report.SystemInfoReport)2 TaskStateComparator (com.sk89q.worldedit.util.task.TaskStateComparator)2 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)2 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)2 ApplicableRegionsReport (com.sk89q.worldguard.util.report.ApplicableRegionsReport)2 ConfigReport (com.sk89q.worldguard.util.report.ConfigReport)2 File (java.io.File)2