Skip to content

Commit

Permalink
fix: fixup invalid command sender message (#799)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
derklaro committed Aug 19, 2022
1 parent 63727a5 commit 069695d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -74,4 +74,12 @@ public void sendMessage(@NonNull Collection<String> messages) {
public boolean checkPermission(@NonNull String permission) {
return true;
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull String toString() {
return this.name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DriverCommandSource implements CommandSource {
private final Collection<String> messages = new ArrayList<>();

/**
* @return "Driver" for the driver command source.
* {@inheritDoc}
*/
@Override
public @NonNull String name() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion node/src/main/resources/lang/en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 069695d

Please sign in to comment.