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