Add /dynmap add-id-by-ip and /dynmap del-id-by-ip to allow manual adding and removing of IP to ID mappings

This commit is contained in:
Mike Primm 2011-12-31 04:54:54 +08:00 committed by mikeprimm
parent 3c1c8ec8dc
commit 87be292538
2 changed files with 36 additions and 2 deletions

View File

@ -230,7 +230,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
if (permissions == null)
permissions = BukkitPermissions.create("dynmap");
if (permissions == null)
permissions = new OpPermissions(new String[] { "fullrender", "cancelrender", "radiusrender", "resetstats", "reload", "purgequeue", "pause" });
permissions = new OpPermissions(new String[] { "fullrender", "cancelrender", "radiusrender", "resetstats", "reload", "purgequeue", "pause", "ips-for-id", "ids-for-ip", "add-id-for-ip", "del-id-for-ip" });
dataDirectory = this.getDataFolder();
if(dataDirectory.exists() == false)
@ -836,7 +836,9 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
"pause",
"purgequeue",
"ids-for-ip",
"ips-for-id" }));
"ips-for-id",
"add-id-for-ip",
"del-id-for-ip"}));
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
@ -1074,6 +1076,35 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
else {
sender.sendMessage("Player ID required as parameter");
}
} else if((c.equals("add-id-for-ip") && checkPlayerPermission(sender, "add-id-for-ip")) ||
(c.equals("del-id-for-ip") && checkPlayerPermission(sender, "del-id-for-ip"))) {
if(args.length > 2) {
String ipaddr = "";
try {
InetAddress ip = InetAddress.getByName(args[2]);
ipaddr = ip.getHostAddress();
} catch (UnknownHostException uhx) {
sender.sendMessage("Invalid address : " + args[2]);
return false;
}
LinkedList<String> ids = ids_by_ip.get(ipaddr);
if(ids == null) {
ids = new LinkedList<String>();
ids_by_ip.put(ipaddr, ids);
}
ids.remove(args[1]); /* Remove existing, if any */
if(c.equals("add-id-for-ip")) {
ids.addFirst(args[1]); /* And add us first */
sender.sendMessage("Added player ID '" + args[1] + "' to address '" + ipaddr + "'");
}
else {
sender.sendMessage("Removed player ID '" + args[1] + "' from address '" + ipaddr + "'");
}
saveIDsByIP();
}
else {
sender.sendMessage("Needs player ID and IP address");
}
}
return true;
}

View File

@ -35,6 +35,9 @@ commands:
/<command> pause - Show render pause state
/<command> pause <all|none|full|update> - Set render pause state
/<command> ids-for-ip <ipaddress> - Show player IDs that have logged in from given IP address
/<command> ips-for-id <playerid> - Show IP addresses that have been used for the given player ID
/<command> add-id-for-ip <playerid> <ipaddress> - Add player ID to given IP address
/<command> del-id-for-ip <playerid> <ipaddress> - Delete player ID from given IP address
dmarker:
description: Manipulate map markers