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

56 lines
1.4 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
2013-03-10 22:43:20 +00:00
import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
2013-03-10 22:43:20 +00:00
import com.earth2me.essentials.Util;
import java.util.logging.Level;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
2013-03-10 22:43:20 +00:00
import org.bukkit.entity.Player;
public class Commandunbanip extends EssentialsCommand
{
public Commandunbanip()
{
super("unbanip");
}
@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();
}
2013-03-10 22:43:20 +00:00
String ipAddress;
if (Util.validIP(args[0]))
{
ipAddress = args[0];
}
else
{
final User user = getPlayer(server, args, 0, true);
2013-03-10 22:43:20 +00:00
ipAddress = user.getLastLoginAddress();
if (ipAddress.isEmpty())
{
throw new PlayerNotFoundException();
}
}
2013-03-10 22:43:20 +00:00
ess.getServer().unbanIP(ipAddress);
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
server.getLogger().log(Level.INFO, _("playerUnbanIpAddress", senderName, ipAddress));
2013-03-10 22:43:20 +00:00
for (Player onlinePlayer : server.getOnlinePlayers())
{
2013-03-10 22:43:20 +00:00
final User onlineUser = ess.getUser(onlinePlayer);
if (onlinePlayer == sender || onlineUser.isAuthorized("essentials.ban.notify"))
{
onlinePlayer.sendMessage(_("playerUnbanIpAddress", senderName, ipAddress));
}
}
}
}