2011-10-19 02:52:32 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
|
|
|
2014-04-11 15:24:44 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
2014-04-08 18:31:04 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_Admin;
|
2014-04-09 20:33:03 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
2013-03-19 10:50:57 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
|
2012-03-06 19:25:22 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
2012-11-20 02:50:33 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
2013-12-01 11:13:39 +00:00
|
|
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
2014-04-09 20:33:03 +00:00
|
|
|
import org.bukkit.Bukkit;
|
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)
|
2014-05-05 12:10:32 +00:00
|
|
|
@CommandParameters(description = "Manage superadmins.",
|
|
|
|
usage = "/<command> <list | clean | clear [ip] | <add | delete | info> <username>>")
|
2011-10-19 02:52:32 +00:00
|
|
|
public class Command_saconfig extends TFM_Command
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2014-04-11 15:24:44 +00:00
|
|
|
if (args.length == 0 || args.length > 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-21 15:45:32 +00:00
|
|
|
|
2012-03-06 19:25:22 +00:00
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
if (args[0].equals("list"))
|
|
|
|
{
|
2014-04-21 15:45:32 +00:00
|
|
|
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperNames(), ", "), ChatColor.GOLD);
|
2014-04-11 15:24:44 +00:00
|
|
|
return true;
|
2012-03-06 19:25:22 +00:00
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
|
|
|
|
if (args[0].equals("clean"))
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2014-04-09 20:33:03 +00:00
|
|
|
if (!TFM_AdminList.isSeniorAdmin(sender, true))
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2013-08-12 09:24:23 +00:00
|
|
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2014-04-11 15:24:44 +00:00
|
|
|
TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list", true);
|
|
|
|
TFM_AdminList.cleanSuperadminList(true);
|
2014-04-23 14:23:50 +00:00
|
|
|
playerMsg("Superadmins: " + StringUtils.join(TFM_AdminList.getSuperNames(), ", "), ChatColor.YELLOW);
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-05 12:10:32 +00:00
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2014-05-05 12:10:32 +00:00
|
|
|
// All commands below are superadmin+ commands.
|
|
|
|
if (!TFM_AdminList.isSuperAdmin(sender))
|
|
|
|
{
|
|
|
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
|
|
|
return true;
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
|
2014-05-05 12:10:32 +00:00
|
|
|
if (args[0].equals("clear"))
|
2011-10-19 02:52:32 +00:00
|
|
|
{
|
2014-05-05 12:10:32 +00:00
|
|
|
if (senderIsConsole)
|
|
|
|
{
|
|
|
|
playerMsg(TotalFreedomMod.NOT_FROM_CONSOLE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final TFM_Admin admin = TFM_AdminList.getEntry(sender_p);
|
|
|
|
|
|
|
|
final String ip = TFM_Util.getIp(sender_p);
|
|
|
|
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
2014-05-05 12:27:33 +00:00
|
|
|
TFM_Util.adminAction(sender.getName(), "Cleaning my supered IPs", true);
|
|
|
|
|
2014-05-05 12:10:32 +00:00
|
|
|
int counter = 0;
|
2014-05-05 12:27:33 +00:00
|
|
|
for (int i = 0; i < admin.getIps().size(); i++)
|
2014-05-05 12:10:32 +00:00
|
|
|
{
|
2014-05-05 12:27:33 +00:00
|
|
|
if (admin.getIps().get(i).equals(ip))
|
2014-05-05 12:10:32 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-05 12:27:33 +00:00
|
|
|
admin.removeIp(admin.getIps().get(i));
|
2014-05-05 12:10:32 +00:00
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
TFM_AdminList.save();
|
|
|
|
|
|
|
|
playerMsg(counter + " IPs removed.");
|
|
|
|
playerMsg(admin.getIps().get(0) + " is now your only IP address");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// args.length == 2
|
|
|
|
if (!admin.getIps().contains(args[1]))
|
|
|
|
{
|
|
|
|
playerMsg("That IP is not registered to you.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ip.equals(args[1]))
|
2012-12-20 01:25:29 +00:00
|
|
|
{
|
2014-05-05 12:10:32 +00:00
|
|
|
playerMsg("You cannot remove your current IP.");
|
2012-12-20 01:25:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-05 12:27:33 +00:00
|
|
|
TFM_Util.adminAction(sender.getName(), "Removing a supered IP", true);
|
|
|
|
|
2014-05-05 12:10:32 +00:00
|
|
|
admin.removeIp(args[1]);
|
|
|
|
TFM_AdminList.save();
|
|
|
|
|
|
|
|
playerMsg("Removed IP " + args[1]);
|
|
|
|
playerMsg("Current IPs: " + StringUtils.join(admin.getIps(), ", "));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0].equals("info"))
|
|
|
|
{
|
|
|
|
|
2014-04-11 15:24:44 +00:00
|
|
|
TFM_Admin superadmin = TFM_AdminList.getEntry(args[1].toLowerCase());
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2014-04-11 15:24:44 +00:00
|
|
|
if (superadmin == null)
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
|
|
|
|
final Player player = getPlayer(args[1]);
|
|
|
|
|
|
|
|
if (player != null)
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
superadmin = TFM_AdminList.getEntry(player.getName().toLowerCase());
|
2012-11-20 02:50:33 +00:00
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2014-04-11 15:24:44 +00:00
|
|
|
if (superadmin == null)
|
|
|
|
{
|
|
|
|
playerMsg("Superadmin not found: " + args[1]);
|
2014-05-05 12:10:32 +00:00
|
|
|
return true;
|
2014-04-11 15:24:44 +00:00
|
|
|
}
|
2012-12-20 01:25:29 +00:00
|
|
|
|
2014-05-05 12:10:32 +00:00
|
|
|
playerMsg(superadmin.toString());
|
2014-04-11 15:24:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-20 02:50:33 +00:00
|
|
|
|
2014-04-11 15:24:44 +00:00
|
|
|
if (!senderIsConsole)
|
|
|
|
{
|
|
|
|
playerMsg("This command may only be used from the console.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-05 12:10:32 +00:00
|
|
|
if (args[0].equals("add"))
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
2014-05-05 12:10:32 +00:00
|
|
|
OfflinePlayer player = getPlayer(args[1]);
|
2014-05-04 21:03:34 +00:00
|
|
|
|
2014-04-26 11:55:24 +00:00
|
|
|
if (player == null)
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
|
|
|
final TFM_Admin superadmin = TFM_AdminList.getEntry(args[1]);
|
2014-04-21 15:45:32 +00:00
|
|
|
|
|
|
|
if (superadmin == null)
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
playerMsg(TotalFreedomMod.PLAYER_NOT_FOUND);
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-21 15:45:32 +00:00
|
|
|
player = Bukkit.getOfflinePlayer(superadmin.getLastLoginName());
|
2011-10-31 12:00:42 +00:00
|
|
|
}
|
2014-04-21 15:45:32 +00:00
|
|
|
|
|
|
|
TFM_Util.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list", true);
|
|
|
|
TFM_AdminList.addSuperadmin(player);
|
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
2011-10-31 12:00:42 +00:00
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
|
2014-05-14 14:22:56 +00:00
|
|
|
if ("delete".equals(args[0]))
|
2012-09-14 22:49:44 +00:00
|
|
|
{
|
2014-04-11 15:24:44 +00:00
|
|
|
if (!TFM_AdminList.isSeniorAdmin(sender))
|
|
|
|
{
|
|
|
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String targetName = args[1];
|
|
|
|
|
|
|
|
|
2014-04-26 11:55:24 +00:00
|
|
|
final Player player = getPlayer(targetName);
|
2014-05-04 21:03:34 +00:00
|
|
|
|
|
|
|
if (player != null)
|
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
targetName = player.getName();
|
|
|
|
}
|
2014-05-04 21:03:34 +00:00
|
|
|
|
2014-04-21 15:45:32 +00:00
|
|
|
if (!TFM_AdminList.getLowerSuperNames().contains(targetName.toLowerCase()))
|
2014-04-11 15:24:44 +00:00
|
|
|
{
|
|
|
|
playerMsg("Superadmin not found: " + targetName);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
|
|
|
|
TFM_AdminList.removeSuperadmin(Bukkit.getOfflinePlayer(targetName));
|
|
|
|
|
|
|
|
// Twitterbot
|
|
|
|
if (TFM_ConfigEntry.TWITTERBOT_ENABLED.getBoolean())
|
|
|
|
{
|
|
|
|
TFM_TwitterHandler.getInstance().delTwitterVerbose(targetName, sender);
|
|
|
|
}
|
|
|
|
return true;
|
2012-09-14 22:49:44 +00:00
|
|
|
}
|
2014-04-11 15:24:44 +00:00
|
|
|
return false;
|
|
|
|
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
|
|
|
}
|