Filter duplicate IPs and shit in superadmin list.

This commit is contained in:
Steven Lawson 2012-11-20 20:29:57 -05:00
parent 8076ee822e
commit 892682e969
3 changed files with 16 additions and 3 deletions

View File

@ -1,7 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.Random;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;

View File

@ -86,6 +86,7 @@ public class TFM_SuperadminList
{
superadminNames.clear();
superadminIPs.clear();
seniorAdminNames.clear();
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
while (it.hasNext())
@ -115,6 +116,10 @@ public class TFM_SuperadminList
}
}
}
superadminNames = TFM_Util.removeDuplicates(superadminNames);
superadminIPs = TFM_Util.removeDuplicates(superadminIPs);
seniorAdminNames = TFM_Util.removeDuplicates(seniorAdminNames);
}
public static void saveSuperadminList()
@ -135,11 +140,11 @@ public class TFM_SuperadminList
String admin_name = pair.getKey().toLowerCase();
TFM_Superadmin superadmin = pair.getValue();
config.set("superadmins." + admin_name + ".ips", superadmin.getIps());
config.set("superadmins." + admin_name + ".ips", TFM_Util.removeDuplicates(superadmin.getIps()));
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 + ".is_senior_admin", superadmin.isSeniorAdmin());
config.set("superadmins." + admin_name + ".console_aliases", superadmin.getConsoleAliases());
config.set("superadmins." + admin_name + ".console_aliases", TFM_Util.removeDuplicates(superadmin.getConsoleAliases()));
config.set("superadmins." + admin_name + ".is_activated", superadmin.isActivated());
}

View File

@ -912,6 +912,15 @@ public class TFM_Util
{
return restricted_senders.contains(sender_name.toLowerCase());
}
public static List<String> removeDuplicates(List<String> list)
{
HashSet<String> hash = new HashSet<String>();
hash.addAll(list);
list.clear();
list.addAll(hash);
return list;
}
// I wrote all this before i discovered getTargetBlock >.> - might come in handy some day...
// public static final double LOOKAT_VIEW_HEIGHT = 1.65;
// public static final double LOOKAT_STEP_DISTANCE = 0.2;