2011-10-19 02:52:32 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2011-10-30 19:27:06 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2011-10-19 02:52:32 +00:00
|
|
|
import java.util.logging.Level;
|
2012-03-06 19:25:22 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
2011-10-19 02:52:32 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
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"))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.GOLD + "Superadmins: " + TFM_Util.implodeStringList(", ", TotalFreedomMod.superadmins));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-19 02:52:32 +00:00
|
|
|
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0].equalsIgnoreCase("add"))
|
|
|
|
{
|
|
|
|
Player p;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
p = getPlayer(args[1]);
|
|
|
|
}
|
|
|
|
catch (CantFindPlayerException ex)
|
|
|
|
{
|
|
|
|
sender.sendMessage(ex.getMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String user_name = p.getName().toLowerCase().trim();
|
2012-03-09 19:01:04 +00:00
|
|
|
String new_ip = p.getAddress().getAddress().getHostAddress();
|
2011-10-19 02:52:32 +00:00
|
|
|
|
2011-10-30 19:27:06 +00:00
|
|
|
boolean something_changed = false;
|
2011-10-19 02:52:32 +00:00
|
|
|
|
2011-11-21 06:47:19 +00:00
|
|
|
if (!TotalFreedomMod.superadmins.contains(user_name))
|
2011-10-19 02:52:32 +00:00
|
|
|
{
|
2011-11-21 06:47:19 +00:00
|
|
|
TotalFreedomMod.superadmins.add(user_name);
|
2011-10-30 19:27:06 +00:00
|
|
|
sender.sendMessage("Adding new superadmin: " + user_name);
|
|
|
|
something_changed = true;
|
|
|
|
}
|
|
|
|
|
2011-11-21 06:47:19 +00:00
|
|
|
if (!TotalFreedomMod.superadmin_ips.contains(new_ip))
|
2011-10-30 19:27:06 +00:00
|
|
|
{
|
2011-11-21 06:47:19 +00:00
|
|
|
TotalFreedomMod.superadmin_ips.add(new_ip);
|
2011-10-30 19:27:06 +00:00
|
|
|
sender.sendMessage("Adding new superadmin IP: " + new_ip);
|
|
|
|
something_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!something_changed)
|
|
|
|
{
|
|
|
|
sender.sendMessage("That superadmin/superadmin ip pair already exists. Nothing to change!");
|
|
|
|
}
|
|
|
|
|
|
|
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
|
|
|
|
|
|
|
List<String> user_ips = new ArrayList<String>();
|
|
|
|
if (config.contains(user_name))
|
|
|
|
{
|
2011-11-28 22:44:51 +00:00
|
|
|
user_ips = (List<String>) config.getStringList(user_name);
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
|
|
|
|
2011-10-30 19:27:06 +00:00
|
|
|
if (!user_ips.contains(new_ip))
|
2011-10-19 02:52:32 +00:00
|
|
|
{
|
2011-10-30 19:27:06 +00:00
|
|
|
user_ips.add(new_ip);
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
|
|
|
|
2011-10-30 19:27:06 +00:00
|
|
|
config.set(user_name, user_ips);
|
|
|
|
|
2011-10-19 02:52:32 +00:00
|
|
|
try
|
|
|
|
{
|
2011-10-30 19:27:06 +00:00
|
|
|
config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
2011-10-30 19:27:06 +00:00
|
|
|
log.log(Level.SEVERE, null, ex);
|
2011-10-19 02:52:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-31 12:00:42 +00:00
|
|
|
else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("del"))
|
|
|
|
{
|
|
|
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
|
|
|
|
|
|
|
String user_name = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Player p = getPlayer(args[1]);
|
|
|
|
user_name = p.getName().toLowerCase().trim();
|
|
|
|
}
|
|
|
|
catch (CantFindPlayerException ex)
|
|
|
|
{
|
|
|
|
for (String user : config.getKeys(false))
|
|
|
|
{
|
|
|
|
if (user.equalsIgnoreCase(args[1]))
|
|
|
|
{
|
|
|
|
user_name = user;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user_name == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage("Superadmin not found: " + user_name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-21 06:47:19 +00:00
|
|
|
TotalFreedomMod.superadmins.remove(user_name);
|
2011-10-31 12:00:42 +00:00
|
|
|
|
|
|
|
if (config.contains(user_name))
|
|
|
|
{
|
2011-11-28 22:44:51 +00:00
|
|
|
List<String> user_ips = (List<String>) config.getStringList(user_name);
|
2011-10-31 12:00:42 +00:00
|
|
|
for (String ip : user_ips)
|
|
|
|
{
|
2011-11-21 06:47:19 +00:00
|
|
|
TotalFreedomMod.superadmin_ips.remove(ip);
|
2011-10-31 12:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
config.set(user_name, null);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
log.log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
}
|
2011-10-19 02:52:32 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|