summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzbomb <knowhalo@gmail.com>2011-10-08 10:04:07 -0300
committerzzbomb <knowhalo@gmail.com>2011-10-08 10:04:07 -0300
commit71da92dd661349856b7a82be706394533d6d8d73 (patch)
treef13de49c397341c74c7a4fcec6fb750cc5dd8c46
parente7aeb27a7862277c9aec66883bd5ed63c4a67849 (diff)
downloadEssentials-71da92dd661349856b7a82be706394533d6d8d73.tar
Essentials-71da92dd661349856b7a82be706394533d6d8d73.tar.gz
Essentials-71da92dd661349856b7a82be706394533d6d8d73.tar.lz
Essentials-71da92dd661349856b7a82be706394533d6d8d73.tar.xz
Essentials-71da92dd661349856b7a82be706394533d6d8d73.zip
Improved to operate like.. "banip <IP|Username>" bans the specified IP or the IP of the user specified.
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbanip.java48
1 files changed, 32 insertions, 16 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
index 3301afc87..dff0edcbd 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
@@ -3,24 +3,40 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
-
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class Commandbanip extends EssentialsCommand
{
- public Commandbanip()
- {
- super("banip");
- }
-
- @Override
- public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
- {
- if (args.length < 1)
- {
- throw new NotEnoughArgumentsException();
- }
+ public Commandbanip()
+ {
+ super("banip");
+ }
- ess.getServer().banIP(args[0]);
- sender.sendMessage(Util.i18n("banIpAddress"));
- }
+ @Override
+ public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
+ {
+ if (args.length < 1)
+ {
+ throw new NotEnoughArgumentsException();
+ }
+
+ if ( isIPAddress(args[0]) {
+ ess.getServer().banIP(args[0]);
+ 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();
+ }
}