2022-03-20 12:35:43 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.commands;
|
|
|
|
|
|
|
|
import me.StevenLawson.TotalFreedomMod.admin.Admin;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.deprecated.twitter.TwitterHandler;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.player.PlayerData;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.util.DeprecationUtil;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
2014-11-29 19:16:00 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2011-10-19 02:52:32 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2014-04-21 15:45:32 +00:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2011-10-19 02:52:32 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2013-03-19 22:05:20 +00:00
|
|
|
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
|
2022-03-20 12:35:43 +00:00
|
|
|
public class Command_saconfig extends FreedomCommand {
|
2011-10-19 02:52:32 +00:00
|
|
|
@Override
|
2022-03-20 12:35:43 +00:00
|
|
|
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
2014-09-19 23:59:29 +00:00
|
|
|
final SAConfigMode mode;
|
2022-03-20 12:35:43 +00:00
|
|
|
try {
|
2014-09-19 23:59:29 +00:00
|
|
|
mode = SAConfigMode.findMode(args, sender, senderIsConsole);
|
2022-03-20 12:35:43 +00:00
|
|
|
} catch (final PermissionsException ex) {
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, ex.getMessage());
|
2014-09-19 23:59:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (final FormatException ex)
|
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, ex.getMessage());
|
2014-04-11 15:24:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-21 15:45:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
switch (mode)
|
2012-03-06 19:25:22 +00:00
|
|
|
{
|
2014-09-19 23:59:29 +00:00
|
|
|
case LIST:
|
2012-03-06 19:25:22 +00:00
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, "Superadmins: " + StringUtils.join(AdminList.getSuperNames(), ", "), ChatColor.GOLD);
|
2014-04-11 15:24:44 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CLEAN:
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
Utilities.adminAction(sender.getName(), "Cleaning superadmin list", true);
|
|
|
|
AdminList.cleanSuperadminList(true);
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, "Superadmins: " + StringUtils.join(AdminList.getSuperNames(), ", "), ChatColor.YELLOW);
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
break;
|
2014-05-05 12:10:32 +00:00
|
|
|
}
|
2014-09-19 23:59:29 +00:00
|
|
|
case CLEARME:
|
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
final Admin admin = AdminList.getEntry(sender_p);
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2015-05-30 18:51:49 +00:00
|
|
|
if (admin == null)
|
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, "Could not find your admin entry! Please notify a developer.", ChatColor.RED);
|
2015-05-30 18:01:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
final String ip = Utilities.getIp(sender_p);
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
if (args.length == 1)
|
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
Utilities.adminAction(sender.getName(), "Cleaning my supered IPs", true);
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
int counter = admin.getIps().size() - 1;
|
|
|
|
admin.clearIPs();
|
|
|
|
admin.addIp(ip);
|
2014-05-05 12:27:33 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
AdminList.saveAll();
|
2014-09-19 23:59:29 +00:00
|
|
|
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, counter + " IPs removed.");
|
|
|
|
playerMsg(sender, admin.getIps().get(0) + " is now your only IP address");
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
|
|
|
else
|
2014-05-05 12:10:32 +00:00
|
|
|
{
|
2014-09-19 23:59:29 +00:00
|
|
|
if (!admin.getIps().contains(args[1]))
|
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, "That IP is not registered to you.");
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
|
|
|
else if (ip.equals(args[1]))
|
2014-05-05 12:10:32 +00:00
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, "You cannot remove your current IP.");
|
2014-05-05 12:10:32 +00:00
|
|
|
}
|
2014-09-19 23:59:29 +00:00
|
|
|
else
|
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
Utilities.adminAction(sender.getName(), "Removing a supered IP", true);
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
admin.removeIp(args[1]);
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
AdminList.saveAll();
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, "Removed IP " + args[1]);
|
|
|
|
playerMsg(sender, "Current IPs: " + StringUtils.join(admin.getIps(), ", "));
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
break;
|
2014-05-05 12:10:32 +00:00
|
|
|
}
|
2014-09-19 23:59:29 +00:00
|
|
|
case INFO:
|
2012-12-20 01:25:29 +00:00
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
Admin superadmin = AdminList.getEntry(args[1].toLowerCase());
|
2012-12-20 01:25:29 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
if (superadmin == null)
|
|
|
|
{
|
|
|
|
final Player player = getPlayer(args[1]);
|
|
|
|
if (player != null)
|
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
superadmin = AdminList.getEntry(player.getName().toLowerCase());
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-05 12:27:33 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
if (superadmin == null)
|
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, "Superadmin not found: " + args[1]);
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, superadmin.toString());
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ADD:
|
|
|
|
{
|
|
|
|
OfflinePlayer player = getPlayer(args[1], true); // Exact case-insensitive match.
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
if (player == null)
|
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
final Admin superadmin = AdminList.getEntry(args[1]);
|
2014-05-05 12:10:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
if (superadmin == null)
|
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, FreedomCommand.PLAYER_NOT_FOUND);
|
2014-09-19 23:59:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
player = DeprecationUtil.getOfflinePlayer(server, superadmin.getLastLoginName());
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
2014-04-26 11:55:24 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
Utilities.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list", true);
|
|
|
|
AdminList.addSuperadmin(player);
|
2014-04-26 11:55:24 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
if (player.isOnline())
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
final PlayerData playerdata = PlayerData.getPlayerData(player.getPlayer());
|
2014-09-19 23:59:29 +00:00
|
|
|
|
|
|
|
if (playerdata.isFrozen())
|
|
|
|
{
|
|
|
|
playerdata.setFrozen(false);
|
|
|
|
playerMsg(player.getPlayer(), "You have been unfrozen.");
|
|
|
|
}
|
2012-11-20 02:50:33 +00:00
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
break;
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
2014-09-19 23:59:29 +00:00
|
|
|
case DELETE:
|
|
|
|
{
|
|
|
|
String targetName = args[1];
|
2012-12-20 01:25:29 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
final Player player = getPlayer(targetName, true); // Exact case-insensitive match.
|
2014-05-04 21:03:34 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
targetName = player.getName();
|
|
|
|
}
|
2014-04-21 15:45:32 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
if (!AdminList.getLowercaseSuperNames().contains(targetName.toLowerCase()))
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2022-03-21 16:02:24 +00:00
|
|
|
playerMsg(sender, "Superadmin not found: " + targetName);
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
Utilities.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
|
|
|
|
AdminList.removeSuperadmin(DeprecationUtil.getOfflinePlayer(server, targetName));
|
2014-04-21 15:45:32 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
// Twitterbot
|
2022-03-20 12:35:43 +00:00
|
|
|
if (ConfigurationEntry.TWITTERBOT_ENABLED.getBoolean())
|
2014-06-22 15:12:30 +00:00
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
TwitterHandler.delTwitterVerbose(targetName, sender);
|
2014-06-22 15:12:30 +00:00
|
|
|
}
|
2014-09-19 23:59:29 +00:00
|
|
|
|
|
|
|
break;
|
2014-06-22 15:12:30 +00:00
|
|
|
}
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
2014-06-22 15:12:30 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
private static enum SAConfigMode {
|
2014-09-19 23:59:29 +00:00
|
|
|
LIST("list", AdminLevel.OP, SourceType.BOTH, 1, 1),
|
|
|
|
CLEAN("clean", AdminLevel.SENIOR, SourceType.BOTH, 1, 1),
|
|
|
|
CLEARME("clearme", AdminLevel.SUPER, SourceType.ONLY_IN_GAME, 1, 2),
|
|
|
|
INFO("info", AdminLevel.SUPER, SourceType.BOTH, 2, 2),
|
|
|
|
ADD("add", AdminLevel.SUPER, SourceType.ONLY_CONSOLE, 2, 2),
|
|
|
|
DELETE("delete", AdminLevel.SENIOR, SourceType.ONLY_CONSOLE, 2, 2);
|
|
|
|
private final String modeName;
|
|
|
|
private final AdminLevel adminLevel;
|
|
|
|
private final SourceType sourceType;
|
|
|
|
private final int minArgs;
|
|
|
|
private final int maxArgs;
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
private SAConfigMode(String modeName, AdminLevel adminLevel, SourceType sourceType, int minArgs, int maxArgs) {
|
2014-09-19 23:59:29 +00:00
|
|
|
this.modeName = modeName;
|
|
|
|
this.adminLevel = adminLevel;
|
|
|
|
this.sourceType = sourceType;
|
|
|
|
this.minArgs = minArgs;
|
|
|
|
this.maxArgs = maxArgs;
|
2011-10-31 12:00:42 +00:00
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
private static SAConfigMode findMode(final String[] args, final CommandSender sender, final boolean senderIsConsole) throws PermissionsException, FormatException
|
2012-09-14 22:49:44 +00:00
|
|
|
{
|
2014-09-19 23:59:29 +00:00
|
|
|
if (args.length == 0)
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
2014-09-19 23:59:29 +00:00
|
|
|
throw new FormatException("Invalid number of arguments.");
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
boolean isSuperAdmin = AdminList.isSuperAdmin(sender);
|
|
|
|
boolean isSeniorAdmin = isSuperAdmin ? AdminList.isSeniorAdmin(sender, false) : false;
|
2014-05-04 21:03:34 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
for (final SAConfigMode mode : values())
|
2014-05-04 21:03:34 +00:00
|
|
|
{
|
2014-09-19 23:59:29 +00:00
|
|
|
if (mode.modeName.equalsIgnoreCase(args[0]))
|
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
if (mode.adminLevel == AdminLevel.SUPER) {
|
|
|
|
if (!isSuperAdmin) {
|
|
|
|
throw new PermissionsException(FreedomCommand.MSG_NO_PERMS);
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
2022-03-20 12:35:43 +00:00
|
|
|
} else if (mode.adminLevel == AdminLevel.SENIOR) {
|
|
|
|
if (!isSeniorAdmin) {
|
|
|
|
throw new PermissionsException(FreedomCommand.MSG_NO_PERMS);
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-04 21:03:34 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
if (mode.sourceType == SourceType.ONLY_IN_GAME)
|
|
|
|
{
|
|
|
|
if (senderIsConsole)
|
|
|
|
{
|
|
|
|
throw new PermissionsException("This command may only be used in-game.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode.sourceType == SourceType.ONLY_CONSOLE)
|
|
|
|
{
|
|
|
|
if (!senderIsConsole)
|
|
|
|
{
|
|
|
|
throw new PermissionsException("This command may only be used from the console.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length >= mode.minArgs && args.length <= mode.maxArgs)
|
|
|
|
{
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new FormatException("Invalid number of arguments for mode: " + mode.modeName);
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
throw new FormatException("Invalid mode.");
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
private static class PermissionsException extends Exception
|
|
|
|
{
|
|
|
|
public PermissionsException(final String message)
|
|
|
|
{
|
|
|
|
super(message);
|
2012-09-14 22:49:44 +00:00
|
|
|
}
|
2014-09-19 23:59:29 +00:00
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
private static class FormatException extends Exception
|
|
|
|
{
|
|
|
|
public FormatException(final String message)
|
|
|
|
{
|
|
|
|
super(message);
|
|
|
|
}
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
|
|
|
}
|