summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-10-09 07:07:15 -0700
committersnowleo <schneeleo@gmail.com>2011-10-09 07:07:15 -0700
commit8fe08871410b07c2875e30a838a2de58269c8d0c (patch)
tree8708654595a57334045ed0177f70e311b749202f
parent8389a59d5492551bd1f98e49b97b6a1011a79a1f (diff)
parent16384159e7bde8fb895f1b6c26e7fbf8a3a3f259 (diff)
downloadEssentials-8fe08871410b07c2875e30a838a2de58269c8d0c.tar
Essentials-8fe08871410b07c2875e30a838a2de58269c8d0c.tar.gz
Essentials-8fe08871410b07c2875e30a838a2de58269c8d0c.tar.lz
Essentials-8fe08871410b07c2875e30a838a2de58269c8d0c.tar.xz
Essentials-8fe08871410b07c2875e30a838a2de58269c8d0c.zip
Merge pull request #29 from zzbomb/patch-1
Improved to operate like.. "banip <IP|Username>" bans the specified IP or
-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();
+ }
}