Skip to content

Commit

Permalink
Merge pull request #437 from nicolube/bugfix/clickable_help_cmds
Browse files Browse the repository at this point in the history
Fix help subcommand clickable messages
  • Loading branch information
Mindgamesnl authored Jun 13, 2024
2 parents 60f5036 + 8d34386 commit c7ef179
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public SubCommand(String argument, String... aliases) {
* @param sender Command sender
* @param message Your message
*/
protected void message(User sender, String message) {
protected void message(User<?> sender, String message) {
sender.sendMessage(MagicValue.COMMAND_PREFIX.get(String.class) + Platform.translateColors(message));
}

Expand All @@ -69,7 +69,7 @@ protected void message(User sender, String message) {
* @param commandSender Command sender
* @return true if the player is allowed to execute a command
*/
public boolean isAllowed(User commandSender) {
public boolean isAllowed(User<?> commandSender) {
if (ignorePermissions) return true;

return commandSender.hasPermission(permissionScope + command)
Expand All @@ -89,7 +89,7 @@ protected void registerSubCommands(SubCommand... commands) {
* @param user User
* @param args Arguments
*/
protected void delegateTo(String subCommand, User user, String[] args) {
protected void delegateTo(String subCommand, User<?> user, String[] args) {
SubCommand sci = moreSubCommands.get(subCommand);
if (sci.trimArguments) {
String[] subArgs = new String[args.length - 1];
Expand Down Expand Up @@ -118,7 +118,7 @@ protected void registerArguments(Argument... args) {
* @param sender the sender that executed the commands
* @param args the arguments after your command, starting at index 0
*/
public abstract void onExecute(User sender, String[] args);
public abstract void onExecute(User<?> sender, String[] args);

protected boolean isInteger(String s) {
return isInteger(s,10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HelpSubCommand(CommandContext context, boolean useHelpTrail) {
}

@Override
public void onExecute(User sender, String[] args) {
public void onExecute(User<?> sender, String[] args) {
if (args.length == 1) {
args[0] = args[0].toLowerCase();
SubCommand subCommand = commandService.getSubCommand(context, args[0]);
Expand All @@ -50,7 +50,7 @@ public void onExecute(User sender, String[] args) {

// only render aliases
if (command.equals(handler.getCommand()) && handler.isListed()) {
String optionalDelegates = "";
StringBuilder optionalDelegates = new StringBuilder();
boolean hasDelegates = false;
if (!handler.getArguments().isEmpty()) {
Set<String> arguments = new HashSet<>();
Expand All @@ -60,38 +60,38 @@ public void onExecute(User sender, String[] args) {
if (!base.isEmpty()) arguments.add(argument.getBase());
}

optionalDelegates += OaColor.GRAY + "[";
optionalDelegates.append(OaColor.GRAY + "[");
int argCount = arguments.size();
int index = 0;
for (String argument : arguments) {
optionalDelegates += OaColor.DARK_GRAY + argument;
optionalDelegates.append(OaColor.DARK_GRAY).append(argument);
if (index != argCount - 1) {
optionalDelegates += OaColor.GRAY + "|";
optionalDelegates.append(OaColor.GRAY + "|");
}
index++;
}
optionalDelegates += OaColor.GRAY + "]";
optionalDelegates.append(OaColor.GRAY + "]");
hasDelegates = index > 0;
}

goldClickableMessage(sender, "/" + context.getBaseCommand() + " " + handler.getCommand() + " " + (hasDelegates ? optionalDelegates : ""), "oa help " + handler.getCommand());
goldClickableMessage(sender, "/" + context.getBaseCommand() + " " + handler.getCommand() + " " + (hasDelegates ? optionalDelegates.toString() : ""), context.getBaseCommand() + " help " + handler.getCommand());
}
}

if (this.useHelpTrail)
message(sender, "For more personal help or other questions, please visit https://openaudiomc.net/docs");
}

private void goldMessage(User s, String message) {
private void goldMessage(User<?> s, String message) {
s.sendMessage(" " + getColor("YELLOW") + "> " + getColor("GOLD") + message);
}

@SneakyThrows
private void goldClickableMessage(User s, String message, String command) {
private void goldClickableMessage(User<?> s, String message, String command) {
s.sendClickableCommandMessage(OaColor.GOLD + " > " + message, "Click here to run " + command, command);
}

private void grayMessage(User s, String message) {
s.sendMessage(" " + getColor("DARK_GRAY") + "> " + getColor("ITALIC") + "" + getColor("GRAY") + message);
private void grayMessage(User<?> s, String message) {
s.sendMessage(" " + getColor("DARK_GRAY") + "> " + getColor("ITALIC")+ getColor("GRAY") + message);
}
}

0 comments on commit c7ef179

Please sign in to comment.