diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java index ee810d70..1f490ba8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java @@ -23,6 +23,7 @@ import com.onarandombox.MultiverseCore.display.filters.ContentFilter; import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter; import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter; import com.onarandombox.MultiverseCore.utils.PlayerFinder; +import io.vavr.control.Option; import jakarta.inject.Inject; import org.bukkit.GameRule; import org.bukkit.entity.Player; @@ -123,7 +124,7 @@ public class MVCommandContexts extends PaperCommandContexts { if (Strings.isNullOrEmpty(configName)) { throw new InvalidCommandArgument("No config name specified."); } - Optional node = config.getNodes().findNode(configName); + Option node = config.getNodes().findNode(configName); if (node.isEmpty()) { throw new InvalidCommandArgument("The config " + configName + " is not valid."); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/FileConfigHandle.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/FileConfigHandle.java index 87eb7d40..a9dd8b1b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/FileConfigHandle.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/FileConfigHandle.java @@ -127,8 +127,8 @@ abstract class FileConfigHandle { */ public Try get(@Nullable String name) { return nodes.findNode(name, ValueNode.class) - .map(node -> Try.of(() -> get(node))) - .orElse(Try.failure(new Exception("Node not found"))); + .map(node -> get((ValueNode) node)) + .toTry(() -> new Exception("Node not found")); } /** @@ -150,8 +150,8 @@ abstract class FileConfigHandle { */ public Try set(@Nullable String name, Object value) { return nodes.findNode(name, ValueNode.class) - .map(node -> (Try) set(node, value)) - .orElse(Try.failure(new Exception("Node not found"))); + .toTry(() -> new Exception("Node not found")) + .flatMap(node -> set(node, value)); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/node/NodeGroup.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/node/NodeGroup.java index 80e8b56e..051a9770 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/node/NodeGroup.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/node/NodeGroup.java @@ -5,9 +5,9 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Optional; import io.github.townyadvanced.commentedconfiguration.setting.CommentedNode; +import io.vavr.control.Option; import org.jetbrains.annotations.NotNull; /** @@ -53,10 +53,10 @@ public class NodeGroup implements Collection { * Gets the node with the given name. * * @param name The name of the node to get. - * @return The node with the given name, or {@link Optional#empty()} if no node with the given name exists. + * @return The node with the given name, or {@link Option.None} if no node with the given name exists. */ - public Optional findNode(String name) { - return Optional.ofNullable(nodesMap.get(name)); + public Option findNode(String name) { + return Option.of(nodesMap.get(name)); } /** @@ -64,11 +64,10 @@ public class NodeGroup implements Collection { * * @param name The name of the node to get. * @param type The type of the node to get. - * @return The node with the given name, or {@link Optional#empty()} if no node with the given name exists. + * @return The node with the given name, or {@link Option.None} if no node with the given name exists. */ - public Optional findNode(String name, Class type) { - return Optional.ofNullable(nodesMap.get(name)) - .map(node -> type.isAssignableFrom(node.getClass()) ? (T) node : null); + public Option findNode(String name, Class type) { + return Option.of(nodesMap.get(name)).map(node -> type.isAssignableFrom(node.getClass()) ? (T) node : null); } @Override