Made superadmin entries permanent, can only be removed manually.

/saconfig del will only deactivate the entry, not remove it.
Renamed SuperAwesomeAdmin to Senior Admin.
This commit is contained in:
Steven Lawson 2012-11-18 20:25:47 -05:00
parent 59e6588779
commit 6e266fcff2
9 changed files with 87 additions and 76 deletions

View File

@ -14,7 +14,7 @@ public class Command_doom extends TFM_Command
@Override @Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (!(senderIsConsole && TFM_SuperadminList.isSuperAwesomeAdmin(sender))) if (!(senderIsConsole && TFM_SuperadminList.isSeniorAdmin(sender)))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;

View File

@ -24,7 +24,7 @@ public class Command_fuckoff extends TFM_Command
return true; return true;
} }
if (!TFM_SuperadminList.isSuperAwesomeAdmin(sender_p)) if (!TFM_SuperadminList.isSeniorAdmin(sender_p))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;

View File

@ -16,7 +16,7 @@ public class Command_lockup extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (!(senderIsConsole && TFM_SuperadminList.isSuperAwesomeAdmin(sender))) if (!(senderIsConsole && TFM_SuperadminList.isSeniorAdmin(sender)))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;

View File

@ -13,7 +13,7 @@ public class Command_wipeflatlands extends TFM_Command
@Override @Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (!(senderIsConsole && TFM_SuperadminList.isSuperAwesomeAdmin(sender))) if (!(senderIsConsole && TFM_SuperadminList.isSeniorAdmin(sender)))
{ {
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true; return true;

View File

@ -265,7 +265,7 @@ public class TFM_BlockListener implements Listener
return; return;
} }
if (!TFM_SuperadminList.isSuperAwesomeAdmin(player)) if (!TFM_SuperadminList.isSeniorAdmin(player))
{ {
TFM_Util.playerMsg(player, "You do not have permission to set Command Block commands."); TFM_Util.playerMsg(player, "You do not have permission to set Command Block commands.");
event.setCancelled(true); event.setCancelled(true);

View File

@ -9,19 +9,21 @@ public class TFM_Superadmin
{ {
private final String name; private final String name;
private final String custom_login_message; private final String custom_login_message;
private final boolean is_super_awesome_admin; private final boolean is_senior_admin;
private final List<String> console_aliases; private final List<String> console_aliases;
private List<String> ips; private List<String> ips;
private Date last_login; private Date last_login;
private boolean is_activated;
public TFM_Superadmin(String name, List<String> ips, Date last_login, String custom_login_message, boolean is_super_awesome_admin, List<String> console_aliases) public TFM_Superadmin(String name, List<String> ips, Date last_login, String custom_login_message, boolean is_senior_admin, List<String> console_aliases, boolean is_activated)
{ {
this.name = name.toLowerCase(); this.name = name.toLowerCase();
this.ips = ips; this.ips = ips;
this.last_login = last_login; this.last_login = last_login;
this.custom_login_message = custom_login_message; this.custom_login_message = custom_login_message;
this.is_super_awesome_admin = is_super_awesome_admin; this.is_senior_admin = is_senior_admin;
this.console_aliases = console_aliases; this.console_aliases = console_aliases;
this.is_activated = is_activated;
} }
public TFM_Superadmin(String name, ConfigurationSection section) public TFM_Superadmin(String name, ConfigurationSection section)
@ -30,8 +32,9 @@ public class TFM_Superadmin
this.ips = section.getStringList("ips"); this.ips = section.getStringList("ips");
this.last_login = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L)))); this.last_login = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L))));
this.custom_login_message = section.getString("custom_login_message", ""); this.custom_login_message = section.getString("custom_login_message", "");
this.is_super_awesome_admin = section.getBoolean("is_super_awesome_admin", false); this.is_senior_admin = section.getBoolean("is_senior_admin", false);
this.console_aliases = section.getStringList("console_aliases"); this.console_aliases = section.getStringList("console_aliases");
this.is_activated = section.getBoolean("is_activated", true);
} }
@Override @Override
@ -45,8 +48,9 @@ public class TFM_Superadmin
output.append("- IPs: ").append(StringUtils.join(this.ips, ", ")).append("\n"); output.append("- IPs: ").append(StringUtils.join(this.ips, ", ")).append("\n");
output.append("- Last Login: ").append(TFM_Util.dateToString(this.last_login)).append("\n"); output.append("- Last Login: ").append(TFM_Util.dateToString(this.last_login)).append("\n");
output.append("- Custom Login Message: ").append(this.custom_login_message).append("\n"); output.append("- Custom Login Message: ").append(this.custom_login_message).append("\n");
output.append("- Is Super Awesome Admin: ").append(this.is_super_awesome_admin).append("\n"); output.append("- Is Senior Admin: ").append(this.is_senior_admin).append("\n");
output.append("- Console Aliases: ").append(StringUtils.join(this.console_aliases, ", ")); output.append("- Console Aliases: ").append(StringUtils.join(this.console_aliases, ", ")).append("\n");
output.append("- Is Activated: ").append(this.is_activated);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -76,9 +80,9 @@ public class TFM_Superadmin
return custom_login_message; return custom_login_message;
} }
public boolean isSuperAwesomeAdmin() public boolean isSeniorAdmin()
{ {
return is_super_awesome_admin; return is_senior_admin;
} }
public List<String> getConsoleAliases() public List<String> getConsoleAliases()
@ -95,4 +99,14 @@ public class TFM_Superadmin
{ {
this.last_login = last_login; this.last_login = last_login;
} }
public boolean isActivated()
{
return is_activated;
}
public void setActivated(boolean is_activated)
{
this.is_activated = is_activated;
}
} }

View File

@ -22,7 +22,7 @@ public class TFM_SuperadminList
private static Map<String, TFM_Superadmin> superadminList = new HashMap<String, TFM_Superadmin>(); private static Map<String, TFM_Superadmin> superadminList = new HashMap<String, TFM_Superadmin>();
private static List<String> superadminNames = new ArrayList<String>(); private static List<String> superadminNames = new ArrayList<String>();
private static List<String> superadminIPs = new ArrayList<String>(); private static List<String> superadminIPs = new ArrayList<String>();
private static List<String> superAwesomeAdminsConsole = new ArrayList<String>(); private static List<String> seniorAdminNames = new ArrayList<String>();
private TFM_SuperadminList() private TFM_SuperadminList()
{ {
@ -43,8 +43,6 @@ public class TFM_SuperadminList
{ {
try try
{ {
// convertV1List();
superadminList.clear(); superadminList.clear();
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file); TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
@ -93,50 +91,28 @@ public class TFM_SuperadminList
String admin_name = pair.getKey().toLowerCase(); String admin_name = pair.getKey().toLowerCase();
TFM_Superadmin superadmin = pair.getValue(); TFM_Superadmin superadmin = pair.getValue();
superadminNames.add(admin_name); if (superadmin.isActivated())
for (String ip : superadmin.getIps())
{ {
superadminIPs.add(ip); superadminNames.add(admin_name);
}
if (superadmin.isSuperAwesomeAdmin()) for (String ip : superadmin.getIps())
{
superAwesomeAdminsConsole.add(admin_name);
for (String console_alias : superadmin.getConsoleAliases())
{ {
superAwesomeAdminsConsole.add(console_alias.toLowerCase()); superadminIPs.add(ip);
}
if (superadmin.isSeniorAdmin())
{
seniorAdminNames.add(admin_name);
for (String console_alias : superadmin.getConsoleAliases())
{
seniorAdminNames.add(console_alias.toLowerCase());
}
} }
} }
} }
} }
// public static void convertV1List()
// {
// try
// {
// superadminList.clear();
//
// TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
// FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
//
// if (!config.isConfigurationSection("superadmins"))
// {
// for (String admin_name : config.getKeys(false))
// {
// TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, config.getStringList(admin_name), new Date(), "", false, new ArrayList<String>());
// superadminList.put(admin_name.toLowerCase(), superadmin);
// }
//
// saveSuperadminList();
// }
// }
// catch (Exception ex)
// {
// TFM_Log.severe(ex);
// }
// }
public static void saveSuperadminList() public static void saveSuperadminList()
{ {
try try
@ -156,8 +132,9 @@ public class TFM_SuperadminList
config.set("superadmins." + admin_name + ".ips", superadmin.getIps()); config.set("superadmins." + admin_name + ".ips", superadmin.getIps());
config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin())); config.set("superadmins." + admin_name + ".last_login", TFM_Util.dateToString(superadmin.getLastLogin()));
config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage()); config.set("superadmins." + admin_name + ".custom_login_message", superadmin.getCustomLoginMessage());
config.set("superadmins." + admin_name + ".is_super_awesome_admin", superadmin.isSuperAwesomeAdmin()); config.set("superadmins." + admin_name + ".is_senior_admin", superadmin.isSeniorAdmin());
config.set("superadmins." + admin_name + ".console_aliases", superadmin.getConsoleAliases()); config.set("superadmins." + admin_name + ".console_aliases", superadmin.getConsoleAliases());
config.set("superadmins." + admin_name + ".is_activated", superadmin.isActivated());
} }
config.save(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); config.save(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
@ -212,19 +189,19 @@ public class TFM_SuperadminList
} }
} }
public static boolean isSuperAwesomeAdmin(CommandSender user) public static boolean isSeniorAdmin(CommandSender user)
{ {
String user_name = user.getName().toLowerCase(); String user_name = user.getName().toLowerCase();
if (!(user instanceof Player)) if (!(user instanceof Player))
{ {
return superAwesomeAdminsConsole.contains(user_name); return seniorAdminNames.contains(user_name);
} }
TFM_Superadmin admin_entry = getAdminEntry((Player) user); TFM_Superadmin admin_entry = getAdminEntry((Player) user);
if (admin_entry != null) if (admin_entry != null)
{ {
return admin_entry.isSuperAwesomeAdmin(); return admin_entry.isSeniorAdmin();
} }
return false; return false;
@ -339,13 +316,23 @@ public class TFM_SuperadminList
public static void addSuperadmin(String admin_name, List<String> ips) public static void addSuperadmin(String admin_name, List<String> ips)
{ {
Date last_login = new Date(); admin_name = admin_name.toLowerCase();
String custom_login_message = "";
boolean is_super_awesome_admin = false;
List<String> console_aliases = new ArrayList<String>();
TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, ips, last_login, custom_login_message, is_super_awesome_admin, console_aliases); if (superadminList.containsKey(admin_name))
superadminList.put(admin_name.toLowerCase(), superadmin); {
TFM_Superadmin superadmin = superadminList.get(admin_name);
superadmin.setActivated(true);
}
else
{
Date last_login = new Date();
String custom_login_message = "";
boolean is_senior_admin = false;
List<String> console_aliases = new ArrayList<String>();
TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, ips, last_login, custom_login_message, is_senior_admin, console_aliases, true);
superadminList.put(admin_name.toLowerCase(), superadmin);
}
saveSuperadminList(); saveSuperadminList();
} }
@ -369,10 +356,10 @@ public class TFM_SuperadminList
if (superadminList.containsKey(admin_name)) if (superadminList.containsKey(admin_name))
{ {
superadminList.remove(admin_name); TFM_Superadmin superadmin = superadminList.get(admin_name);
superadmin.setActivated(false);
saveSuperadminList();
} }
saveSuperadminList();
} }
public static void removeSuperadmin(Player p) public static void removeSuperadmin(Player p)

View File

@ -547,7 +547,7 @@ public class TFM_Util
//JeromSar //JeromSar
public static String getRank(CommandSender sender) public static String getRank(CommandSender sender)
{ {
if (TFM_Util.isSuperadminImpostor(sender)) if (TFM_SuperadminList.isSuperadminImpostor(sender))
{ {
return "an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "impostor" + ChatColor.RESET + ChatColor.AQUA + "!"; return "an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "impostor" + ChatColor.RESET + ChatColor.AQUA + "!";
} }
@ -556,17 +556,27 @@ public class TFM_Util
if (admin_entry != null) if (admin_entry != null)
{ {
String custom_login_message = admin_entry.getCustomLoginMessage(); if (admin_entry.isActivated())
if (custom_login_message != null)
{ {
if (!custom_login_message.isEmpty()) String custom_login_message = admin_entry.getCustomLoginMessage();
if (custom_login_message != null)
{ {
return ChatColor.translateAlternateColorCodes('&', custom_login_message); if (!custom_login_message.isEmpty())
{
return ChatColor.translateAlternateColorCodes('&', custom_login_message);
}
}
if (admin_entry.isSeniorAdmin())
{
return "a " + ChatColor.GOLD + "senior admin" + ChatColor.AQUA + ".";
}
else
{
return "an " + ChatColor.RED + "admin" + ChatColor.AQUA + ".";
} }
} }
return "an " + ChatColor.RED + "admin" + ChatColor.AQUA + ".";
} }
if (sender.isOp()) if (sender.isOp())

View File

@ -5,7 +5,7 @@ superadmins:
- 213.211.159.63 - 213.211.159.63
last_login: Fri, 9 Nov 2012 03:09:14 -0500 last_login: Fri, 9 Nov 2012 03:09:14 -0500
custom_login_message: a &5developer&b! custom_login_message: a &5developer&b!
is_super_awesome_admin: true is_senior_admin: true
console_aliases: console_aliases:
- darth - darth
madgeek1450: madgeek1450:
@ -14,7 +14,7 @@ superadmins:
- 8.8.8.8 - 8.8.8.8
last_login: Sun, 11 Nov 2012 01:09:14 -0500 last_login: Sun, 11 Nov 2012 01:09:14 -0500
custom_login_message: the &5chief-developer&b and &6master-ass-kicker&b. custom_login_message: the &5chief-developer&b and &6master-ass-kicker&b.
is_super_awesome_admin: true is_senior_admin: true
console_aliases: console_aliases:
- madgeek - madgeek
markbyron: markbyron:
@ -23,5 +23,5 @@ superadmins:
- 8.8.4.4 - 8.8.4.4
last_login: Sat, 10 Nov 2012 02:09:14 -0500 last_login: Sat, 10 Nov 2012 02:09:14 -0500
custom_login_message: the &downer&b. custom_login_message: the &downer&b.
is_super_awesome_admin: true is_senior_admin: true
console_aliases: [] console_aliases: []