From f906f6271301d053c9db054aada44ad0bdac196d Mon Sep 17 00:00:00 2001 From: Nahuel Dolores Date: Thu, 25 Apr 2024 10:03:53 -0300 Subject: [PATCH] Ditch weak map world references and use names instead --- src/main/java/net/coreprotect/config/Config.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/coreprotect/config/Config.java b/src/main/java/net/coreprotect/config/Config.java index bae4f161..c90636a2 100644 --- a/src/main/java/net/coreprotect/config/Config.java +++ b/src/main/java/net/coreprotect/config/Config.java @@ -27,7 +27,6 @@ public class Config extends Language { private static final Map HEADERS = new HashMap<>(); private static final Map DEFAULT_VALUES = new LinkedHashMap<>(); private static final Map CONFIG_BY_WORLD_NAME = new HashMap<>(); - private static final WeakHashMap CONFIG_BY_WORLD = new WeakHashMap<>(); private static final String DEFAULT_FILE_HEADER = "# CoreProtect Config"; public static final String LINE_SEPARATOR = "\n"; @@ -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; } @@ -409,7 +412,6 @@ private static void parseConfig(final Map 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");