summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-10-09 16:44:35 +0200
committersnowleo <schneeleo@gmail.com>2011-10-09 16:44:35 +0200
commita9a87710f3a7ddabf22ac524ccd8de764d97e5d7 (patch)
tree6c14f9d3aed96d84c126f3f06bf22492d2b2db1b
parent5984cd58356b554e19c1e0342f91f06508ecfdb6 (diff)
downloadEssentials-a9a87710f3a7ddabf22ac524ccd8de764d97e5d7.tar
Essentials-a9a87710f3a7ddabf22ac524ccd8de764d97e5d7.tar.gz
Essentials-a9a87710f3a7ddabf22ac524ccd8de764d97e5d7.tar.lz
Essentials-a9a87710f3a7ddabf22ac524ccd8de764d97e5d7.tar.xz
Essentials-a9a87710f3a7ddabf22ac524ccd8de764d97e5d7.zip
Easier version of /banip username
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbanip.java59
1 files changed, 27 insertions, 32 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
index dff0edcbd..591542bcb 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
@@ -1,42 +1,37 @@
package com.earth2me.essentials.commands;
+import com.earth2me.essentials.User;
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");
- }
+ public Commandbanip()
+ {
+ super("banip");
+ }
+
+ @Override
+ public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
+ {
+ if (args.length < 1)
+ {
+ throw new NotEnoughArgumentsException();
+ }
+
+ final User u = ess.getUser(args[0]);
- @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();
- }
+ if (u == null)
+ {
+ ess.getServer().banIP(args[0]);
+ sender.sendMessage(Util.i18n("banIpAddress"));
+ }
+ else
+ {
+ ess.getServer().banIP(u.getAddress().getAddress().getHostAddress());
+ sender.sendMessage(Util.i18n("banIpAddress"));
+ }
+ }
}