From 018b9dcf15d8d9fd06b85007b1f3bfb4d0e99328 Mon Sep 17 00:00:00 2001 From: Pasqual Koschmieder Date: Fri, 19 Aug 2022 11:10:02 +0200 Subject: [PATCH] fix: fixup invalid command sender message (#799) Motivation The invalid command sender message is currently not showing the required sender as the argument was escaped by the surrounding '. Modification Fixup the escape of the message arguments, as well as fixing the message to correctly reflect what it is meant to show. This requires to override the toString method in all registered command senders to get a human readable name of the sender during formatting. Result The invalid command sender message shows up correctly. --- .../command/source/ConsoleCommandSource.java | 10 +++++++++- .../node/command/source/DriverCommandSource.java | 16 +++++++++++++++- .../command/PermissionUserCommandSource.java | 8 ++++++++ node/src/main/resources/lang/en_US.properties | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/node/src/main/java/eu/cloudnetservice/node/command/source/ConsoleCommandSource.java b/node/src/main/java/eu/cloudnetservice/node/command/source/ConsoleCommandSource.java index 6120d27841..b1657cec70 100644 --- a/node/src/main/java/eu/cloudnetservice/node/command/source/ConsoleCommandSource.java +++ b/node/src/main/java/eu/cloudnetservice/node/command/source/ConsoleCommandSource.java @@ -30,7 +30,7 @@ public class ConsoleCommandSource implements CommandSource { private static final Logger LOGGER = LogManager.logger(ConsoleCommandSource.class); /** - * @return "Console" for the console command source. + * {@inheritDoc} */ @Override public @NonNull String name() { @@ -74,4 +74,12 @@ public void sendMessage(@NonNull Collection messages) { public boolean checkPermission(@NonNull String permission) { return true; } + + /** + * {@inheritDoc} + */ + @Override + public @NonNull String toString() { + return this.name(); + } } diff --git a/node/src/main/java/eu/cloudnetservice/node/command/source/DriverCommandSource.java b/node/src/main/java/eu/cloudnetservice/node/command/source/DriverCommandSource.java index a8f420a960..72d373fd96 100644 --- a/node/src/main/java/eu/cloudnetservice/node/command/source/DriverCommandSource.java +++ b/node/src/main/java/eu/cloudnetservice/node/command/source/DriverCommandSource.java @@ -38,7 +38,7 @@ public class DriverCommandSource implements CommandSource { private final Collection messages = new ArrayList<>(); /** - * @return "Driver" for the driver command source. + * {@inheritDoc} */ @Override public @NonNull String name() { @@ -86,6 +86,17 @@ public boolean checkPermission(@NonNull String permission) { return this.messages; } + /** + * {@inheritDoc} + */ + @Override + public @NonNull String toString() { + return this.name(); + } + + /** + * {@inheritDoc} + */ @Override public boolean equals(Object o) { if (this == o) { @@ -97,6 +108,9 @@ public boolean equals(Object o) { return that.name().equals(this.name()); } + /** + * {@inheritDoc} + */ @Override public int hashCode() { return Objects.hash(this.name()); diff --git a/node/src/main/java/eu/cloudnetservice/node/permission/command/PermissionUserCommandSource.java b/node/src/main/java/eu/cloudnetservice/node/permission/command/PermissionUserCommandSource.java index 4b5237f6ac..a9a4a7106d 100644 --- a/node/src/main/java/eu/cloudnetservice/node/permission/command/PermissionUserCommandSource.java +++ b/node/src/main/java/eu/cloudnetservice/node/permission/command/PermissionUserCommandSource.java @@ -60,4 +60,12 @@ public PermissionUserCommandSource( public boolean checkPermission(@NonNull String permission) { return this.permissionManagement.hasPermission(this.permissionUser, Permission.of(permission)); } + + /** + * {@inheritDoc} + */ + @Override + public @NonNull String toString() { + return this.name(); + } } diff --git a/node/src/main/resources/lang/en_US.properties b/node/src/main/resources/lang/en_US.properties index 6d77ca3283..04e9f2b393 100644 --- a/node/src/main/resources/lang/en_US.properties +++ b/node/src/main/resources/lang/en_US.properties @@ -119,7 +119,7 @@ cloudnet-post-unload-module=Module {0$module_group$}:{1$module_name$}:{2$module_ command-no-description=No command description provided command-confirmation-no-requests=There are no commands to confirm command-confirmation-required=Please confirm executing the command by executing ''&bconfirm&r'' within 30s -invalid-command-sender=This command can be executed using the '{0$source$}' only +invalid-command-sender=This command cannot be executed by ''{0$source$}'' invalid-command-syntax=Invalid syntax! Use {0$syntax$} no-such-command=Command could not be found! For help, use the command "help" argument-parse-failure-no-input-was-provided=No input provided