From 87f88cb32acf4320142fbb3c4d3a6f987ea8c682 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 9 Oct 2016 16:23:18 +0200 Subject: [PATCH] #293 Fix localized command losing its children --- .../authme/command/help/HelpMessagesService.java | 4 +++- src/main/resources/messages/help_en.yml | 3 ++- .../command/help/HelpMessagesServiceTest.java | 14 ++++++++++++++ .../fr/xephi/authme/command/help/help_test.yml | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/command/help/HelpMessagesService.java b/src/main/java/fr/xephi/authme/command/help/HelpMessagesService.java index caddcc37..b500e431 100644 --- a/src/main/java/fr/xephi/authme/command/help/HelpMessagesService.java +++ b/src/main/java/fr/xephi/authme/command/help/HelpMessagesService.java @@ -62,7 +62,9 @@ public class HelpMessagesService implements Reloadable { ++i; } - return builder.build(); + CommandDescription localCommand = builder.build(); + localCommand.getChildren().addAll(command.getChildren()); + return localCommand; } public String getMessage(HelpMessage message) { diff --git a/src/main/resources/messages/help_en.yml b/src/main/resources/messages/help_en.yml index 4a9fe5ec..bcc501b7 100644 --- a/src/main/resources/messages/help_en.yml +++ b/src/main/resources/messages/help_en.yml @@ -29,9 +29,10 @@ section: # ------------------------------------------------------- # You can translate the data for all commands using the below pattern. -# So for example to translate /authme reload, create a section "authme.reload", or "login" for /login +# For example to translate /authme reload, create a section "authme.reload", or "login" for /login # If the command has arguments, you can use arg1 as below to translate the first argument, and so forth # Translations don't need to be complete; any missing section will be taken from the default silently +# Important: Put main commands like "authme" before their children (e.g. "authme.reload") commands: authme.register: description: 'Register a player' diff --git a/src/test/java/fr/xephi/authme/command/help/HelpMessagesServiceTest.java b/src/test/java/fr/xephi/authme/command/help/HelpMessagesServiceTest.java index 39130534..ac346d24 100644 --- a/src/test/java/fr/xephi/authme/command/help/HelpMessagesServiceTest.java +++ b/src/test/java/fr/xephi/authme/command/help/HelpMessagesServiceTest.java @@ -92,6 +92,20 @@ public class HelpMessagesServiceTest { assertThat(localCommand, sameInstance(command)); } + @Test + public void shouldKeepChildrenInLocalCommand() { + // given + CommandDescription command = TestCommandsUtil.getCommandWithLabel(COMMANDS, "authme"); + + // when + CommandDescription localCommand = helpMessagesService.buildLocalizedDescription(command); + + // then + assertThat(localCommand.getChildren(), equalTo(command.getChildren())); + assertThat(localCommand.getDescription(), equalTo("authme cmd")); + assertThat(localCommand.getDetailedDescription(), equalTo("Main command")); + } + @Test public void shouldGetTranslationsForSectionAndMessage() { // given / when / then diff --git a/src/test/resources/fr/xephi/authme/command/help/help_test.yml b/src/test/resources/fr/xephi/authme/command/help/help_test.yml index a7616cc9..2fe4ee44 100644 --- a/src/test/resources/fr/xephi/authme/command/help/help_test.yml +++ b/src/test/resources/fr/xephi/authme/command/help/help_test.yml @@ -7,6 +7,8 @@ section: arguments: 'arg.' commands: + authme: + detailedDescription: 'Main command' authme.register: description: 'Registration' detailedDescription: 'Registers the player'