Allowed passing #<index> in place of a region ID, where <index> is the index as displayed by /region list.

/region claim/remove/redefine are exempt from this and require exact matches.
This commit is contained in:
TomyLobo 2012-03-12 14:46:33 +01:00
parent 2024a93126
commit 40c1d93f02
5 changed files with 52 additions and 21 deletions

View File

@ -149,12 +149,12 @@ public void redefine(CommandContext args, CommandSender sender) throws CommandEx
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion existing = mgr.getRegion(id);
ProtectedRegion existing = mgr.getRegionExact(id);
if (existing == null) {
throw new CommandException("Could not find a region by that ID.");
}
if (existing.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.redefine.own");
} else if (existing.isMember(localPlayer)) {
@ -272,7 +272,7 @@ public void claim(CommandContext args, CommandSender sender) throws CommandExcep
}
}
ProtectedRegion existing = mgr.getRegion(id);
ProtectedRegion existing = mgr.getRegionExact(id);
// Check for an existing region
if (existing != null) {
@ -793,11 +793,12 @@ public void setPriority(CommandContext args, CommandSender sender) throws Comman
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id);
if (region == null) {
throw new CommandException("Could not find a region by that ID.");
}
id = region.getId();
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setpriority.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
@ -839,6 +840,8 @@ public void setParent(CommandContext args, CommandSender sender) throws CommandE
throw new CommandException("Could not find a target region by that ID.");
}
id = region.getId();
if (args.argsLength() == 1) {
try {
region.setParent(null);
@ -901,7 +904,7 @@ public void remove(CommandContext args, CommandSender sender) throws CommandExce
String id = args.getString(0);
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id);
ProtectedRegion region = mgr.getRegionExact(id);
if (region == null) {
throw new CommandException("Could not find a region by that ID.");
@ -1061,7 +1064,7 @@ public void teleport(CommandContext args, CommandSender sender) throws CommandEx
final Player player = plugin.checkPlayer(sender);
final RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
final String id = args.getString(0);
String id = args.getString(0);
final ProtectedRegion region = mgr.getRegion(id);
if (region == null) {
@ -1071,6 +1074,8 @@ public void teleport(CommandContext args, CommandSender sender) throws CommandEx
throw new CommandException("A region with ID '" + id + "' doesn't exist.");
}
id = region.getId();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.teleport.own." + id.toLowerCase());

View File

@ -61,7 +61,9 @@ public void addMember(CommandContext args, CommandSender sender) throws CommandE
if (region == null) {
throw new CommandException("Could not find a region by that ID.");
}
id = region.getId();
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addmember.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
@ -100,6 +102,8 @@ public void addOwner(CommandContext args, CommandSender sender) throws CommandEx
throw new CommandException("Could not find a region by that ID.");
}
id = region.getId();
Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
DefaultDomain owners = region.getOwners();
if (flag != null && flag && owners != null && owners.size() == 0) {
@ -150,7 +154,9 @@ public void removeMember(CommandContext args, CommandSender sender) throws Comma
if (region == null) {
throw new CommandException("Could not find a region by that ID.");
}
id = region.getId();
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removemember.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {
@ -189,7 +195,9 @@ public void removeOwner(CommandContext args,
if (region == null) {
throw new CommandException("Could not find a region by that ID.");
}
id = region.getId();
if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removeowner.own." + id.toLowerCase());
} else if (region.isMember(localPlayer)) {

View File

@ -97,11 +97,6 @@ public boolean hasRegion(String id) {
return regions.containsKey(id.toLowerCase());
}
@Override
public ProtectedRegion getRegion(String id) {
return regions.get(id.toLowerCase());
}
@Override
public ApplicableRegionSet getApplicableRegions(Vector pt) {
TreeSet<ProtectedRegion> appRegions =

View File

@ -88,11 +88,6 @@ public boolean hasRegion(String id) {
return regions.containsKey(id.toLowerCase());
}
@Override
public ProtectedRegion getRegion(String id) {
return regions.get(id.toLowerCase());
}
@Override
public void removeRegion(String id) {
ProtectedRegion region = regions.get(id.toLowerCase());

View File

@ -101,13 +101,41 @@ public void save() throws ProtectionDatabaseException {
*/
public abstract boolean hasRegion(String id);
/**
* Get a region by its ID. Includes symbolic names like #&lt;index&gt;
*
* @param id id of the region, can be mixed-case
* @return region or null if it doesn't exist
*/
public ProtectedRegion getRegion(String id) {
if (id.startsWith("#")) {
int index;
try {
index = Integer.parseInt(id.substring(1)) - 1;
} catch (NumberFormatException e) {
return null;
}
for (ProtectedRegion region : getRegions().values()) {
if (index == 0) {
return region;
}
--index;
}
return null;
}
return getRegionExact(id);
}
/**
* Get a region by its ID.
*
* @param id id of the region, can be mixed-case
* @return region or null if it doesn't exist
*/
public abstract ProtectedRegion getRegion(String id);
public ProtectedRegion getRegionExact(String id) {
return getRegions().get(id.toLowerCase());
}
/**
* Removes a region, including inheriting children.