Merge pull request #99 from Moo0/listbyname

Filter "/region list" by user.
This commit is contained in:
MonsieurApple 2011-05-16 17:11:13 -07:00
commit ba3818884d

View File

@ -437,22 +437,40 @@ public static void info(CommandContext args, WorldGuardPlugin plugin,
} }
@Command(aliases = {"list"}, @Command(aliases = {"list"},
usage = "[page] [world]", usage = "[.player] [page] [world]",
desc = "Get a list of regions", desc = "Get a list of regions",
flags = "", min = 0, max = 2) flags = "", min = 0, max = 3)
@CommandPermissions({"worldguard.region.list"}) // @CommandPermissions({"worldguard.region.list"})
public static void list(CommandContext args, WorldGuardPlugin plugin, public static void list(CommandContext args, WorldGuardPlugin plugin,
CommandSender sender) throws CommandException { CommandSender sender) throws CommandException {
World world; World world;
int page = 0; int page = 0;
int argl = 0;
String name = "";
boolean own = false;
LocalPlayer localPlayer = null;
if (args.argsLength() > 0) { if (args.argsLength() > 0 && args.getString(0).startsWith(".")) {
page = Math.max(0, args.getInteger(0) - 1); name = args.getString(0).substring(1).toLowerCase();
argl = 1;
if (name.equals("me") || name.isEmpty() ||
name.equals(plugin.checkPlayer(sender).getDisplayName().toLowerCase())) {
plugin.checkPermission(sender, "worldguard.region.list.own");
name = plugin.checkPlayer(sender).getDisplayName().toLowerCase();
localPlayer = plugin.wrapPlayer(plugin.checkPlayer(sender));
own = true;
}
}
if (!own)
plugin.checkPermission(sender, "worldguard.region.list");
if (args.argsLength() > 0 + argl) {
page = Math.max(0, args.getInteger(0 + argl) - 1);
} }
if (args.argsLength() > 1) { if (args.argsLength() > 1 + argl) {
world = plugin.matchWorld(sender, args.getString(1)); world = plugin.matchWorld(sender, args.getString(1 + argl));
} else { } else {
world = plugin.checkPlayer(sender).getWorld(); world = plugin.checkPlayer(sender).getWorld();
} }
@ -461,18 +479,54 @@ public static void list(CommandContext args, WorldGuardPlugin plugin,
RegionManager mgr = plugin.getGlobalRegionManager().get(world); RegionManager mgr = plugin.getGlobalRegionManager().get(world);
Map<String, ProtectedRegion> regions = mgr.getRegions(); Map<String, ProtectedRegion> regions = mgr.getRegions();
int size = regions.size(); int size = regions.size();
int pages = (int) Math.ceil(size / (float) listSize);
String[] regionIDList = new String[size]; String[] regionIDList = new String[size];
int index = 0; int index = 0;
boolean show = false;
String prefix = "";
for (String id : regions.keySet()) { for (String id : regions.keySet()) {
regionIDList[index] = id; show = false;
index++; prefix = "";
if (name.isEmpty()) {
show = true;
}
else {
if (own) {
if (regions.get(id).isOwner(localPlayer)) {
show = true;
prefix += "+";
}
else if (regions.get(id).isMember(localPlayer)) {
show = true;
prefix += "-";
}
}
else {
if (regions.get(id).getOwners().getPlayers().contains(name)) {
show = true;
prefix += "+";
}
if (regions.get(id).getMembers().getPlayers().contains(name)) {
show = true;
prefix += "-";
}
}
}
if (show) {
regionIDList[index] = prefix + " " + id;
index++;
}
} }
if (!name.isEmpty())
regionIDList = Arrays.copyOf(regionIDList, index);
Arrays.sort(regionIDList); Arrays.sort(regionIDList);
size = index;
int pages = (int) Math.ceil(size / (float) listSize);
sender.sendMessage(ChatColor.RED + "Regions (page " sender.sendMessage(ChatColor.RED
+ (name == "" ? "Regions (page " : "Regions for " + name + " (page ")
+ (page + 1) + " of " + pages + "):"); + (page + 1) + " of " + pages + "):");
if (page < pages) { if (page < pages) {
@ -481,7 +535,7 @@ public static void list(CommandContext args, WorldGuardPlugin plugin,
break; break;
} }
sender.sendMessage(ChatColor.YELLOW.toString() + (i + 1) + sender.sendMessage(ChatColor.YELLOW.toString() + (i + 1) +
". " + regionIDList[i]); "." + regionIDList[i]);
} }
} }
} }