Search in sources :

Example 1 with Task

use of com.sk89q.worldedit.util.task.Task 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 2 with Task

use of com.sk89q.worldedit.util.task.Task in project WorldGuard by EngineHub.

the class WorldGuardCommands method listRunningTasks.

@Command(aliases = { "running", "queue" }, desc = "List running tasks", max = 0)
@CommandPermissions("worldguard.running")
public void listRunningTasks(CommandContext args, Actor sender) throws CommandException {
    List<Task<?>> tasks = WorldGuard.getInstance().getSupervisor().getTasks();
    if (tasks.isEmpty()) {
        sender.print("There are currently no running tasks.");
    } else {
        tasks.sort(new TaskStateComparator());
        MessageBox builder = new MessageBox("Running Tasks", new TextComponentProducer());
        builder.append(TextComponent.of("Note: Some 'running' tasks may be waiting to be start.", TextColor.GRAY));
        for (Task<?> task : tasks) {
            builder.append(TextComponent.newline());
            builder.append(TextComponent.of("(" + task.getState().name() + ") ", TextColor.BLUE));
            builder.append(TextComponent.of(CommandUtils.getOwnerName(task.getOwner()) + ": ", TextColor.YELLOW));
            builder.append(TextComponent.of(task.getName(), TextColor.WHITE));
        }
        sender.print(builder.create());
    }
}
Also used : FutureForwardingTask(com.sk89q.worldedit.util.task.FutureForwardingTask) Task(com.sk89q.worldedit.util.task.Task) TaskStateComparator(com.sk89q.worldedit.util.task.TaskStateComparator) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) MessageBox(com.sk89q.worldedit.util.formatting.component.MessageBox) NestedCommand(com.sk89q.minecraft.util.commands.NestedCommand) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)2 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)2 NestedCommand (com.sk89q.minecraft.util.commands.NestedCommand)2 FutureForwardingTask (com.sk89q.worldedit.util.task.FutureForwardingTask)2 Task (com.sk89q.worldedit.util.task.Task)2 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 MessageBox (com.sk89q.worldedit.util.formatting.component.MessageBox)1 TextComponentProducer (com.sk89q.worldedit.util.formatting.component.TextComponentProducer)1 TaskStateComparator (com.sk89q.worldedit.util.task.TaskStateComparator)1 World (com.sk89q.worldedit.world.World)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)1 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)1 Logger (java.util.logging.Logger)1