Refactor ServerUtilsConfig#set to delete existing objects at path
This commit is contained in:
parent
90b248f321
commit
d2928b4a04
5 changed files with 67 additions and 21 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue