TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java

57 lines
1.3 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
2013-03-10 22:43:20 +00:00
import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.User;
2013-06-08 21:31:19 +00:00
import com.earth2me.essentials.utils.FormatUtil;
import java.util.logging.Level;
import org.bukkit.Server;
public class Commandunbanip extends EssentialsCommand
{
public Commandunbanip()
{
super("unbanip");
}
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
2013-06-09 20:35:51 +00:00
2013-03-10 22:43:20 +00:00
String ipAddress;
2013-06-08 21:31:19 +00:00
if (FormatUtil.validIP(args[0]))
2013-03-10 22:43:20 +00:00
{
ipAddress = args[0];
}
else
{
2013-06-09 20:35:51 +00:00
try
2013-03-10 22:43:20 +00:00
{
2013-06-09 20:35:51 +00:00
User player = getPlayer(server, args, 0, true, true);
ipAddress = player.getLastLoginAddress();
2013-03-10 22:43:20 +00:00
}
2013-06-09 20:35:51 +00:00
catch (PlayerNotFoundException ex)
{
ipAddress = args[0];
}
}
if (ipAddress.isEmpty())
{
throw new PlayerNotFoundException();
}
2013-03-10 22:43:20 +00:00
ess.getServer().unbanIP(ipAddress);
final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME;
server.getLogger().log(Level.INFO, tl("playerUnbanIpAddress", senderName, ipAddress));
ess.broadcastMessage("essentials.ban.notify", tl("playerUnbanIpAddress", senderName, ipAddress));
}
}