mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 12:02:36 +01:00
Fixed deeply nested configuration sections retrieving values
By: Nathan Adams <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
510ec3a467
commit
e7f66d5be6
1 changed files with 14 additions and 9 deletions
|
@ -205,29 +205,34 @@ public class MemorySection implements ConfigurationSection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(String path, Object def) {
|
public Object get(String path, Object def) {
|
||||||
Object result = null;
|
|
||||||
String[] split = path.split(Pattern.quote(Character.toString(getRoot().options().pathSeparator())));
|
|
||||||
ConfigurationSection section = this;
|
|
||||||
|
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
throw new IllegalArgumentException("Path cannot be null");
|
throw new IllegalArgumentException("Path cannot be null");
|
||||||
} else if (path.length() == 0) {
|
} else if (path.length() == 0) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; (i < split.length - 1) && (section != null); i++) {
|
Object result = null;
|
||||||
section = getConfigurationSection(split[i]);
|
String[] split = path.split(Pattern.quote(Character.toString(getRoot().options().pathSeparator())));
|
||||||
|
ConfigurationSection section = this;
|
||||||
|
|
||||||
|
for (int i = 0; i < split.length - 1; i++) {
|
||||||
|
section = section.getConfigurationSection(split[i]);
|
||||||
|
|
||||||
|
if (section == null) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = split[split.length - 1];
|
String key = split[split.length - 1];
|
||||||
|
|
||||||
if (section == this) {
|
if (section == this) {
|
||||||
result = map.get(key);
|
result = map.get(key);
|
||||||
} else if (section != null) {
|
|
||||||
result = section.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (result == null) ? def : result;
|
return (result == null) ? def : result;
|
||||||
|
} else if (section != null) {
|
||||||
|
return section.get(key, def);
|
||||||
|
} else {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationSection createSection(String path) {
|
public ConfigurationSection createSection(String path) {
|
||||||
|
|
Loading…
Reference in a new issue