Skip to content

Commit

Permalink
Ensure copy-on-write is used for worldsMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Jul 26, 2014
1 parent 564ce88 commit 126c400
Showing 1 changed file with 9 additions and 6 deletions.
Expand Up @@ -183,7 +183,7 @@ public static synchronized ConfigFile getConfigFileSync(final String worldName)
*/
public static synchronized void init(final Plugin plugin) {
// (This can lead to minor problems with async checks during reloading.)
worldsMap.clear();
LinkedHashMap<String, ConfigFile> newWorldsMap = new LinkedHashMap<String, ConfigFile>();
// Try to obtain and parse the global configuration file.
final File globalFile = new File(plugin.getDataFolder(), "config.yml");
PathUtils.processPaths(globalFile, "global config", false);
Expand Down Expand Up @@ -224,7 +224,7 @@ public static synchronized void init(final Plugin plugin) {
}
}
// globalConfig.setActionFactory();
worldsMap.put(null, globalConfig);
newWorldsMap.put(null, globalConfig);


final MemoryConfiguration worldDefaults = PathUtils.getWorldsDefaultConfig(globalConfig);
Expand All @@ -250,7 +250,7 @@ public static synchronized void init(final Plugin plugin) {
worldConfig.options().copyDefaults(true);
try {
worldConfig.load(worldFile);
worldsMap.put(worldEntry.getKey(), worldConfig);
newWorldsMap.put(worldEntry.getKey(), worldConfig);
try{
if (worldConfig.getBoolean(ConfPaths.SAVEBACKCONFIG)) worldConfig.save(worldFile);
} catch (final Exception e){
Expand All @@ -265,17 +265,20 @@ public static synchronized void init(final Plugin plugin) {
worldConfig.options().copyDefaults(true);
// worldConfig.setActionFactory();
}
ConfigManager.worldsMap = newWorldsMap;
}

/**
* Set a property in all configs. Might use with DataManager.clearConfigs if configs might already be in use.
* Set a property for all configurations. Might use with DataManager.clearConfigs if check-configurations might already be in use.
* @param path
* @param value
*/
public static void setForAllConfigs(String path, Object value){
for (final ConfigFile cfg : worldsMap.values()){
public static synchronized void setForAllConfigs(String path, Object value){
final Map<String, ConfigFile> newWorldsMap = new LinkedHashMap<String, ConfigFile>(ConfigManager.worldsMap);
for (final ConfigFile cfg : newWorldsMap.values()){
cfg.set(path, value);
}
ConfigManager.worldsMap = newWorldsMap;
}

/**
Expand Down

0 comments on commit 126c400

Please sign in to comment.