2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2016-03-02 19:28:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import net.pravian.aero.util.Ips;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
2016-03-02 19:28:01 +00:00
|
|
|
@CommandParameters(description = "Manage admins.", usage = "/<command> <list | clean | clearme [ip] | <add | remove | info> <username>>")
|
|
|
|
public class Command_saconfig extends FreedomCommand
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args[0])
|
|
|
|
{
|
|
|
|
case "list":
|
|
|
|
{
|
|
|
|
msg("Superadmins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "clean":
|
|
|
|
{
|
|
|
|
checkConsole();
|
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), "Cleaning admin list", true);
|
|
|
|
plugin.al.deactivateOldEntries(true);
|
2016-03-06 15:56:15 +00:00
|
|
|
msg("Superadmins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "clearme":
|
|
|
|
{
|
|
|
|
checkPlayer();
|
2016-03-06 15:56:15 +00:00
|
|
|
checkRank(Rank.SUPER_ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
final Admin admin = plugin.al.getAdmin(playerSender);
|
|
|
|
|
|
|
|
if (admin == null)
|
|
|
|
{
|
|
|
|
msg("Could not find your admin entry! Please notify a developer.", ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String ip = Ips.getIp(playerSender);
|
|
|
|
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
FUtil.adminAction(sender.getName(), "Cleaning my supered IPs", true);
|
|
|
|
|
|
|
|
int counter = admin.getIps().size() - 1;
|
|
|
|
admin.clearIPs();
|
|
|
|
admin.addIp(ip);
|
|
|
|
|
|
|
|
plugin.al.save(admin);
|
|
|
|
|
|
|
|
msg(counter + " IPs removed.");
|
|
|
|
msg(admin.getIps().get(0) + " is now your only IP address");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!admin.getIps().contains(args[1]))
|
|
|
|
{
|
|
|
|
msg("That IP is not registered to you.");
|
|
|
|
}
|
|
|
|
else if (ip.equals(args[1]))
|
|
|
|
{
|
|
|
|
msg("You cannot remove your current IP.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FUtil.adminAction(sender.getName(), "Removing a supered IP", true);
|
|
|
|
|
|
|
|
admin.removeIp(args[1]);
|
|
|
|
|
|
|
|
plugin.al.save(admin);
|
|
|
|
|
|
|
|
msg("Removed IP " + args[1]);
|
|
|
|
msg("Current IPs: " + StringUtils.join(admin.getIps(), ", "));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "info":
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
checkRank(Rank.SUPER_ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
Admin admin = plugin.al.getEntryByName(args[1]);
|
|
|
|
|
|
|
|
if (admin == null)
|
|
|
|
{
|
|
|
|
final Player player = getPlayer(args[1]);
|
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
admin = plugin.al.getAdmin(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (admin == null)
|
|
|
|
{
|
|
|
|
msg("Superadmin not found: " + args[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg(admin.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "add":
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkConsole();
|
2016-03-06 15:56:15 +00:00
|
|
|
checkRank(Rank.TELNET_ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
final Player player = getPlayer(args[1]);
|
|
|
|
|
|
|
|
if (plugin.al.isAdmin(player))
|
|
|
|
{
|
|
|
|
msg("That player is already admin.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Admin admin = player != null ? plugin.al.getEntryByName(player.getName()) : plugin.al.getEntryByName(args[1]);
|
|
|
|
|
|
|
|
if (admin != null) // Existing admin
|
|
|
|
{
|
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), "Readding " + admin.getName() + " to the admin list", true);
|
|
|
|
|
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
admin.loadFrom(player); // Reset IP, username
|
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
admin.setActive(true);
|
2016-03-02 19:28:01 +00:00
|
|
|
admin.setLastLogin(new Date());
|
|
|
|
plugin.al.save(admin);
|
|
|
|
plugin.al.updateTables();
|
|
|
|
}
|
|
|
|
else // New admin
|
|
|
|
{
|
|
|
|
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
|
|
|
|
plugin.al.addAdmin(new Admin(player));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
|
|
|
if (fPlayer.getFreezeData().isFrozen())
|
|
|
|
{
|
|
|
|
fPlayer.getFreezeData().setFrozen(false);
|
|
|
|
msg(player.getPlayer(), "You have been unfrozen.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "remove":
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkConsole();
|
2016-03-06 15:56:15 +00:00
|
|
|
checkRank(Rank.TELNET_ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
Player player = getPlayer(args[1]);
|
|
|
|
Admin admin = player == null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
|
|
|
|
|
|
|
|
if (admin == null)
|
|
|
|
{
|
|
|
|
msg("Superadmin not found: " + args[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
|
|
|
|
plugin.al.removeAdmin(admin);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|