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;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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();
|
2011-10-30 19:27:06 +00:00
|
|
|
String new_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
|
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
|
|
|
|
|
|
|
if (!plugin.superadmins.contains(user_name))
|
|
|
|
{
|
|
|
|
plugin.superadmins.add(user_name);
|
2011-10-30 19:27:06 +00:00
|
|
|
sender.sendMessage("Adding new superadmin: " + user_name);
|
|
|
|
something_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!plugin.superadmin_ips.contains(new_ip))
|
|
|
|
{
|
|
|
|
plugin.superadmin_ips.add(new_ip);
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
user_ips = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin.superadmins.remove(user_name);
|
|
|
|
|
|
|
|
if (config.contains(user_name))
|
|
|
|
{
|
|
|
|
List<String> user_ips = config.getStringList(user_name);
|
|
|
|
for (String ip : user_ips)
|
|
|
|
{
|
|
|
|
plugin.superadmin_ips.remove(ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|