From 1f359da0d1c8a355f5366aa924834d87e3ada8f5 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Mon, 31 Oct 2011 08:00:42 -0400 Subject: [PATCH] Added saconfig delete --- .../Commands/Command_saconfig.java | 91 ++++++++++--------- src/plugin.yml | 2 +- 2 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java index d0919501..7a28ad5a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java @@ -29,47 +29,6 @@ public class Command_saconfig extends TFM_Command 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(); -// String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim(); -// -// sender.sendMessage(ChatColor.GRAY + "Adding " + user_name + " as a superadmin, with current IP = " + user_ip); -// -// if (!plugin.superadmins.contains(user_name)) -// { -// plugin.superadmins.add(user_name); -// } -// -// if (!plugin.superadmin_ips.contains(user_ip)) -// { -// plugin.superadmin_ips.add(user_ip); -// } -// -// try -// { -// FileConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); -// config.set("superadmins", plugin.superadmins); -// config.set("superadmin_ips", plugin.superadmin_ips); -// config.save(new File(plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); -// } -// catch (IOException ex) -// { -// Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); -// } -// } - if (args[0].equalsIgnoreCase("add")) { Player p; @@ -131,6 +90,56 @@ public class Command_saconfig extends TFM_Command log.log(Level.SEVERE, null, ex); } } + 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 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); + } + } return true; } diff --git a/src/plugin.yml b/src/plugin.yml index 214de5aa..40536c5e 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -100,7 +100,7 @@ commands: usage: / saconfig: description: Owner command - Manage superadmins. - usage: / + usage: / say: description: Broadcasts the given message as the console, includes sender name. usage: /