Search in sources :

Example 1 with RegionManagerLoader

use of com.sk89q.worldguard.commands.task.RegionManagerLoader in project WorldGuard by EngineHub.

the class RegionCommands method load.

/**
 * Reload the region database.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "load", "reload" }, usage = "[world]", desc = "Reload regions from file", flags = "w:")
public void load(CommandContext args, final Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    World world = null;
    try {
        // Get the world
        world = checkWorld(args, sender, 'w');
    } catch (CommandException ignored) {
    // assume the user wants to reload all worlds
    }
    // Check permissions
    if (!getPermissionModel(sender).mayForceLoadRegions()) {
        throw new CommandPermissionsException();
    }
    if (world != null) {
        RegionManager manager = checkRegionManager(world);
        if (manager == null) {
            throw new CommandException("No region manager exists for world '" + world.getName() + "'.");
        }
        final String description = String.format("Loading region data for '%s'.", world.getName());
        AsyncCommandBuilder.wrap(new RegionManagerLoader(manager), sender).registerWithSupervisor(worldGuard.getSupervisor(), description).sendMessageAfterDelay("Please wait... " + description).onSuccess(String.format("Loaded region data for '%s'", world.getName()), null).onFailure(String.format("Failed to load region data for '%s'", world.getName()), worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
    } else {
        // Load regions for all worlds
        List<RegionManager> managers = new ArrayList<>();
        for (World w : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
            RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(w);
            if (manager != null) {
                managers.add(manager);
            }
        }
        AsyncCommandBuilder.wrap(new RegionManagerLoader(managers), sender).registerWithSupervisor(worldGuard.getSupervisor(), "Loading regions for all worlds").sendMessageAfterDelay("(Please wait... loading region data for all worlds...)").onSuccess("Successfully load the region data for all worlds.", null).onFailure("Failed to load regions for all worlds", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
    }
}
Also used : RegionManagerLoader(com.sk89q.worldguard.commands.task.RegionManagerLoader) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) ArrayList(java.util.ArrayList) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)1 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)1 World (com.sk89q.worldedit.world.World)1 RegionManagerLoader (com.sk89q.worldguard.commands.task.RegionManagerLoader)1 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)1 ArrayList (java.util.ArrayList)1