Search in sources :

Example 16 with Command

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

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

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

use of com.sk89q.minecraft.util.commands.Command 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)

Example 20 with Command

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

the class GeneralCommands method ungod.

@Command(aliases = { "ungod" }, usage = "[player]", desc = "Disable godmode on a player", flags = "s", max = 1)
public void ungod(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
    Iterable<? extends LocalPlayer> targets;
    boolean included = false;
    // Detect arguments based on the number of arguments provided
    if (args.argsLength() == 0) {
        targets = worldGuard.getPlatform().getMatcher().matchPlayers(worldGuard.checkPlayer(sender));
        // Check permissions!
        sender.checkPermission("worldguard.god");
    } else {
        targets = worldGuard.getPlatform().getMatcher().matchPlayers(sender, args.getString(0));
        // Check permissions!
        sender.checkPermission("worldguard.god.other");
    }
    for (LocalPlayer player : targets) {
        Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
        if (GodMode.set(player, session, false)) {
            // Tell the user
            if (player.equals(sender)) {
                player.print("God mode disabled!");
                // Keep track of this
                included = true;
            } else {
                player.print("God disabled by " + sender.getDisplayName() + ".");
            }
        }
    }
    // user a message so s/he know that something is indeed working
    if (!included && args.hasFlag('s')) {
        sender.print("Players no longer have god mode.");
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Session(com.sk89q.worldguard.session.Session) Command(com.sk89q.minecraft.util.commands.Command)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)41 LocalPlayer (com.sk89q.worldguard.LocalPlayer)24 World (com.sk89q.worldedit.world.World)23 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)22 CommandException (com.sk89q.minecraft.util.commands.CommandException)18 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)18 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)16 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)15 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)12 NestedCommand (com.sk89q.minecraft.util.commands.NestedCommand)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)5 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)5 Logger (java.util.logging.Logger)5 RegionPermissionModel (com.sk89q.worldguard.internal.permission.RegionPermissionModel)4 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)3 FutureForwardingTask (com.sk89q.worldedit.util.task.FutureForwardingTask)3 Task (com.sk89q.worldedit.util.task.Task)3 RegionAdder (com.sk89q.worldguard.commands.task.RegionAdder)3 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)3 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)3