diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/MVValueNode.java b/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/MVValueNode.java index 7ac1ce8b..e7fcea3f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/MVValueNode.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/MVValueNode.java @@ -1,5 +1,7 @@ package com.onarandombox.MultiverseCore.utils.settings.node; +import java.util.Optional; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,7 +27,7 @@ public class MVValueNode extends MVCommentedNode implements NamedValueNode } /** - * {@InheritDoc} + * {@inheritDoc} */ @Override public @NotNull Class getType() { @@ -33,7 +35,7 @@ public class MVValueNode extends MVCommentedNode implements NamedValueNode } /** - * {@InheritDoc} + * {@inheritDoc} */ @Override public @Nullable T getDefaultValue() { @@ -41,11 +43,11 @@ public class MVValueNode extends MVCommentedNode implements NamedValueNode } /** - * {@InheritDoc} + * {@inheritDoc} */ @Override - public @Nullable String getName() { - return name; + public Optional getName() { + return Optional.ofNullable(name); } public static class Builder> extends MVCommentedNode.Builder { @@ -54,18 +56,18 @@ public class MVValueNode extends MVCommentedNode implements NamedValueNode protected T defaultValue; private String name; - public Builder(String path, Class type) { + public Builder(@NotNull String path, @NotNull Class type) { super(path); this.type = type; this.name = path; } - public B defaultValue(T defaultValue) { + public B defaultValue(@NotNull T defaultValue) { this.defaultValue = defaultValue; return (B) this; } - public B name(String name) { + public B name(@Nullable String name) { this.name = name; return (B) this; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/NamedValueNode.java b/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/NamedValueNode.java index f6c7abe1..080186bc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/NamedValueNode.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/NamedValueNode.java @@ -1,5 +1,7 @@ package com.onarandombox.MultiverseCore.utils.settings.node; +import java.util.Optional; + import io.github.townyadvanced.commentedconfiguration.setting.TypedValueNode; import org.jetbrains.annotations.Nullable; @@ -9,5 +11,5 @@ public interface NamedValueNode extends TypedValueNode { * * @return The name of this node. */ - @Nullable String getName(); + Optional getName(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/NodeGroup.java b/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/NodeGroup.java index 0cc1373f..1f33cfe0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/NodeGroup.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/settings/node/NodeGroup.java @@ -29,14 +29,14 @@ public class NodeGroup implements Collection { } private void addNodeIndex(CommentedNode node) { - if (node instanceof NamedValueNode namedValueNode && namedValueNode.getName() != null) { - nodesMap.put(namedValueNode.getName(), node); + if (node instanceof NamedValueNode) { + ((NamedValueNode) node).getName().ifPresent(name -> nodesMap.put(name, node)); } } private void removeNodeIndex(CommentedNode node) { - if (node instanceof NamedValueNode namedValueNode) { - nodesMap.remove(namedValueNode.getName()); + if (node instanceof NamedValueNode) { + ((NamedValueNode) node).getName().ifPresent(nodesMap::remove); } } @@ -86,7 +86,7 @@ public class NodeGroup implements Collection { } @Override - public T @NotNull [] toArray(@NotNull T[] ts) { + public T @NotNull [] toArray(T @NotNull [] ts) { return nodes.toArray(ts); }