diff --git a/core/src/main/java/co/aikar/commands/BaseCommand.java b/core/src/main/java/co/aikar/commands/BaseCommand.java index 24d1a346..147319a8 100644 --- a/core/src/main/java/co/aikar/commands/BaseCommand.java +++ b/core/src/main/java/co/aikar/commands/BaseCommand.java @@ -793,7 +793,7 @@ public abstract class BaseCommand { public void showSyntax(CommandIssuer issuer, RegisteredCommand cmd) { issuer.sendMessage(MessageType.SYNTAX, MessageKeys.INVALID_SYNTAX, "{command}", manager.getCommandPrefix(issuer) + cmd.command, - "{syntax}", cmd.syntaxText + "{syntax}", cmd.getSyntaxText(issuer) ); } diff --git a/core/src/main/java/co/aikar/commands/CommandHelp.java b/core/src/main/java/co/aikar/commands/CommandHelp.java index fcc70970..55f1387d 100644 --- a/core/src/main/java/co/aikar/commands/CommandHelp.java +++ b/core/src/main/java/co/aikar/commands/CommandHelp.java @@ -107,7 +107,7 @@ public class CommandHelp { if (pattern.matcher(help.getDescription()).matches()) { searchScore += 2; } - if (pattern.matcher(help.getParameterSyntax()).matches()) { + if (pattern.matcher(help.getParameterSyntax(issuer)).matches()) { searchScore++; } if (help.getSearchTags() != null && pattern.matcher(help.getSearchTags()).matches()) { diff --git a/core/src/main/java/co/aikar/commands/CommandHelpFormatter.java b/core/src/main/java/co/aikar/commands/CommandHelpFormatter.java index 0670ba9f..759b6e71 100644 --- a/core/src/main/java/co/aikar/commands/CommandHelpFormatter.java +++ b/core/src/main/java/co/aikar/commands/CommandHelpFormatter.java @@ -174,7 +174,7 @@ public class CommandHelpFormatter { return new String[]{ "{command}", entry.getCommand(), "{commandprefix}", help.getCommandPrefix(), - "{parameters}", entry.getParameterSyntax(), + "{parameters}", entry.getParameterSyntax(help.getIssuer()), "{separator}", entry.getDescription().isEmpty() ? "" : "-", "{description}", entry.getDescription() }; @@ -192,9 +192,9 @@ public class CommandHelpFormatter { public String[] getParameterFormatReplacements(CommandHelp help, CommandParameter param, HelpEntry entry) { //{name} {description} return new String[]{ - "{name}", param.getName(), - "{syntaxorname}", ACFUtil.nullDefault(param.getSyntax(), param.getName()), - "{syntax}", ACFUtil.nullDefault(param.getSyntax(), ""), + "{name}", param.getDisplayName(help.getIssuer()), + "{syntaxorname}", ACFUtil.nullDefault(param.getSyntax(help.getIssuer()), param.getDisplayName(help.getIssuer())), + "{syntax}", ACFUtil.nullDefault(param.getSyntax(help.getIssuer()), ""), "{description}", ACFUtil.nullDefault(param.getDescription(), ""), "{command}", help.getCommandName(), "{fullcommand}", entry.getCommand(), diff --git a/core/src/main/java/co/aikar/commands/CommandParameter.java b/core/src/main/java/co/aikar/commands/CommandParameter.java index dfeb0de2..dbfeaec8 100644 --- a/core/src/main/java/co/aikar/commands/CommandParameter.java +++ b/core/src/main/java/co/aikar/commands/CommandParameter.java @@ -28,6 +28,7 @@ import co.aikar.commands.annotation.Conditions; import co.aikar.commands.annotation.Default; import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Flags; +import co.aikar.commands.annotation.Name; import co.aikar.commands.annotation.Optional; import co.aikar.commands.annotation.Single; import co.aikar.commands.annotation.Syntax; @@ -36,6 +37,7 @@ import co.aikar.commands.contexts.ContextResolver; import co.aikar.commands.contexts.IssuerAwareContextResolver; import co.aikar.commands.contexts.IssuerOnlyContextResolver; import co.aikar.commands.contexts.OptionalContextResolver; +import co.aikar.locales.MessageKey; import java.lang.reflect.Parameter; import java.util.Arrays; @@ -74,11 +76,12 @@ public class CommandParameter"; - } - } } this.flags = new HashMap<>(); @@ -174,6 +170,11 @@ public class CommandParameter"; + } + } return syntax; } diff --git a/core/src/main/java/co/aikar/commands/HelpEntry.java b/core/src/main/java/co/aikar/commands/HelpEntry.java index 577b4b22..adfc3283 100644 --- a/core/src/main/java/co/aikar/commands/HelpEntry.java +++ b/core/src/main/java/co/aikar/commands/HelpEntry.java @@ -46,8 +46,13 @@ public class HelpEntry { return this.commandHelp.getCommandPrefix(); } - public String getParameterSyntax(){ - return this.command.syntaxText != null ? this.command.syntaxText : ""; + public String getParameterSyntax() { + return this.getParameterSyntax(null); + } + + public String getParameterSyntax(CommandIssuer issuer) { + String translated = this.command.getSyntaxText(issuer); + return translated != null ? translated : ""; } public String getDescription(){ diff --git a/core/src/main/java/co/aikar/commands/Locales.java b/core/src/main/java/co/aikar/commands/Locales.java index 877014e6..e655982d 100644 --- a/core/src/main/java/co/aikar/commands/Locales.java +++ b/core/src/main/java/co/aikar/commands/Locales.java @@ -180,6 +180,13 @@ public class Locales { return message; } + public String getOptionalMessage(CommandIssuer issuer, MessageKey key) { + if (issuer == null) { + return this.localeManager.getTable(getDefaultLocale()).getMessage(key); + } + return this.localeManager.getMessage(issuer, key); + } + public String replaceI18NStrings(String message) { if (message == null) { return null; diff --git a/core/src/main/java/co/aikar/commands/RegisteredCommand.java b/core/src/main/java/co/aikar/commands/RegisteredCommand.java index ba809435..9e16c238 100644 --- a/core/src/main/java/co/aikar/commands/RegisteredCommand.java +++ b/core/src/main/java/co/aikar/commands/RegisteredCommand.java @@ -97,6 +97,7 @@ public class RegisteredCommand previousParam = null; for (int i = 0; i < parameters.length; i++) { @@ -129,16 +129,8 @@ public class RegisteredCommand 0) { - syntaxBuilder.append(' '); - } - syntaxBuilder.append(parameter.getSyntax()); - } } - String syntaxText = syntaxBuilder.toString().trim(); - final String syntaxStr = annotations.getAnnotationValue(method, Syntax.class); - this.syntaxText = syntaxStr != null ? ACFUtil.replace(syntaxStr, "@syntax", syntaxText) : syntaxText; + this.requiredResolvers = requiredResolvers; this.consumeInputResolvers = consumeInputResolvers; this.doesNotConsumeInputResolvers = doesNotConsumeInputResolvers; @@ -345,7 +337,22 @@ public class RegisteredCommand parameter : parameters) { + String syntax = parameter.getSyntax(issuer); + if (syntax != null) { + if (syntaxBuilder.length() > 0) { + syntaxBuilder.append(' '); + } + syntaxBuilder.append(syntax); + } + } + return syntaxBuilder.toString().trim(); } public String getHelpText() { diff --git a/core/src/main/java/co/aikar/commands/annotation/Name.java b/core/src/main/java/co/aikar/commands/annotation/Name.java new file mode 100644 index 00000000..353a8ff8 --- /dev/null +++ b/core/src/main/java/co/aikar/commands/annotation/Name.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016-2020 Daniel Ennis (Aikar) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package co.aikar.commands.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +public @interface Name { + String value(); +}