Added some startup crash prevention.

This commit is contained in:
Steven Lawson 2012-09-20 16:35:00 -04:00
parent 5785cc2164
commit 054ce678f4
2 changed files with 98 additions and 70 deletions

View File

@ -28,22 +28,30 @@ public class TFM_UserList
private void primeList() private void primeList()
{ {
_userlist.clear(); try
FileConfiguration saved_userlist = YamlConfiguration.loadConfiguration(new File(_plugin.getDataFolder(), USERLIST_FILENAME));
for (String username : saved_userlist.getKeys(false))
{ {
TFM_UserListEntry entry = new TFM_UserListEntry(username, saved_userlist.getStringList(username)); _userlist.clear();
_userlist.put(username, entry);
}
for (Player p : _plugin.getServer().getOnlinePlayers()) FileConfiguration saved_userlist = YamlConfiguration.loadConfiguration(new File(_plugin.getDataFolder(), USERLIST_FILENAME));
for (String username : saved_userlist.getKeys(false))
{
TFM_UserListEntry entry = new TFM_UserListEntry(username, saved_userlist.getStringList(username));
_userlist.put(username, entry);
}
for (Player p : _plugin.getServer().getOnlinePlayers())
{
addUser(p);
}
exportList();
}
catch (Exception ex)
{ {
addUser(p); TFM_Log.severe("Error loading Userlist, resetting list: " + ex.getMessage());
purge();
} }
exportList();
} }
private void exportList() private void exportList()

View File

@ -188,38 +188,45 @@ public class TotalFreedomMod extends JavaPlugin
public void loadMainConfig() public void loadMainConfig()
{ {
TFM_Util.createDefaultConfiguration(CONFIG_FILE, getFile()); try
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), CONFIG_FILE)); {
TFM_Util.createDefaultConfiguration(CONFIG_FILE, getFile());
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), CONFIG_FILE));
allowFirePlace = config.getBoolean("allow_fire_place", allowFirePlace); allowFirePlace = config.getBoolean("allow_fire_place", allowFirePlace);
allowFireSpread = config.getBoolean("allow_fire_spread", allowFireSpread); allowFireSpread = config.getBoolean("allow_fire_spread", allowFireSpread);
allowLavaDamage = config.getBoolean("allow_lava_damage", allowLavaDamage); allowLavaDamage = config.getBoolean("allow_lava_damage", allowLavaDamage);
allowLavaPlace = config.getBoolean("allow_lava_place", allowLavaPlace); allowLavaPlace = config.getBoolean("allow_lava_place", allowLavaPlace);
allowWaterPlace = config.getBoolean("allow_water_place", allowWaterPlace); allowWaterPlace = config.getBoolean("allow_water_place", allowWaterPlace);
allowExplosions = config.getBoolean("allow_explosions", allowExplosions); allowExplosions = config.getBoolean("allow_explosions", allowExplosions);
explosiveRadius = config.getDouble("explosiveRadius", explosiveRadius); explosiveRadius = config.getDouble("explosiveRadius", explosiveRadius);
autoEntityWipe = config.getBoolean("auto_wipe", autoEntityWipe); autoEntityWipe = config.getBoolean("auto_wipe", autoEntityWipe);
nukeMonitor = config.getBoolean("nuke_monitor", nukeMonitor); nukeMonitor = config.getBoolean("nuke_monitor", nukeMonitor);
nukeMonitorCountBreak = config.getInt("nuke_monitor_count_break", nukeMonitorCountBreak); nukeMonitorCountBreak = config.getInt("nuke_monitor_count_break", nukeMonitorCountBreak);
nukeMonitorCountPlace = config.getInt("nuke_monitor_count_place", nukeMonitorCountPlace); nukeMonitorCountPlace = config.getInt("nuke_monitor_count_place", nukeMonitorCountPlace);
nukeMonitorRange = config.getDouble("nuke_monitor_range", nukeMonitorRange); nukeMonitorRange = config.getDouble("nuke_monitor_range", nukeMonitorRange);
freecamTriggerCount = config.getInt("freecam_trigger_count", freecamTriggerCount); freecamTriggerCount = config.getInt("freecam_trigger_count", freecamTriggerCount);
preprocessLogEnabled = config.getBoolean("preprocess_log", preprocessLogEnabled); preprocessLogEnabled = config.getBoolean("preprocess_log", preprocessLogEnabled);
disableNight = config.getBoolean("disable_night", disableNight); disableNight = config.getBoolean("disable_night", disableNight);
disableWeather = config.getBoolean("disable_weather", disableWeather); disableWeather = config.getBoolean("disable_weather", disableWeather);
landminesEnabled = config.getBoolean("landmines_enabled", landminesEnabled); landminesEnabled = config.getBoolean("landmines_enabled", landminesEnabled);
mp44Enabled = config.getBoolean("mp44_enabled", mp44Enabled); mp44Enabled = config.getBoolean("mp44_enabled", mp44Enabled);
mobLimiterEnabled = config.getBoolean("mob_limiter_enabled", mobLimiterEnabled); mobLimiterEnabled = config.getBoolean("mob_limiter_enabled", mobLimiterEnabled);
mobLimiterMax = config.getInt("mob_limiter_max", mobLimiterMax); mobLimiterMax = config.getInt("mob_limiter_max", mobLimiterMax);
mobLimiterDisableDragon = config.getBoolean("mob_limiter_disable_dragon", mobLimiterDisableDragon); mobLimiterDisableDragon = config.getBoolean("mob_limiter_disable_dragon", mobLimiterDisableDragon);
mobLimiterDisableGhast = config.getBoolean("mob_limiter_disable_ghast", mobLimiterDisableGhast); mobLimiterDisableGhast = config.getBoolean("mob_limiter_disable_ghast", mobLimiterDisableGhast);
mobLimiterDisableSlime = config.getBoolean("mob_limiter_disable_slime", mobLimiterDisableSlime); mobLimiterDisableSlime = config.getBoolean("mob_limiter_disable_slime", mobLimiterDisableSlime);
mobLimiterDisableGiant = config.getBoolean("mob_limiter_disable_giant", mobLimiterDisableGiant); mobLimiterDisableGiant = config.getBoolean("mob_limiter_disable_giant", mobLimiterDisableGiant);
tossmobEnabled = config.getBoolean("tossmob_enabled", tossmobEnabled); tossmobEnabled = config.getBoolean("tossmob_enabled", tossmobEnabled);
generateFlatlands = config.getBoolean("generate_flatlands", generateFlatlands); generateFlatlands = config.getBoolean("generate_flatlands", generateFlatlands);
flatlandsGenerationParams = config.getString("flatlands_generation_params", flatlandsGenerationParams); flatlandsGenerationParams = config.getString("flatlands_generation_params", flatlandsGenerationParams);
allowFliudSpread = config.getBoolean("allow_fluid_spread", allowFliudSpread); allowFliudSpread = config.getBoolean("allow_fluid_spread", allowFliudSpread);
adminOnlyMode = config.getBoolean("admin_only_mode", adminOnlyMode); adminOnlyMode = config.getBoolean("admin_only_mode", adminOnlyMode);
}
catch (Exception ex)
{
TFM_Log.severe("Error loading main config: " + ex.getMessage());
}
} }
public static List<String> superadmins = new ArrayList<String>(); public static List<String> superadmins = new ArrayList<String>();
@ -227,53 +234,66 @@ public class TotalFreedomMod extends JavaPlugin
public void loadSuperadminConfig() public void loadSuperadminConfig()
{ {
TFM_Util.createDefaultConfiguration(SUPERADMIN_FILE, getFile()); try
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), SUPERADMIN_FILE));
superadmins = new ArrayList<String>();
superadmin_ips = new ArrayList<String>();
for (String user : config.getKeys(false))
{ {
superadmins.add(user.toLowerCase().trim()); TFM_Util.createDefaultConfiguration(SUPERADMIN_FILE, getFile());
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), SUPERADMIN_FILE));
List<String> user_ips = (List<String>) config.getStringList(user); superadmins = new ArrayList<String>();
for (String ip : user_ips) superadmin_ips = new ArrayList<String>();
for (String user : config.getKeys(false))
{ {
ip = ip.toLowerCase().trim(); superadmins.add(user.toLowerCase().trim());
if (!superadmin_ips.contains(ip))
List<String> user_ips = (List<String>) config.getStringList(user);
for (String ip : user_ips)
{ {
superadmin_ips.add(ip); ip = ip.toLowerCase().trim();
if (!superadmin_ips.contains(ip))
{
superadmin_ips.add(ip);
}
} }
} }
} }
catch (Exception ex)
{
TFM_Log.severe("Error loading superadmin list: " + ex.getMessage());
}
} }
public static List<String> permbanned_players = new ArrayList<String>(); public static List<String> permbanned_players = new ArrayList<String>();
public static List<String> permbanned_ips = new ArrayList<String>(); public static List<String> permbanned_ips = new ArrayList<String>();
public void loadPermbanConfig() public void loadPermbanConfig()
{ {
TFM_Util.createDefaultConfiguration(PERMBAN_FILE, getFile()); try
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), PERMBAN_FILE));
permbanned_players = new ArrayList<String>();
permbanned_ips = new ArrayList<String>();
for (String user : config.getKeys(false))
{ {
permbanned_players.add(user.toLowerCase().trim()); TFM_Util.createDefaultConfiguration(PERMBAN_FILE, getFile());
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), PERMBAN_FILE));
List<String> user_ips = (List<String>) config.getStringList(user); permbanned_players = new ArrayList<String>();
for (String ip : user_ips) permbanned_ips = new ArrayList<String>();
for (String user : config.getKeys(false))
{ {
ip = ip.toLowerCase().trim(); permbanned_players.add(user.toLowerCase().trim());
if (!permbanned_ips.contains(ip))
List<String> user_ips = (List<String>) config.getStringList(user);
for (String ip : user_ips)
{ {
permbanned_ips.add(ip); ip = ip.toLowerCase().trim();
if (!permbanned_ips.contains(ip))
{
permbanned_ips.add(ip);
}
} }
} }
} }
catch (Exception ex)
{
TFM_Log.severe("Error loading permban list: " + ex.getMessage());
}
} }
private void registerEventHandlers() private void registerEventHandlers()