From 848177889e6507d4c014aff2abb7abf2c7818fdd Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 1 Aug 2020 21:40:20 +0200 Subject: [PATCH] Made system commands case insensitive and reworked /dabr mechanism --- .../data/commands/SystemCommandsMap.java | 6 ++++-- .../envoy/client/ui/controller/ChatScene.java | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/client/src/main/java/envoy/client/data/commands/SystemCommandsMap.java b/client/src/main/java/envoy/client/data/commands/SystemCommandsMap.java index cfcb0a4..ed75f24 100644 --- a/client/src/main/java/envoy/client/data/commands/SystemCommandsMap.java +++ b/client/src/main/java/envoy/client/data/commands/SystemCommandsMap.java @@ -37,7 +37,9 @@ public final class SystemCommandsMap { * @see SystemCommandsMap#isValidKey(String) * @since Envoy Client v0.2-beta */ - public void add(String command, SystemCommand systemCommand) { if (isValidKey(command)) systemCommands.put(command, systemCommand); } + public void add(String command, SystemCommand systemCommand) { + if (isValidKey(command)) systemCommands.put(command.toLowerCase(), systemCommand); + } /** * This method checks if the input String is a key in the map and returns the @@ -60,7 +62,7 @@ public final class SystemCommandsMap { * @return the wrapped system command, if present * @since Envoy Client v0.2-beta */ - public Optional get(String input) { return Optional.ofNullable(systemCommands.get(getCommand(input))); } + public Optional get(String input) { return Optional.ofNullable(systemCommands.get(getCommand(input.toLowerCase()))); } /** * This method ensures that the "/" of a {@link SystemCommand} is stripped.
diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 9af7c62..ba8346a 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -10,9 +10,11 @@ import java.io.IOException; import java.nio.file.Files; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Arrays; import java.util.Random; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Collectors; import javafx.animation.RotateTransition; import javafx.application.Platform; @@ -423,9 +425,21 @@ public final class ChatScene implements Restorable { * @since Envoy Client v0.1-beta */ private void doABarrelRoll(int rotations, double animationTime) { - // contains all Node objects in ChatScene in alphabetical order - final var rotatableNodes = new Node[] { attachmentButton, attachmentView, contactLabel, infoLabel, messageList, messageTextArea, postButton, - remainingChars, rotateButton, scene, settingsButton, chatList, voiceButton }; + // Limiting the rotations and duration + rotations = Math.min(rotations, 100000); + rotations = Math.max(rotations, 1); + animationTime = Math.min(animationTime, 150); + animationTime = Math.max(animationTime, 0.25); + + // contains all Node objects in ChatScene + final var rotatableNodes = Arrays.stream(ChatScene.class.getDeclaredFields()).map(field -> { + try { + return field.get(this); + } catch (IllegalArgumentException | IllegalAccessException e1) { + // In this case, this option can never be executed + return null; + } + }).filter(Node.class::isInstance).map(Node.class::cast).collect(Collectors.toList()); for (final var node : rotatableNodes) { // Sets the animation duration to {animationTime} final var rotateTransition = new RotateTransition(Duration.seconds(animationTime), node);