/region info changes

- Fixed /region info <world> <id> checking the wrong permission
- Condensed /region info output a bit
- Cleaned up the source a bit
This commit is contained in:
TomyLobo 2012-03-11 18:10:45 +01:00
parent 83f943965f
commit 6a3e987668

View File

@ -41,7 +41,6 @@
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection; import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection; import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WorldConfiguration; import com.sk89q.worldguard.bukkit.WorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.domains.DefaultDomain;
@ -388,21 +387,32 @@ public void select(CommandContext args, CommandSender sender) throws CommandExce
desc = "Get information about a region", min = 0, max = 2) desc = "Get information about a region", min = 0, max = 2)
public void info(CommandContext args, CommandSender sender) throws CommandException { public void info(CommandContext args, CommandSender sender) throws CommandException {
final Player player;
final LocalPlayer localPlayer; final LocalPlayer localPlayer;
final World world; final World world;
if (sender instanceof Player) {
final Player player = (Player) sender;
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
} else if (args.argsLength() < 2) {
throw new CommandException("A player is expected.");
} else {
localPlayer = null;
world = plugin.matchWorld(sender, args.getString(0));
}
final RegionManager mgr = plugin.getGlobalRegionManager().get(world);
final String id; final String id;
// Get different values based on provided arguments // Get different values based on provided arguments
switch (args.argsLength()) { switch (args.argsLength()) {
case 0: case 0:
player = plugin.checkPlayer(sender); if (localPlayer == null) {
localPlayer = plugin.wrapPlayer(player); throw new CommandException("A player is expected.");
world = player.getWorld(); }
Vector pt = BukkitUtil.toVector(player.getLocation()); final Vector pt = localPlayer.getPosition();
RegionManager mgr = plugin.getGlobalRegionManager().get(world); final ApplicableRegionSet set = mgr.getApplicableRegions(pt);
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (set.size() == 0) { if (set.size() == 0) {
throw new CommandException("No region ID specified and no region found at current location!"); throw new CommandException("No region ID specified and no region found at current location!");
} }
@ -411,82 +421,80 @@ public void info(CommandContext args, CommandSender sender) throws CommandExcept
break; break;
case 1: case 1:
player = plugin.checkPlayer(sender);
localPlayer = plugin.wrapPlayer(player);
world = player.getWorld();
id = args.getString(0).toLowerCase(); id = args.getString(0).toLowerCase();
break; break;
default: default:
player = null;
localPlayer = null;
world = plugin.matchWorld(sender, args.getString(0));
id = args.getString(1).toLowerCase(); id = args.getString(1).toLowerCase();
break;
} }
RegionManager mgr = plugin.getGlobalRegionManager().get(world); final ProtectedRegion region = mgr.getRegion(id);
if (!mgr.hasRegion(id)) { if (region == null) {
if (!ProtectedRegion.isValidId(id)) { if (!ProtectedRegion.isValidId(id)) {
throw new CommandException("Invalid region ID specified!"); throw new CommandException("Invalid region ID specified!");
} }
throw new CommandException("A region with ID '" + id + "' doesn't exist."); throw new CommandException("A region with ID '" + id + "' doesn't exist.");
} }
ProtectedRegion region = mgr.getRegion(id); displayRegion(sender, localPlayer, region);
}
if (player != null) { public void displayRegion(CommandSender sender, final LocalPlayer localPlayer, ProtectedRegion region) throws CommandPermissionsException {
if (region.isOwner(localPlayer)) { if (localPlayer == null) {
plugin.checkPermission(sender, "worldguard.region.info.own"); plugin.checkPermission(sender, "worldguard.region.info");
} else if (region.isMember(localPlayer)) { } else if (region.isOwner(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.info.member"); plugin.checkPermission(sender, "worldguard.region.info.own");
} else { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.info"); plugin.checkPermission(sender, "worldguard.region.info.member");
}
} else { } else {
plugin.checkPermission(sender, "worldguard.region.info"); plugin.checkPermission(sender, "worldguard.region.info");
} }
DefaultDomain owners = region.getOwners(); final String id = region.getId();
DefaultDomain members = region.getMembers();
sender.sendMessage(ChatColor.YELLOW + "Region: " + id sender.sendMessage(ChatColor.YELLOW + "Region: " + id + ChatColor.GRAY + ", type: " + region.getTypeName() + ", " + ChatColor.BLUE + "Priority: " + region.getPriority());
+ ChatColor.GRAY + " (type: " + region.getTypeName() + ")");
if (!ProtectedRegion.isValidId(id)) {
sender.sendMessage(ChatColor.RED + "This region has an invalid ID. "
+ "Please ask the owner to delete it and recreate it.");
}
sender.sendMessage(ChatColor.BLUE + "Priority: " + region.getPriority());
StringBuilder s = new StringBuilder();
boolean hasFlags = false;
final StringBuilder s = new StringBuilder(ChatColor.BLUE + "Flags: ");
for (Flag<?> flag : DefaultFlag.getFlags()) { for (Flag<?> flag : DefaultFlag.getFlags()) {
Object val = region.getFlag(flag); Object val = region.getFlag(flag);
if (val == null) { if (val == null) {
continue; continue;
} }
if (s.length() > 0) { if (s.length() > 0) {
s.append(", "); s.append(", ");
} }
s.append(flag.getName() + ": " + String.valueOf(val)); s.append(flag.getName() + ": " + String.valueOf(val));
hasFlags = true;
}
if (hasFlags) {
sender.sendMessage(s.toString());
} }
sender.sendMessage(ChatColor.BLUE + "Flags: " + s.toString()); if (region.getParent() != null) {
sender.sendMessage(ChatColor.BLUE + "Parent: " sender.sendMessage(ChatColor.BLUE + "Parent: " + region.getParent().getId());
+ (region.getParent() == null ? "(none)" : region.getParent().getId())); }
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Owners: "
+ owners.toUserFriendlyString()); final DefaultDomain owners = region.getOwners();
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Members: " if (owners.size() != 0) {
+ members.toUserFriendlyString()); sender.sendMessage(ChatColor.LIGHT_PURPLE + "Owners: " + owners.toUserFriendlyString());
BlockVector min = region.getMinimumPoint(); }
BlockVector max = region.getMaximumPoint();
String c = "(" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ")"; final DefaultDomain members = region.getMembers();
c += " (" +max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")"; if (members.size() != 0) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Bounds: " + c); sender.sendMessage(ChatColor.LIGHT_PURPLE + "Members: " + members.toUserFriendlyString());
}
final BlockVector min = region.getMinimumPoint();
final BlockVector max = region.getMaximumPoint();
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Bounds:"
+ " (" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ")"
+ " (" + max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")"
);
} }
@Command(aliases = {"list"}, usage = "[.player] [page] [world]", @Command(aliases = {"list"}, usage = "[.player] [page] [world]",