Refactor ServerUtilsConfig#set to delete existing objects at path

This commit is contained in:
Frank van der Heijden 2021-08-04 16:25:30 +02:00
parent 90b248f321
commit d2928b4a04
No known key found for this signature in database
GPG key ID: B808721C2DD5B5B8
5 changed files with 67 additions and 21 deletions

View file

@ -56,21 +56,13 @@ public class VelocityTomlConfig implements ServerUtilsConfig {
}
@Override
public void set(String path, Object value) {
if (value == null) {
config.remove(path);
} else {
int lastDotIndex = path.lastIndexOf('.');
if (lastDotIndex != -1) {
String parentPath = path.substring(0, lastDotIndex);
try {
CommentedConfig parent = config.get(parentPath);
} catch (ClassCastException ex) {
config.remove(parentPath);
}
}
config.set(path, value);
}
public void setUnsafe(String path, Object value) {
config.set(path, value);
}
@Override
public void remove(String path) {
config.remove(path);
}
@Override