From bfedc268d4b62eb2e21cff6b683ca12f43b75dc1 Mon Sep 17 00:00:00 2001 From: benwoo1110 <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 30 Mar 2023 17:29:39 +0800 Subject: [PATCH] refactor: Improve setProperty onFailure output --- .../MultiverseCore/commands/ConfigCommand.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java index 60c14b5b..3c1ad912 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java @@ -14,6 +14,7 @@ import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand; import com.onarandombox.MultiverseCore.commandtools.context.MVConfigValue; import com.onarandombox.MultiverseCore.config.MVCoreConfig; import com.onarandombox.MultiverseCore.exceptions.MultiverseException; +import io.vavr.control.Option; import jakarta.inject.Inject; import org.jetbrains.annotations.NotNull; import org.jvnet.hk2.annotations.Service; @@ -66,14 +67,7 @@ public class ConfigCommand extends MultiverseCommand { config.save(); issuer.sendMessage("Successfully set " + name + " to " + value); }) - .onFailure(e -> { - issuer.sendMessage("Unable to set " + name + " to " + value + "."); - if (e instanceof MultiverseException) { - var message = ((MultiverseException) e).getMVMessage(); - if (message != null) { - issuer.sendError(message); - } - } - }); + .onFailure(ignore -> issuer.sendMessage("Unable to set " + name + " to " + value + ".")) + .onFailure(MultiverseException.class, e -> Option.of(e.getMVMessage()).peek(issuer::sendError)); } }