diff --git a/client/src/main/java/envoy/client/data/commands/SystemCommandMap.java b/client/src/main/java/envoy/client/data/commands/SystemCommandMap.java index 19b7da0..831de0d 100644 --- a/client/src/main/java/envoy/client/data/commands/SystemCommandMap.java +++ b/client/src/main/java/envoy/client/data/commands/SystemCommandMap.java @@ -1,11 +1,16 @@ package envoy.client.data.commands; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.logging.*; import java.util.regex.Pattern; import java.util.stream.Collectors; +import javafx.application.Platform; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; + import envoy.util.EnvoyLog; /** @@ -27,26 +32,9 @@ public final class SystemCommandMap { private static final Logger logger = EnvoyLog.getLogger(SystemCommandMap.class); /** - * The default char to be used as activator. - *

- * Value: '/'. - * - * @since Envoy Client v0.3-beta - */ - public static final char defaultActivator = '/'; - - /** - * The Character to use if every String should be considered as a possible - * {@link SystemCommand}. - *

- * Value: null. - * - * @since Envoy Client v0.3-beta - */ - public static final Character noActivator = null; - - /** - * Creates a new {@link SystemCommandMap} with the given activator. + * Creates a new {@code SystemCommandMap} with the given char as activator. + * If this Character is null, any text used as input will be treated as a system + * command. * * @param activator the char to use as activator for commands * @since Envoy Client v0.3-beta @@ -54,11 +42,11 @@ public final class SystemCommandMap { public SystemCommandMap(Character activator) { this.activator = activator; } /** - * Creates a new {@link SystemCommandMap} with default activator. + * Creates a new {@code SystemCommandMap} with '/' as activator. * * @since Envoy Client v0.3-beta */ - public SystemCommandMap() { activator = defaultActivator; } + public SystemCommandMap() { activator = '/'; } /** * Adds a new command to the map if the command name is valid. @@ -101,7 +89,7 @@ public final class SystemCommandMap { * input. * It returns the command as (most likely) entered as key in the map for the * first word of the text.
- * Activators in the middle of the wod will be disregarded. + * Activators in the middle of the word will be disregarded. * * @param raw the input * @return the command as entered in the map @@ -149,7 +137,7 @@ public final class SystemCommandMap { * activator. If that is the case, it will be executed. * * @param raw the raw input string - * @return whether a command could be found + * @return whether a command could be found and successfully executed * @since Envoy Client v0.2-beta */ public boolean executeIfPresent(String raw) { @@ -204,12 +192,13 @@ public final class SystemCommandMap { * result: {@code button.getText()=="xyz"} * * @param input the input string given by the user - * @return whether a command could be found + * @return whether a command could be found and successfully executed * @since Envoy Client v0.2-beta */ private boolean executeAvailableCommand(String input) { - final var command = getCommand(input); - final var value = get(command); + final var command = getCommand(input); + final var value = get(command); + final var commandExecuted = new AtomicBoolean(value.isPresent()); value.ifPresent(systemCommand -> { // Splitting the String so that the leading command including the first " " is @@ -225,11 +214,23 @@ public final class SystemCommandMap { String.format( "System command %s could not be performed correctly because the user is a dumbass and could not write a parseable number.", command)); + Platform.runLater(() -> { + final var alert = new Alert(AlertType.ERROR); + alert.setContentText("Please enter a readable number as argument."); + alert.showAndWait(); + }); + commandExecuted.set(false); } catch (final Exception e) { logger.log(Level.WARNING, "System command " + command + " threw an exception: ", e); + Platform.runLater(() -> { + final var alert = new Alert(AlertType.ERROR); + alert.setContentText("Could not execute system command: Internal error. Please insult the responsible programmer."); + alert.showAndWait(); + }); + commandExecuted.set(false); } }); - return value.isPresent(); + return commandExecuted.get(); } /** diff --git a/client/src/main/java/envoy/client/ui/chatscene/ChatSceneCommands.java b/client/src/main/java/envoy/client/ui/chatscene/ChatSceneCommands.java index 850d8bb..e2fd619 100644 --- a/client/src/main/java/envoy/client/ui/chatscene/ChatSceneCommands.java +++ b/client/src/main/java/envoy/client/ui/chatscene/ChatSceneCommands.java @@ -40,6 +40,9 @@ public final class ChatSceneCommands { public ChatSceneCommands(ListView messageList, ChatScene chatScene) { this.messageList = messageList; + // Error message initialization + builder.setAction(text -> { throw new RuntimeException(); }).setDescription("Shows an error message.").buildNoArg("error"); + // Do A Barrel roll initialization final var random = new Random(); builder.setAction(text -> chatScene.doABarrelRoll(Integer.parseInt(text.get(0)), Double.parseDouble(text.get(1))))