use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class RegionCommands method select.
/**
* Get a WorldEdit selection from a region.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "select", "sel", "s" }, usage = "[-w <world>] [id]", desc = "Load a region as a WorldEdit selection", min = 0, max = 1, flags = "w:")
public void select(CommandContext args, Actor sender) throws CommandException {
World world = checkWorld(args, sender, 'w');
RegionManager manager = checkRegionManager(world);
ProtectedRegion existing;
// If no arguments were given, get the region that the player is inside
if (args.argsLength() == 0) {
LocalPlayer player = worldGuard.checkPlayer(sender);
if (!player.getWorld().equals(world)) {
// just don't allow that
throw new CommandException("Please specify a region name.");
}
world = player.getWorld();
existing = checkRegionStandingIn(manager, player, "/rg select -w \"" + world.getName() + "\" %id%");
} else {
existing = checkExistingRegion(manager, args.getString(0), false);
}
// Check permissions
if (!getPermissionModel(sender).maySelect(existing)) {
throw new CommandPermissionsException();
}
// Select
setPlayerSelection(sender, existing, world);
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class RegionCommands method flagHelper.
@Command(aliases = "flags", usage = "[-p <page>] [id]", flags = "p:w:", desc = "View region flags", min = 0, max = 2)
public void flagHelper(CommandContext args, Actor sender) throws CommandException {
// Get the world
World world = checkWorld(args, sender, 'w');
// Lookup the existing region
RegionManager manager = checkRegionManager(world);
ProtectedRegion region;
if (args.argsLength() == 0) {
// Get region from where the player is
if (!(sender instanceof LocalPlayer)) {
throw new CommandException("Please specify the region with /region flags -w world_name region_name.");
}
region = checkRegionStandingIn(manager, (LocalPlayer) sender, true, "/rg flags -w \"" + world.getName() + "\" %id%");
} else {
// Get region from the ID
region = checkExistingRegion(manager, args.getString(0), true);
}
final RegionPermissionModel perms = getPermissionModel(sender);
if (!perms.mayLookup(region)) {
throw new CommandPermissionsException();
}
int page = args.hasFlag('p') ? args.getFlagInteger('p') : 1;
sendFlagHelper(sender, world, region, perms, page);
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class RegionCommands method setPriority.
/**
* Set the priority of a region.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "setpriority", "priority", "pri" }, usage = "<id> <priority>", flags = "w:", desc = "Set the priority of a region", min = 2, max = 2)
public void setPriority(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
int priority = args.getInteger(1);
// Lookup the existing region
RegionManager manager = checkRegionManager(world);
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), false);
// Check permissions
if (!getPermissionModel(sender).maySetPriority(existing)) {
throw new CommandPermissionsException();
}
existing.setPriority(priority);
sender.print("Priority of '" + existing.getId() + "' set to " + priority + " (higher numbers override).");
checkSpawnOverlap(sender, world, existing);
}
use of com.sk89q.minecraft.util.commands.Command 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());
}
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class RegionCommands method toggleBypass.
@Command(aliases = { "toggle-bypass", "bypass" }, usage = "[on|off]", desc = "Toggle region bypassing, effectively ignoring bypass permissions.")
public void toggleBypass(CommandContext args, Actor sender) throws CommandException {
LocalPlayer player = worldGuard.checkPlayer(sender);
if (!player.hasPermission("worldguard.region.toggle-bypass")) {
throw new CommandPermissionsException();
}
Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
boolean shouldEnableBypass;
if (args.argsLength() > 0) {
String arg1 = args.getString(0);
if (!arg1.equalsIgnoreCase("on") && !arg1.equalsIgnoreCase("off")) {
throw new CommandException("Allowed optional arguments are: on, off");
}
shouldEnableBypass = arg1.equalsIgnoreCase("on");
} else {
shouldEnableBypass = session.hasBypassDisabled();
}
if (shouldEnableBypass) {
session.setBypassDisabled(false);
player.print("You are now bypassing region protection (as long as you have permission).");
} else {
session.setBypassDisabled(true);
player.print("You are no longer bypassing region protection.");
}
}
Aggregations