Ditch weak map world references and use names instead (#533)

This commit is contained in:
Nahuel Dolores 2024-04-25 17:05:48 -03:00 committed by GitHub
parent b1598a022a
commit a4c37da8ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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";
@ -262,10 +261,14 @@ public class Config extends Language {
// 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 @@ public class Config extends Language {
}
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");