2011-10-19 02:52:32 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
|
2012-11-13 01:42:30 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
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;
|
2012-11-13 01:42:30 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2011-10-19 02:52:32 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
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)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(description = "Manage superadmins.", usage = "/<command> <list | clean | <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)
|
|
|
|
{
|
2012-03-06 19:25:22 +00:00
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
if (args[0].equals("list"))
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminNames(), ", "), ChatColor.GOLD);
|
2012-03-06 19:25:22 +00:00
|
|
|
}
|
2012-11-20 02:50:33 +00:00
|
|
|
else
|
|
|
|
{
|
2013-08-12 09:24:23 +00:00
|
|
|
if (!TFM_SuperadminList.isSeniorAdmin(sender))
|
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
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
if (args[0].equals("clean"))
|
|
|
|
{
|
2013-08-12 09:24:23 +00:00
|
|
|
TFM_Util.adminAction(sender.getName(), "Cleaning superadmin list", true);
|
2012-11-20 02:50:33 +00:00
|
|
|
TFM_SuperadminList.cleanSuperadminList(true);
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Superadmins: " + StringUtils.join(TFM_SuperadminList.getSuperadminNames(), ", "), ChatColor.YELLOW);
|
2012-11-20 02:50:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
2012-11-20 02:50:33 +00:00
|
|
|
else if (args.length == 2)
|
2011-10-19 02:52:32 +00:00
|
|
|
{
|
2012-12-20 01:25:29 +00:00
|
|
|
if (args[0].equalsIgnoreCase("info"))
|
|
|
|
{
|
|
|
|
if (!TFM_SuperadminList.isUserSuperadmin(sender))
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
2012-12-20 01:25:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TFM_Superadmin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase());
|
|
|
|
|
|
|
|
if (superadmin == null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
superadmin = TFM_SuperadminList.getAdminEntry(getPlayer(args[1]).getName().toLowerCase());
|
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (PlayerNotFoundException ex)
|
2012-12-20 01:25:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (superadmin == null)
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Superadmin not found: " + args[1]);
|
2012-12-20 01:25:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-12 10:26:49 +00:00
|
|
|
playerMsg(ChatColor.stripColor(TFM_Util.colorise(superadmin.toString())));
|
2012-12-20 01:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
if (!senderIsConsole)
|
2011-10-19 02:52:32 +00:00
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("This command may only be used from the console.");
|
2011-10-19 02:52:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
if (args[0].equalsIgnoreCase("add"))
|
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
Player player = null;
|
2012-11-20 02:50:33 +00:00
|
|
|
String admin_name = null;
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
try
|
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
player = getPlayer(args[1]);
|
2012-11-20 02:50:33 +00:00
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (PlayerNotFoundException ex)
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
|
|
|
TFM_Superadmin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase());
|
|
|
|
if (superadmin != null)
|
|
|
|
{
|
|
|
|
admin_name = superadmin.getName();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
playerMsg(ex.getMessage(), ChatColor.RED);
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
if (player != null)
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2013-08-14 14:01:42 +00:00
|
|
|
TFM_Util.adminAction(sender.getName(), "Adding " + player.getName() + " to the superadmin list.", true);
|
|
|
|
TFM_SuperadminList.addSuperadmin(player);
|
2012-11-20 02:50:33 +00:00
|
|
|
}
|
|
|
|
else if (admin_name != null)
|
|
|
|
{
|
|
|
|
TFM_Util.adminAction(sender.getName(), "Adding " + admin_name + " to the superadmin list.", true);
|
|
|
|
TFM_SuperadminList.addSuperadmin(admin_name);
|
|
|
|
}
|
2011-10-31 12:00:42 +00:00
|
|
|
}
|
2012-11-20 02:50:33 +00:00
|
|
|
else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("remove"))
|
2011-10-31 12:00:42 +00:00
|
|
|
{
|
2012-11-20 02:50:33 +00:00
|
|
|
if (!TFM_SuperadminList.isSeniorAdmin(sender))
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg(TotalFreedomMod.MSG_NO_PERMS);
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-12-20 01:25:29 +00:00
|
|
|
|
2013-08-14 14:55:37 +00:00
|
|
|
String targetName = args[1];
|
2012-11-20 02:50:33 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2013-08-14 14:55:37 +00:00
|
|
|
targetName = getPlayer(targetName).getName();
|
2012-11-20 02:50:33 +00:00
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (PlayerNotFoundException ex)
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2013-08-14 14:55:37 +00:00
|
|
|
if (!TFM_SuperadminList.getSuperadminNames().contains(targetName.toLowerCase()))
|
2012-11-20 02:50:33 +00:00
|
|
|
{
|
2013-08-14 14:55:37 +00:00
|
|
|
playerMsg("Superadmin not found: " + targetName);
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-14 14:55:37 +00:00
|
|
|
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from the superadmin list", true);
|
|
|
|
TFM_SuperadminList.removeSuperadmin(targetName);
|
2013-07-02 18:31:22 +00:00
|
|
|
|
2013-05-06 20:04:10 +00:00
|
|
|
if (!TotalFreedomMod.twitterbotEnabled)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-02 18:31:22 +00:00
|
|
|
|
2013-03-19 10:50:57 +00:00
|
|
|
// Twitterbot
|
|
|
|
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance(plugin);
|
2013-08-14 14:55:37 +00:00
|
|
|
String reply = twitterbot.delTwitter(targetName);
|
2013-03-19 10:50:57 +00:00
|
|
|
if ("ok".equals(reply))
|
|
|
|
{
|
2013-08-14 14:55:37 +00:00
|
|
|
TFM_Util.adminAction(sender.getName(), "Removing " + targetName + " from TwitterBot", true);
|
2013-03-19 10:50:57 +00:00
|
|
|
}
|
|
|
|
else if ("disabled".equals(reply))
|
|
|
|
{
|
|
|
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
2013-08-12 09:24:23 +00:00
|
|
|
TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until it gets re-enabled", ChatColor.RED);
|
2013-03-19 10:50:57 +00:00
|
|
|
}
|
|
|
|
else if ("failed".equals(reply))
|
|
|
|
{
|
|
|
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
|
|
TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
|
|
|
}
|
|
|
|
else if ("false".equals(reply))
|
|
|
|
{
|
|
|
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
|
|
TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
|
|
|
}
|
|
|
|
else if ("cannotauth".equals(reply))
|
|
|
|
{
|
|
|
|
TFM_Util.playerMsg(sender, "Warning: Could not check if player has a twitter handle!");
|
|
|
|
TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
|
|
|
}
|
|
|
|
else if ("notfound".equals(reply))
|
|
|
|
{
|
2013-08-14 14:55:37 +00:00
|
|
|
TFM_Util.playerMsg(sender, targetName + " did not have a twitter handle registered to their name.", ChatColor.GREEN);
|
2013-03-19 10:50:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
}
|
|
|
|
else
|
2011-10-31 12:00:42 +00:00
|
|
|
{
|
2012-11-20 02:50:33 +00:00
|
|
|
return false;
|
2011-10-31 12:00:42 +00:00
|
|
|
}
|
2012-07-22 18:06:01 +00:00
|
|
|
|
2012-11-20 02:50:33 +00:00
|
|
|
return true;
|
2011-10-31 12:00:42 +00:00
|
|
|
}
|
2012-09-14 22:49:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
|
|
|
}
|