TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_unban.java

68 lines
2.3 KiB
Java
Raw Normal View History

2018-07-25 22:06:19 +00:00
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
2018-07-25 22:06:19 +00:00
import me.totalfreedom.totalfreedommod.banning.Ban;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
2018-07-25 22:06:19 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2020-09-28 03:17:01 +00:00
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
2020-04-23 11:18:03 +00:00
@CommandParameters(description = "Unbans the specified player.", usage = "/<command> <username> [-r]")
2018-07-25 22:06:19 +00:00
public class Command_unban extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length > 0)
2018-07-25 22:06:19 +00:00
{
String username;
final List<String> ips = new ArrayList<>();
final PlayerData entry = plugin.pl.getData(args[0]);
if (entry == null)
{
msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
2018-07-25 22:06:19 +00:00
return true;
}
2020-06-30 07:25:38 +00:00
username = entry.getName();
2018-07-25 22:06:19 +00:00
ips.addAll(entry.getIps());
2020-08-15 22:42:46 +00:00
FUtil.staffAction(sender.getName(), "Unbanning " + username, true);
2020-04-23 11:18:03 +00:00
msg(username + " has been unbanned along with the following IPs: " + StringUtils.join(ips, ", "));
2018-07-25 22:06:19 +00:00
plugin.bm.removeBan(plugin.bm.getByUsername(username));
if (args.length >= 2)
{
2020-04-23 11:18:03 +00:00
if (args[1].equalsIgnoreCase("-r"))
{
2020-04-23 11:18:03 +00:00
plugin.cpb.restore(username);
msg("Restored edits for: " + username);
}
}
2018-07-25 22:06:19 +00:00
for (String ip : ips)
{
Ban ban = plugin.bm.getByIp(ip);
if (ban != null)
{
plugin.bm.removeBan(ban);
}
ban = plugin.bm.getByIp(FUtil.getFuzzyIp(ip));
if (ban != null)
{
plugin.bm.removeBan(ban);
}
}
return true;
}
return false;
}
}