use of com.sk89q.worldguard.internal.permission.RegionPermissionModel 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.worldguard.internal.permission.RegionPermissionModel in project WorldGuard by EngineHub.
the class RegionCommands method info.
/**
* Get information about a region.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "info", "i" }, usage = "[id]", flags = "usw:", desc = "Get information about a region", min = 0, max = 1)
public void info(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
RegionPermissionModel permModel = getPermissionModel(sender);
// Lookup the existing region
RegionManager manager = checkRegionManager(world);
ProtectedRegion existing;
if (args.argsLength() == 0) {
// Get region from where the player is
if (!(sender instanceof LocalPlayer)) {
throw new CommandException("Please specify the region with /region info -w world_name region_name.");
}
existing = checkRegionStandingIn(manager, (LocalPlayer) sender, true, "/rg info -w \"" + world.getName() + "\" %id%" + (args.hasFlag('u') ? " -u" : "") + (args.hasFlag('s') ? " -s" : ""));
} else {
// Get region from the ID
existing = checkExistingRegion(manager, args.getString(0), true);
}
// Check permissions
if (!permModel.mayLookup(existing)) {
throw new CommandPermissionsException();
}
// Let the player select the region
if (args.hasFlag('s')) {
// Check permissions
if (!permModel.maySelect(existing)) {
throw new CommandPermissionsException();
}
setPlayerSelection(worldGuard.checkPlayer(sender), existing, world);
}
// Print region information
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), existing, args.hasFlag('u') ? null : WorldGuard.getInstance().getProfileCache(), sender);
AsyncCommandBuilder.wrap(printout, sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), "Fetching region info").sendMessageAfterDelay("(Please wait... fetching region information...)").onSuccess((Component) null, component -> {
sender.print(component);
checkSpawnOverlap(sender, world, existing);
}).onFailure("Failed to fetch region information", WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
}
use of com.sk89q.worldguard.internal.permission.RegionPermissionModel in project WorldGuard by EngineHub.
the class LocationFlag method parseInput.
@Override
public Location parseInput(FlagContext context) throws InvalidFlagFormat {
String input = context.getUserInput();
Player player = context.getPlayerSender();
Location loc = null;
if ("here".equalsIgnoreCase(input)) {
Location playerLoc = player.getLocation();
loc = new LazyLocation(((World) playerLoc.getExtent()).getName(), playerLoc.toVector(), playerLoc.getYaw(), playerLoc.getPitch());
} else {
String[] split = input.split(",");
if (split.length >= 3) {
try {
final World world = player.getWorld();
final double x = Double.parseDouble(split[0]);
final double y = Double.parseDouble(split[1]);
final double z = Double.parseDouble(split[2]);
final float yaw = split.length < 4 ? 0 : Float.parseFloat(split[3]);
final float pitch = split.length < 5 ? 0 : Float.parseFloat(split[4]);
loc = new LazyLocation(world.getName(), Vector3.at(x, y, z), yaw, pitch);
} catch (NumberFormatException ignored) {
}
}
}
if (loc != null) {
Object obj = context.get("region");
if (obj instanceof ProtectedRegion) {
ProtectedRegion rg = (ProtectedRegion) obj;
if (WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(player.getWorld()).boundedLocationFlags) {
if (!rg.contains(loc.toVector().toBlockPoint())) {
if (new RegionPermissionModel(player).mayOverrideLocationFlagBounds(rg)) {
player.printDebug("WARNING: Flag location is outside of region.");
} else {
// no permission
throw new InvalidFlagFormat("You can't set that flag outside of the region boundaries.");
}
}
// clamp height to world limits
loc.setPosition(loc.toVector().clampY(0, player.getWorld().getMaxY()));
return loc;
}
}
return loc;
}
throw new InvalidFlagFormat("Expected 'here' or x,y,z.");
}
use of com.sk89q.worldguard.internal.permission.RegionPermissionModel in project WorldGuard by EngineHub.
the class RegionCommands method claim.
/**
* Claiming command for users.
*
* <p>This command is a joke and it needs to be rewritten. It was contributed
* code :(</p>
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "claim" }, usage = "<id>", desc = "Claim a region", min = 1, max = 1)
public void claim(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
LocalPlayer player = worldGuard.checkPlayer(sender);
RegionPermissionModel permModel = getPermissionModel(player);
// Check permissions
if (!permModel.mayClaim()) {
throw new CommandPermissionsException();
}
String id = checkRegionId(args.getString(0), false);
RegionManager manager = checkRegionManager(player.getWorld());
checkRegionDoesNotExist(manager, id, false);
ProtectedRegion region = checkRegionFromSelection(player, id);
WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(player.getWorld());
// Check whether the player has created too many regions
if (!permModel.mayClaimRegionsUnbounded()) {
int maxRegionCount = wcfg.getMaxRegionCount(player);
if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(player) >= maxRegionCount) {
throw new CommandException("You own too many regions, delete one first to claim a new one.");
}
}
ProtectedRegion existing = manager.getRegion(id);
// Check for an existing region
if (existing != null) {
if (!existing.getOwners().contains(player)) {
throw new CommandException("This region already exists and you don't own it.");
}
}
// We have to check whether this region violates the space of any other region
ApplicableRegionSet regions = manager.getApplicableRegions(region);
// Check if this region overlaps any other region
if (regions.size() > 0) {
if (!regions.isOwnerOfAll(player)) {
throw new CommandException("This region overlaps with someone else's region.");
}
} else {
if (wcfg.claimOnlyInsideExistingRegions) {
throw new CommandException("You may only claim regions inside " + "existing regions that you or your group own.");
}
}
if (wcfg.maxClaimVolume >= Integer.MAX_VALUE) {
throw new CommandException("The maximum claim volume get in the configuration is higher than is supported. " + "Currently, it must be " + Integer.MAX_VALUE + " or smaller. Please contact a server administrator.");
}
// Check claim volume
if (!permModel.mayClaimRegionsUnbounded()) {
if (region instanceof ProtectedPolygonalRegion) {
throw new CommandException("Polygons are currently not supported for /rg claim.");
}
if (region.volume() > wcfg.maxClaimVolume) {
player.printError("This region is too large to claim.");
player.printError("Max. volume: " + wcfg.maxClaimVolume + ", your volume: " + region.volume());
return;
}
}
// Inherit from a template region
if (!Strings.isNullOrEmpty(wcfg.setParentOnClaim)) {
ProtectedRegion templateRegion = manager.getRegion(wcfg.setParentOnClaim);
if (templateRegion != null) {
try {
region.setParent(templateRegion);
} catch (CircularInheritanceException e) {
throw new CommandException(e.getMessage());
}
}
}
RegionAdder task = new RegionAdder(manager, region);
task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY);
task.setOwnersInput(new String[] { player.getName() });
final String description = String.format("Claiming region '%s'", id);
AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), description).sendMessageAfterDelay("(Please wait... " + description + ")").onSuccess(TextComponent.of(String.format("A new region has been claimed named '%s'.", id)), null).onFailure("Failed to claim region", WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
}
use of com.sk89q.worldguard.internal.permission.RegionPermissionModel in project WorldGuard by EngineHub.
the class RegionCommands method flag.
/**
* Set a flag.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "flag", "f" }, usage = "<id> <flag> [-w world] [-g group] [value]", flags = "g:w:eh:", desc = "Set flags", min = 2)
public void flag(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
String flagName = args.getString(1);
String value = args.argsLength() >= 3 ? args.getJoinedStrings(2) : null;
RegionGroup groupValue = null;
FlagRegistry flagRegistry = WorldGuard.getInstance().getFlagRegistry();
RegionPermissionModel permModel = getPermissionModel(sender);
if (args.hasFlag('e')) {
if (value != null) {
throw new CommandException("You cannot use -e(mpty) with a flag value.");
}
value = "";
}
// Lookup the existing region
RegionManager manager = checkRegionManager(world);
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
// Check permissions
if (!permModel.maySetFlag(existing)) {
throw new CommandPermissionsException();
}
String regionId = existing.getId();
Flag<?> foundFlag = Flags.fuzzyMatchFlag(flagRegistry, flagName);
// can use, and do nothing afterwards
if (foundFlag == null) {
AsyncCommandBuilder.wrap(new FlagListBuilder(flagRegistry, permModel, existing, world, regionId, sender, flagName), sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), "Flag list for invalid flag command.").onSuccess((Component) null, sender::print).onFailure((Component) null, WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
return;
} else if (value != null) {
if (foundFlag == Flags.BUILD || foundFlag == Flags.BLOCK_BREAK || foundFlag == Flags.BLOCK_PLACE) {
sender.print(buildFlagWarning);
if (!sender.isPlayer()) {
sender.printRaw("https://worldguard.enginehub.org/en/latest/regions/flags/#protection-related");
}
} else if (foundFlag == Flags.PASSTHROUGH) {
sender.print(passthroughFlagWarning);
if (!sender.isPlayer()) {
sender.printRaw("https://worldguard.enginehub.org/en/latest/regions/flags/#overrides");
}
}
}
// but not here -- in the model
if (!permModel.maySetFlag(existing, foundFlag, value)) {
throw new CommandPermissionsException();
}
// -g for group flag
if (args.hasFlag('g')) {
String group = args.getFlag('g');
RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag();
if (groupFlag == null) {
throw new CommandException("Region flag '" + foundFlag.getName() + "' does not have a group flag!");
}
// the [value] part throws an error.
try {
groupValue = groupFlag.parseInput(FlagContext.create().setSender(sender).setInput(group).setObject("region", existing).build());
} catch (InvalidFlagFormat e) {
throw new CommandException(e.getMessage());
}
}
// Set the flag value if a value was set
if (value != null) {
// Set the flag if [value] was given even if [-g group] was given as well
try {
value = setFlag(existing, foundFlag, sender, value).toString();
} catch (InvalidFlagFormat e) {
throw new CommandException(e.getMessage());
}
if (!args.hasFlag('h')) {
sender.print("Region flag " + foundFlag.getName() + " set on '" + regionId + "' to '" + value + "'.");
}
// No value? Clear the flag, if -g isn't specified
} else if (!args.hasFlag('g')) {
// Clear the flag only if neither [value] nor [-g group] was given
existing.setFlag(foundFlag, null);
// Also clear the associated group flag if one exists
RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag();
if (groupFlag != null) {
existing.setFlag(groupFlag, null);
}
if (!args.hasFlag('h')) {
sender.print("Region flag " + foundFlag.getName() + " removed from '" + regionId + "'. (Any -g(roups) were also removed.)");
}
}
// Now set the group
if (groupValue != null) {
RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag();
// If group set to the default, then clear the group flag
if (groupValue == groupFlag.getDefault()) {
existing.setFlag(groupFlag, null);
sender.print("Region group flag for '" + foundFlag.getName() + "' reset to default.");
} else {
existing.setFlag(groupFlag, groupValue);
sender.print("Region group flag for '" + foundFlag.getName() + "' set.");
}
}
// Print region information
if (args.hasFlag('h')) {
int page = args.getFlagInteger('h');
sendFlagHelper(sender, world, existing, permModel, page);
} else {
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), existing, null, sender);
printout.append(SubtleFormat.wrap("(Current flags: "));
printout.appendFlagsList(false);
printout.append(SubtleFormat.wrap(")"));
printout.send(sender);
checkSpawnOverlap(sender, world, existing);
}
}
Aggregations