Prefer this formatting, rather.

This commit is contained in:
asofold 2013-06-10 19:27:13 +02:00
parent 7805d8d486
commit b84235d31f

View File

@ -75,13 +75,17 @@ public class ConfigManager {
* @param factory * @param factory
*/ */
public static void setActionFactoryFactory(ActionFactoryFactory factory){ public static void setActionFactoryFactory(ActionFactoryFactory factory){
if (factory != null) actionFactoryFactory = factory; if (factory != null){
else actionFactoryFactory = new ActionFactoryFactory() { actionFactoryFactory = factory;
@Override }
public final ActionFactory newActionFactory(final Map<String, Object> library) { else{
return new ActionFactory(library); actionFactoryFactory = new ActionFactoryFactory() {
} @Override
}; public final ActionFactory newActionFactory(final Map<String, Object> library) {
return new ActionFactory(library);
}
};
}
for (final ConfigFile config : worldsMap.values()){ for (final ConfigFile config : worldsMap.values()){
config.regenerateActionLists(); config.regenerateActionLists();
} }
@ -133,11 +137,15 @@ public class ConfigManager {
*/ */
public static ConfigFile getConfigFile(final String worldName) { public static ConfigFile getConfigFile(final String worldName) {
final ConfigFile configFile = worldsMap.get(worldName); final ConfigFile configFile = worldsMap.get(worldName);
if (configFile != null) return configFile; if (configFile != null){
return configFile;
}
// Expensive only once, for the rest of runtime the file is returned fast. // Expensive only once, for the rest of runtime the file is returned fast.
synchronized(ConfigManager.class){ synchronized(ConfigManager.class){
// Need to check again. // Need to check again.
if (worldsMap.containsKey(worldName)) return worldsMap.get(worldName); if (worldsMap.containsKey(worldName)){
return worldsMap.get(worldName);
}
final ConfigFile globalConfig = getConfigFile(); final ConfigFile globalConfig = getConfigFile();
worldsMap.put(worldName, globalConfig); worldsMap.put(worldName, globalConfig);
return globalConfig; return globalConfig;
@ -168,12 +176,14 @@ public class ConfigManager {
final ConfigFile globalConfig = new ConfigFile(); final ConfigFile globalConfig = new ConfigFile();
globalConfig.setDefaults(new DefaultConfig()); globalConfig.setDefaults(new DefaultConfig());
globalConfig.options().copyDefaults(true); globalConfig.options().copyDefaults(true);
if (globalFile.exists()) if (globalFile.exists()){
try { try {
globalConfig.load(globalFile); globalConfig.load(globalFile);
// Quick shallow ugly fix: only save back if loading was successful. // Quick shallow ugly fix: only save back if loading was successful.
try { try {
if (globalConfig.getBoolean(ConfPaths.SAVEBACKCONFIG)) globalConfig.save(globalFile); if (globalConfig.getBoolean(ConfPaths.SAVEBACKCONFIG)){
globalConfig.save(globalFile);
}
} catch (final Exception e) { } catch (final Exception e) {
LogUtil.logSevere("[NoCheatPlus] Could not save back config.yml (see exception below)."); LogUtil.logSevere("[NoCheatPlus] Could not save back config.yml (see exception below).");
LogUtil.logSevere(e); LogUtil.logSevere(e);
@ -182,9 +192,9 @@ public class ConfigManager {
LogUtil.logSevere("[NoCheatPlus] Could not load config.yml (see exception below). Continue with default settings..."); LogUtil.logSevere("[NoCheatPlus] Could not load config.yml (see exception below). Continue with default settings...");
LogUtil.logSevere(e); LogUtil.logSevere(e);
} }
}
else { else {
globalConfig.options().header( globalConfig.options().header("Configuration generated by NoCheatPlus " + plugin.getDescription().getVersion() + ".");
"Configuration generated by NoCheatPlus " + plugin.getDescription().getVersion() + ".");
globalConfig.options().copyHeader(true); globalConfig.options().copyHeader(true);
try { try {
globalConfig.save(globalFile); globalConfig.save(globalFile);
@ -200,15 +210,17 @@ public class ConfigManager {
// Try to obtain and parse the world-specific configuration files. // Try to obtain and parse the world-specific configuration files.
final HashMap<String, File> worldFiles = new HashMap<String, File>(); final HashMap<String, File> worldFiles = new HashMap<String, File>();
if (plugin.getDataFolder().isDirectory()) if (plugin.getDataFolder().isDirectory()){
for (final File file : plugin.getDataFolder().listFiles()) for (final File file : plugin.getDataFolder().listFiles()){
if (file.isFile()) { if (file.isFile()) {
final String fileName = file.getName(); final String fileName = file.getName();
if (fileName.matches(".+_config.yml$")) { if (fileName.matches(".+_config.yml$")) {
final String worldname = fileName.substring(0, fileName.length() - 11); final String worldname = fileName.substring(0, fileName.length() - 11);
worldFiles.put(worldname, file); worldFiles.put(worldname, file);
} }
} }
}
}
for (final Entry<String, File> worldEntry : worldFiles.entrySet()) { for (final Entry<String, File> worldEntry : worldFiles.entrySet()) {
final File worldFile = worldEntry.getValue(); final File worldFile = worldEntry.getValue();
PathUtils.warnPaths(worldFile, worldEntry.getKey(), true); PathUtils.warnPaths(worldFile, worldEntry.getKey(), true);
@ -221,13 +233,11 @@ public class ConfigManager {
try{ try{
if (worldConfig.getBoolean(ConfPaths.SAVEBACKCONFIG)) worldConfig.save(worldFile); if (worldConfig.getBoolean(ConfPaths.SAVEBACKCONFIG)) worldConfig.save(worldFile);
} catch (final Exception e){ } catch (final Exception e){
LogUtil.logSevere("[NoCheatPlus] Couldn't save back world-specific configuration for " LogUtil.logSevere("[NoCheatPlus] Couldn't save back world-specific configuration for " + worldEntry.getKey() + " (see exception below).");
+ worldEntry.getKey() + " (see exception below).");
LogUtil.logSevere(e); LogUtil.logSevere(e);
} }
} catch (final Exception e) { } catch (final Exception e) {
LogUtil.logSevere("[NoCheatPlus] Couldn't load world-specific configuration for " LogUtil.logSevere("[NoCheatPlus] Couldn't load world-specific configuration for " + worldEntry.getKey() + " (see exception below). Continue with global default settings...");
+ worldEntry.getKey() + " (see exception below). Continue with global default settings...");
LogUtil.logSevere(e); LogUtil.logSevere(e);
} }
worldConfig.setDefaults(globalConfig); worldConfig.setDefaults(globalConfig);
@ -261,7 +271,9 @@ public class ConfigManager {
final Object obj = config.get(path); final Object obj = config.get(path);
if (obj instanceof Number){ if (obj instanceof Number){
final Number num = (Number) obj; final Number num = (Number) obj;
if (max == null || num.doubleValue() > max.doubleValue()) max = num; if (max == null || num.doubleValue() > max.doubleValue()){
max = num;
}
} }
} }
catch (Throwable t){ catch (Throwable t){
@ -285,7 +297,9 @@ public class ConfigManager {
final Object obj = config.get(path); final Object obj = config.get(path);
if (obj instanceof Number){ if (obj instanceof Number){
final Number num = (Number) obj; final Number num = (Number) obj;
if (min == null || num.doubleValue() < min.doubleValue()) min = num; if (min == null || num.doubleValue() < min.doubleValue()){
min = num;
}
} }
} }
catch (Throwable t){ catch (Throwable t){