Skip to content

Commit

Permalink
Ditch weak map world references and use names instead
Browse files Browse the repository at this point in the history
  • Loading branch information
NahuLD committed Apr 25, 2024
1 parent b1598a0 commit f906f62
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/net/coreprotect/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class Config extends Language {
private static final Map<String, String[]> HEADERS = new HashMap<>();
private static final Map<String, String> DEFAULT_VALUES = new LinkedHashMap<>();
private static final Map<String, Config> CONFIG_BY_WORLD_NAME = new HashMap<>();
private static final WeakHashMap<World, Config> CONFIG_BY_WORLD = new WeakHashMap<>();
private static final String DEFAULT_FILE_HEADER = "# CoreProtect Config";
public static final String LINE_SEPARATOR = "\n";

Expand Down Expand Up @@ -262,10 +261,14 @@ public static Config getGlobal() {

// returns a world specific config if it exists, otherwise the global config
public static Config getConfig(final World world) {
Config ret = CONFIG_BY_WORLD.get(world);
return getConfig(world.getName());
}

public static Config getConfig(final String worldName) {
Config ret = CONFIG_BY_WORLD_NAME.get(worldName);
if (ret == null) {
ret = CONFIG_BY_WORLD_NAME.getOrDefault(world.getName(), GLOBAL);
CONFIG_BY_WORLD.put(world, ret);
ret = CONFIG_BY_WORLD_NAME.getOrDefault(worldName, GLOBAL);
CONFIG_BY_WORLD_NAME.put(worldName, ret);
}
return ret;
}
Expand Down Expand Up @@ -409,7 +412,6 @@ private static void parseConfig(final Map<String, byte[]> data) {
}

CONFIG_BY_WORLD_NAME.clear();
CONFIG_BY_WORLD.clear();

// we need to load global first since it is used for config defaults
final byte[] defaultData = data.get("config");
Expand Down

0 comments on commit f906f62

Please sign in to comment.