mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-12-02 13:33:31 +01:00
Ditch weak map world references and use names instead (#533)
This commit is contained in:
parent
b1598a022a
commit
a4c37da8ee
@ -27,7 +27,6 @@ public class Config extends Language {
|
|||||||
private static final Map<String, String[]> HEADERS = new HashMap<>();
|
private static final Map<String, String[]> HEADERS = new HashMap<>();
|
||||||
private static final Map<String, String> DEFAULT_VALUES = new LinkedHashMap<>();
|
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 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";
|
private static final String DEFAULT_FILE_HEADER = "# CoreProtect Config";
|
||||||
public static final String LINE_SEPARATOR = "\n";
|
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
|
// returns a world specific config if it exists, otherwise the global config
|
||||||
public static Config getConfig(final World world) {
|
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) {
|
if (ret == null) {
|
||||||
ret = CONFIG_BY_WORLD_NAME.getOrDefault(world.getName(), GLOBAL);
|
ret = CONFIG_BY_WORLD_NAME.getOrDefault(worldName, GLOBAL);
|
||||||
CONFIG_BY_WORLD.put(world, ret);
|
CONFIG_BY_WORLD_NAME.put(worldName, ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -409,7 +412,6 @@ public class Config extends Language {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_BY_WORLD_NAME.clear();
|
CONFIG_BY_WORLD_NAME.clear();
|
||||||
CONFIG_BY_WORLD.clear();
|
|
||||||
|
|
||||||
// we need to load global first since it is used for config defaults
|
// we need to load global first since it is used for config defaults
|
||||||
final byte[] defaultData = data.get("config");
|
final byte[] defaultData = data.get("config");
|
||||||
|
Loading…
Reference in New Issue
Block a user