diff options
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java index d09eb7c..56b3731 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java +++ b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java @@ -27,9 +27,11 @@ import com.google.gson.JsonObject; import java.io.IOException; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Deque; import java.util.LinkedList; import java.util.Map; +import java.util.stream.Collectors; /** * Abstract implementation of {@link ServerConfigProvider}. @@ -99,13 +101,28 @@ public abstract class AbstractServerConfigProvider<T extends Enum<T>> implements } JsonObject jsonObject = json.getAsJsonObject(); - String member = path.removeFirst().replace("<dot>", "."); + String expected = path.removeFirst().replace("<dot>", "."); - if (member.equals("*") || jsonObject.has(member)) { + Collection<String> keys; + if (expected.equals("*")) { + keys = jsonObject.entrySet().stream() + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + } else if (jsonObject.has(expected)) { + keys = Collections.singletonList(expected); + } else { + keys = Collections.emptyList(); + } + + for (String key : keys) { if (path.isEmpty()) { - jsonObject.remove(member); + jsonObject.remove(key); } else { - delete(jsonObject.get(member), path); + Deque<String> pathCopy = expected.equals("*") + ? new LinkedList<>(path) + : path; + + delete(jsonObject.get(key), pathCopy); } } } |