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-05-12 19:40:39 +00:00
|
|
|
@CommandParameters(description = "Manage admins.", usage = "/<command> <list | clean | reload | | setrank <username> <rank> | <add | remove | info> <username>>")
|
2016-03-02 19:28:01 +00:00
|
|
|
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":
|
|
|
|
{
|
2018-01-02 02:46:35 +00:00
|
|
|
msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "clean":
|
|
|
|
{
|
|
|
|
checkConsole();
|
2016-05-12 19:40:39 +00:00
|
|
|
checkRank(Rank.TELNET_ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), "Cleaning admin list", true);
|
|
|
|
plugin.al.deactivateOldEntries(true);
|
2018-01-02 02:46:35 +00:00
|
|
|
msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-07 20:32:05 +00:00
|
|
|
case "reload":
|
|
|
|
{
|
|
|
|
checkRank(Rank.SUPER_ADMIN);
|
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), "Reloading the admin list", true);
|
|
|
|
plugin.al.load();
|
|
|
|
msg("Admin list reloaded!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "setrank":
|
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
checkConsole();
|
|
|
|
checkNotHostConsole();
|
|
|
|
checkRank(Rank.SENIOR_CONSOLE);
|
|
|
|
|
2016-03-07 20:32:05 +00:00
|
|
|
if (args.length < 3)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rank rank = Rank.findRank(args[2]);
|
2016-05-12 19:40:39 +00:00
|
|
|
if (rank == null)
|
|
|
|
{
|
|
|
|
msg("Unknown rank: " + rank);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-26 10:43:36 +00:00
|
|
|
if (rank.isConsole())
|
|
|
|
{
|
|
|
|
msg("You cannot set players to a console rank");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-07 20:32:05 +00:00
|
|
|
if (!rank.isAtLeast(Rank.SUPER_ADMIN))
|
|
|
|
{
|
|
|
|
msg("Rank must be superadmin or higher.", ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Admin admin = plugin.al.getEntryByName(args[1]);
|
|
|
|
if (admin == null)
|
|
|
|
{
|
|
|
|
msg("Unknown admin: " + args[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Setting " + admin.getName() + "'s rank to " + rank.getName(), true);
|
|
|
|
|
2016-03-07 20:32:05 +00:00
|
|
|
admin.setRank(rank);
|
2016-05-12 19:40:39 +00:00
|
|
|
plugin.al.save();
|
2016-03-07 20:32:05 +00:00
|
|
|
|
|
|
|
msg("Set " + admin.getName() + "'s rank to " + rank.getName());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
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)
|
|
|
|
{
|
2018-01-02 02:46:35 +00:00
|
|
|
msg("Admin not found: " + args[1]);
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
// Player already an admin?
|
2016-03-02 19:28:01 +00:00
|
|
|
final Player player = getPlayer(args[1]);
|
2016-05-12 19:40:39 +00:00
|
|
|
if (player != null && plugin.al.isAdmin(player))
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
|
|
|
msg("That player is already admin.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
// Find the old admin entry
|
2016-03-07 20:32:05 +00:00
|
|
|
String name = player != null ? player.getName() : args[1];
|
|
|
|
Admin admin = null;
|
|
|
|
for (Admin loopAdmin : plugin.al.getAllAdmins().values())
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2016-03-07 20:32:05 +00:00
|
|
|
if (loopAdmin.getName().equalsIgnoreCase(name))
|
|
|
|
{
|
|
|
|
admin = loopAdmin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
if (admin == null) // New admin
|
2016-03-07 20:32:05 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
if (player == null)
|
2016-03-07 20:32:05 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
|
|
|
return true;
|
2016-03-07 20:32:05 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
|
|
|
|
plugin.al.addAdmin(new Admin(player));
|
2018-01-07 19:33:58 +00:00
|
|
|
plugin.rm.updateDisplay(player);
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
else // Existing admin
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Readding " + admin.getName() + " to the admin list", true);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
if (player != null)
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
admin.setName(player.getName());
|
|
|
|
admin.addIp(Ips.getIp(player));
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
admin.setActive(true);
|
|
|
|
admin.setLastLogin(new Date());
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
plugin.al.save();
|
|
|
|
plugin.al.updateTables();
|
2018-01-07 19:33:58 +00:00
|
|
|
plugin.rm.updateDisplay(player);
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
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]);
|
2016-05-12 19:40:39 +00:00
|
|
|
Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
if (admin == null)
|
|
|
|
{
|
2018-01-02 02:46:35 +00:00
|
|
|
msg("Admin not found: " + args[1]);
|
2016-03-02 19:28:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
|
2016-03-07 20:32:05 +00:00
|
|
|
admin.setActive(false);
|
2016-05-12 19:40:39 +00:00
|
|
|
plugin.al.save();
|
2016-03-07 20:32:05 +00:00
|
|
|
plugin.al.updateTables();
|
2018-01-07 19:33:58 +00:00
|
|
|
plugin.rm.updateDisplay(player);
|
2016-03-02 19:28:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|