Improved to operate like.. "banip <IP|Username>" bans the specified IP or the IP of the user specified.

This commit is contained in:
zzbomb 2011-10-08 10:04:07 -03:00
parent 06900e19f0
commit 16384159e7

View File

@ -3,7 +3,8 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Commandbanip extends EssentialsCommand public class Commandbanip extends EssentialsCommand
{ {
@ -20,7 +21,22 @@ public class Commandbanip extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
if ( isIPAddress(args[0]) {
ess.getServer().banIP(args[0]); ess.getServer().banIP(args[0]);
sender.sendMessage(Util.i18n("banIpAddress")); sender.sendMessage(Util.i18n("banIpAddress"));
} }
else {
User u = ess.getUser(p);
ess.getServer().banIP(u.getAddress().getAddress().toString());
sender.sendMessage(Util.i18n("banIpAddress"));
}
}
private boolean isIPAddress(String str) {
String expression = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
Pattern pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
return matcher.matches();
}
} }