mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-09-30 07:37:31 +02:00
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:
parent
2024a93126
commit
40c1d93f02
@ -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());
|
||||
|
@ -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)) {
|
||||
|
@ -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 =
|
||||
|
@ -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());
|
||||
|
@ -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 #<index>
|
||||
*
|
||||
* @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.
|
||||
|
Loading…
Reference in New Issue
Block a user