2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
2019-01-29 04:57:41 +00:00
|
|
|
import java.util.ArrayList;
|
2019-01-28 01:49:07 +00:00
|
|
|
import java.util.Arrays;
|
2019-01-29 04:57:41 +00:00
|
|
|
import java.util.Collections;
|
2018-07-31 07:01:29 +00:00
|
|
|
import java.util.Date;
|
2019-01-28 01:49:07 +00:00
|
|
|
import java.util.List;
|
2019-04-21 00:16:00 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
2020-09-12 19:42:12 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.discord.Discord;
|
2016-03-02 19:28:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2020-12-04 00:28:53 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
2016-03-02 19:28:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2019-07-28 06:04:16 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2016-03-02 19:28:01 +00:00
|
|
|
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)
|
2020-12-04 00:28:53 +00:00
|
|
|
@CommandParameters(description = "List, add, remove, or set the rank of admins, clean or reload the admin list, or view admin information.", usage = "/<command> <list | clean | reload | | setrank <username> <rank> | <add | remove | info> <username>>", aliases = "slconfig")
|
|
|
|
public class Command_saconfig extends FreedomCommand
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
@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":
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
msg("Admins: " + StringUtils.join(plugin.al.getAdminNames(), ", "), ChatColor.GOLD);
|
2016-03-02 19:28:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "clean":
|
|
|
|
{
|
2020-07-20 02:10:51 +00:00
|
|
|
checkConsole();
|
2020-09-28 02:51:15 +00:00
|
|
|
checkRank(Rank.SENIOR_ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Cleaning the admin list", true);
|
|
|
|
plugin.al.deactivateOldEntries(true);
|
|
|
|
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":
|
|
|
|
{
|
2020-09-28 02:51:15 +00:00
|
|
|
checkRank(Rank.SENIOR_ADMIN);
|
2016-03-07 20:32:05 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Reloading the admin list", true);
|
|
|
|
plugin.al.load();
|
|
|
|
msg("Admin list reloaded!");
|
2016-03-07 20:32:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "setrank":
|
|
|
|
{
|
2020-07-20 02:10:51 +00:00
|
|
|
checkConsole();
|
2020-09-28 02:51:15 +00:00
|
|
|
checkRank(Rank.SENIOR_ADMIN);
|
2016-05-12 19:40:39 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2020-07-20 02:10:51 +00:00
|
|
|
msg("Unknown rank: " + args[2]);
|
2016-05-12 19:40:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-26 10:43:36 +00:00
|
|
|
if (rank.isConsole())
|
|
|
|
{
|
|
|
|
msg("You cannot set players to a console rank");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-28 03:17:01 +00:00
|
|
|
if (!rank.isAtLeast(Rank.ADMIN))
|
2016-03-07 20:32:05 +00:00
|
|
|
{
|
2020-11-30 23:17:27 +00:00
|
|
|
msg("Rank must be Admin or higher.", ChatColor.RED);
|
2016-03-07 20:32:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
Admin admin = plugin.al.getEntryByName(args[1]);
|
|
|
|
if (admin == null)
|
2016-03-07 20:32:05 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
msg("Unknown admin: " + args[1]);
|
2016-03-07 20:32:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Setting " + admin.getName() + "'s rank to " + rank.getName(), true);
|
2016-05-12 19:40:39 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
admin.setRank(rank);
|
|
|
|
plugin.al.save(admin);
|
2016-03-07 20:32:05 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
Player player = getPlayer(admin.getName());
|
2018-03-03 04:29:08 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
plugin.rm.updateDisplay(player);
|
|
|
|
}
|
|
|
|
|
2019-04-21 00:16:00 +00:00
|
|
|
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
Discord.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
|
2019-04-21 00:16:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.ptero.updateAccountStatus(admin);
|
2020-08-08 05:51:09 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
msg("Set " + admin.getName() + "'s rank to " + rank.getName());
|
2016-03-07 20:32:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
case "info":
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-28 03:17:01 +00:00
|
|
|
checkRank(Rank.ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
Admin admin = plugin.al.getEntryByName(args[1]);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (admin == null)
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
|
|
|
final Player player = getPlayer(args[1]);
|
|
|
|
if (player != null)
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
admin = plugin.al.getAdmin(player);
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (admin == null)
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
msg("Admin not found: " + args[1]);
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
msg(admin.toString());
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "add":
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-20 02:10:51 +00:00
|
|
|
checkConsole();
|
2020-09-28 03:17:01 +00:00
|
|
|
checkRank(Rank.ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
// Player already admin?
|
2016-03-02 19:28:01 +00:00
|
|
|
final Player player = getPlayer(args[1]);
|
2018-07-25 05:54:00 +00:00
|
|
|
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
msg(FreedomCommand.PLAYER_NOT_FOUND);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isAdmin(player))
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
msg("That player is already an admin.");
|
2016-03-02 19:28:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
// Find the old admin entry
|
2016-03-07 20:32:05 +00:00
|
|
|
String name = player != null ? player.getName() : args[1];
|
2020-12-04 00:28:53 +00:00
|
|
|
Admin admin = null;
|
|
|
|
for (Admin loopAdmin : plugin.al.getAllAdmins())
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(FUtil.getIp(player)))
|
2016-03-07 20:32:05 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
admin = loopAdmin;
|
2016-03-07 20:32:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
if (plugin.pl.isPlayerImpostor(player))
|
2019-02-09 17:30:02 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
msg("This player was labeled as a Player impostor and is not an admin, therefore they cannot be added to the admin list.", ChatColor.RED);
|
2019-02-09 17:30:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +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
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the admin list", true);
|
|
|
|
admin = new Admin(player);
|
2019-04-21 00:16:00 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.al.addAdmin(admin);
|
2020-05-29 10:14:21 +00:00
|
|
|
plugin.rm.updateDisplay(player);
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.ptero.updateAccountStatus(admin);
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
else // Existing admin
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Re-adding " + player.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
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
String oldName = admin.getName();
|
2020-06-30 07:25:38 +00:00
|
|
|
if (oldName != player.getName())
|
2020-07-17 04:40:10 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
admin.setName(player.getName());
|
|
|
|
plugin.sql.updateAdminName(oldName, admin.getName());
|
2020-07-17 04:40:10 +00:00
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
admin.addIp(FUtil.getIp(player));
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
admin.setActive(true);
|
|
|
|
admin.setLastLogin(new Date());
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isVerifiedAdmin(player))
|
2019-08-04 02:50:31 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.al.verifiedNoAdmin.remove(player.getName());
|
|
|
|
plugin.al.verifiedNoAdminIps.remove(player.getName());
|
2019-08-04 02:50:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.al.save(admin);
|
|
|
|
plugin.al.updateTables();
|
2018-03-03 04:29:08 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
plugin.rm.updateDisplay(player);
|
|
|
|
}
|
2019-04-21 00:16:00 +00:00
|
|
|
|
|
|
|
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.dc.syncRoles(admin, plugin.pl.getData(player).getDiscordID());
|
2019-04-21 00:16:00 +00:00
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.ptero.updateAccountStatus(admin);
|
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);
|
2020-07-20 02:10:51 +00:00
|
|
|
msg(player, "You have been unfrozen.");
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
2018-03-03 04:29:08 +00:00
|
|
|
|
|
|
|
if (!player.isOp())
|
|
|
|
{
|
|
|
|
player.setOp(true);
|
|
|
|
player.sendMessage(YOU_ARE_OP);
|
|
|
|
}
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "remove":
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-20 02:10:51 +00:00
|
|
|
checkConsole();
|
2020-09-28 03:17:01 +00:00
|
|
|
checkRank(Rank.ADMIN);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
|
|
|
Player player = getPlayer(args[1]);
|
2020-12-04 00:28:53 +00:00
|
|
|
Admin admin = player != null ? plugin.al.getAdmin(player) : plugin.al.getEntryByName(args[1]);
|
2016-03-02 19:28:01 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (admin == null)
|
2016-03-02 19:28:01 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
msg("Admin not found: " + args[1]);
|
2016-03-02 19:28:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Removing " + admin.getName() + " from the admin list", true);
|
|
|
|
admin.setActive(false);
|
2020-08-09 03:20:06 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.al.save(admin);
|
|
|
|
plugin.al.updateTables();
|
2018-03-03 04:29:08 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
plugin.rm.updateDisplay(player);
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.pl.getPlayer(player).setAdminChat(false);
|
2018-03-03 04:29:08 +00:00
|
|
|
}
|
2019-04-21 00:16:00 +00:00
|
|
|
|
|
|
|
if (plugin.dc.enabled && ConfigEntry.DISCORD_ROLE_SYNC.getBoolean())
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
Discord.syncRoles(admin, plugin.pl.getData(admin.getName()).getDiscordID());
|
2019-04-21 00:16:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.ptero.updateAccountStatus(admin);
|
2020-08-08 05:51:09 +00:00
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-28 01:49:07 +00:00
|
|
|
|
2019-01-29 04:57:41 +00:00
|
|
|
@Override
|
|
|
|
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
2019-01-28 01:49:07 +00:00
|
|
|
{
|
2020-07-01 03:21:44 +00:00
|
|
|
if (args.length == 1)
|
2019-01-29 04:57:41 +00:00
|
|
|
{
|
2020-07-01 03:21:44 +00:00
|
|
|
List<String> arguments = new ArrayList<>();
|
|
|
|
arguments.add("list");
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isAdmin(sender))
|
2019-01-29 04:57:41 +00:00
|
|
|
{
|
2020-07-01 03:21:44 +00:00
|
|
|
arguments.add("info");
|
|
|
|
arguments.add("add");
|
|
|
|
arguments.add("remove");
|
2019-01-29 04:57:41 +00:00
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isSeniorAdmin(sender))
|
2019-01-29 04:57:41 +00:00
|
|
|
{
|
2020-07-01 03:21:44 +00:00
|
|
|
arguments.add("reload");
|
|
|
|
arguments.add("clean");
|
|
|
|
arguments.add("setrank");
|
2019-01-29 04:57:41 +00:00
|
|
|
}
|
2020-07-01 03:21:44 +00:00
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
if (args.length == 2 && (args[0].equals("add") || args[0].equals("remove") || args[0].equals("setrank") || args[0].equals("info")))
|
|
|
|
{
|
|
|
|
return FUtil.getPlayerList();
|
|
|
|
}
|
|
|
|
if (args.length == 3 && args[0].equals("setrank"))
|
|
|
|
{
|
2020-11-10 02:16:26 +00:00
|
|
|
return Arrays.asList("ADMIN", "SENIOR_ADMIN");
|
2019-01-29 04:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
2020-08-09 03:20:06 +00:00
|
|
|
}
|