Lang implemented for CommandWithSubcommands

This commit is contained in:
Risto Lahtela 2020-09-01 11:22:03 +03:00
parent 077a150498
commit c3250892d8
3 changed files with 18 additions and 11 deletions

View File

@ -96,7 +96,7 @@ public class PlanCommand {
}
public CommandWithSubcommands build() {
CommandWithSubcommands command = CommandWithSubcommands.builder()
CommandWithSubcommands command = CommandWithSubcommands.builder(locale)
.alias(commandName)
.colorScheme(colors)
.subcommand(serverCommand())
@ -298,7 +298,7 @@ public class PlanCommand {
}
private Subcommand databaseCommand() {
return CommandWithSubcommands.builder()
return CommandWithSubcommands.builder(locale)
.aliases("db", "database")
.optionalArgument(locale.getString(HelpLang.ARG_SUBCOMMAND), locale.getString(HelpLang.DESC_ARG_SUBCOMMAND))
.colorScheme(colors)

View File

@ -16,6 +16,8 @@
*/
package com.djrapitops.plan.commands.use;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.lang.CommandLang;
import com.djrapitops.plan.utilities.java.TriConsumer;
import com.djrapitops.plugin.command.ColorScheme;
@ -34,28 +36,31 @@ public class CommandWithSubcommands extends Subcommand {
private TriConsumer<RuntimeException, CMDSender, Arguments> exceptionHandler;
private ColorScheme colors;
private CommandWithSubcommands() {
private final Locale locale;
private CommandWithSubcommands(Locale locale) {
this.locale = locale;
subcommands = new ArrayList<>();
}
public static Builder builder() {
return new Builder();
public static Builder builder(Locale locale) {
return new Builder(locale);
}
public void onHelp(CMDSender sender, Arguments arguments) {
List<Subcommand> hasPermissionFor = subcommands.stream().filter(sender::hasAllPermissionsFor).collect(Collectors.toList());
sender.buildMessage()
.addPart("Header" /*TODO*/)
.addPart(locale.getString(CommandLang.HEADER_HELP, getPrimaryAlias()))
.newLine().newLine()
.apply(new HelpFormatter(sender, colors, getPrimaryAlias(), hasPermissionFor)::addSubcommands)
.newLine().newLine()
.addPart("Footer" /*TODO*/)
.addPart(locale.getString(CommandLang.FOOTER_HELP))
.send();
}
public void onCommand(CMDSender sender, Arguments arguments) {
if (sender.isMissingPermissionsFor(this)) {
sender.send(/* TODO */"NO PERMISSION");
sender.send(locale.getString(CommandLang.FAIL_NO_PERMISSION) + " " + getRequiredPermissions());
return;
}
try {
@ -75,7 +80,7 @@ public class CommandWithSubcommands extends Subcommand {
for (Subcommand subcommand : subcommands) {
if (subcommand.getAliases().contains(alias)) {
if (sender.isMissingPermissionsFor(subcommand)) {
sender.send(/* TODO */"NO PERMISSION");
sender.send(locale.getString(CommandLang.FAIL_NO_PERMISSION) + " " + subcommand.getRequiredPermissions());
continue;
}
subcommand.getExecutor().accept(sender, arguments.removeFirst());
@ -114,8 +119,8 @@ public class CommandWithSubcommands extends Subcommand {
public static class Builder extends Subcommand.Builder<Builder> {
private final CommandWithSubcommands command;
private Builder() {
this(new CommandWithSubcommands());
private Builder(Locale locale) {
this(new CommandWithSubcommands(locale));
}
private Builder(CommandWithSubcommands command) {

View File

@ -71,6 +71,8 @@ public enum CommandLang implements Lang {
LINK_JSON("Cmd - Link Player JSON", "Player json: "),
LINK_REGISTER("Cmd - Link Register", "Register page: "),
HEADER_HELP("Cmd Header - Help", "> §2/${0} Help"),
FOOTER_HELP("Cmd Footer - Help", "> §7Hover over command or arguments to learn more about them."),
HEADER_SEARCH("Cmd Header - Search", "> §2${0} Results for §f${1}§2:"),
HEADER_ANALYSIS("Cmd Header - Analysis", "> §2Analysis Results"),
HEADER_INFO("Cmd Header - Info", "> §2Player Analytics"),