mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-04 22:41:33 +01:00
Easier version of /banip username
This commit is contained in:
parent
5984cd5835
commit
a9a87710f3
@ -1,42 +1,37 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
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
|
||||||
{
|
{
|
||||||
public Commandbanip()
|
public Commandbanip()
|
||||||
{
|
{
|
||||||
super("banip");
|
super("banip");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
if (args.length < 1)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isIPAddress(args[0]) {
|
final User u = ess.getUser(args[0]);
|
||||||
ess.getServer().banIP(args[0]);
|
|
||||||
sender.sendMessage(Util.i18n("banIpAddress"));
|
if (u == null)
|
||||||
}
|
{
|
||||||
else {
|
ess.getServer().banIP(args[0]);
|
||||||
User u = ess.getUser(p);
|
sender.sendMessage(Util.i18n("banIpAddress"));
|
||||||
ess.getServer().banIP(u.getAddress().getAddress().toString());
|
}
|
||||||
sender.sendMessage(Util.i18n("banIpAddress"));
|
else
|
||||||
}
|
{
|
||||||
}
|
ess.getServer().banIP(u.getAddress().getAddress().getHostAddress());
|
||||||
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user