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());
}
}
Aggregations