77import fr .xephi .authme .command .CommandUtils ;
88import fr .xephi .authme .command .FoundCommandResult ;
99import fr .xephi .authme .initialization .Reloadable ;
10+ import fr .xephi .authme .message .PlayerLocaleResolver ;
1011import fr .xephi .authme .permission .DefaultPermission ;
1112import fr .xephi .authme .permission .PermissionNode ;
1213import fr .xephi .authme .permission .PermissionsManager ;
14+ import fr .xephi .authme .settings .Settings ;
1315import org .bukkit .ChatColor ;
1416import org .bukkit .command .CommandSender ;
1517
@@ -49,13 +51,15 @@ public class HelpProvider implements Reloadable {
4951
5052 private final PermissionsManager permissionsManager ;
5153 private final HelpMessagesService helpMessagesService ;
54+ private final Settings settings ;
5255 /** int with bit flags set corresponding to the above constants for enabled sections. */
5356 private Integer enabledSections ;
5457
5558 @ Inject
56- HelpProvider (PermissionsManager permissionsManager , HelpMessagesService helpMessagesService ) {
59+ HelpProvider (PermissionsManager permissionsManager , HelpMessagesService helpMessagesService , Settings settings ) {
5760 this .permissionsManager = permissionsManager ;
5861 this .helpMessagesService = helpMessagesService ;
62+ this .settings = settings ;
5963 }
6064
6165 /**
@@ -77,37 +81,38 @@ private List<String> buildHelpOutput(CommandSender sender, FoundCommandResult re
7781 // Return directly if no options are enabled so we don't include the help header
7882 return lines ;
7983 }
80- String header = helpMessagesService .getMessage (HelpMessage .HEADER );
84+ String language = PlayerLocaleResolver .resolveLanguage (settings , sender );
85+ String header = helpMessagesService .getMessage (HelpMessage .HEADER , language );
8186 if (!header .isEmpty ()) {
8287 lines .add (ChatColor .GOLD + header );
8388 }
8489
85- CommandDescription command = helpMessagesService .buildLocalizedDescription (result .getCommandDescription ());
90+ CommandDescription command = helpMessagesService .buildLocalizedDescription (result .getCommandDescription (), language );
8691 List <String > correctLabels = ImmutableList .copyOf (filterCorrectLabels (command , result .getLabels ()));
8792
8893 if (hasFlag (SHOW_COMMAND , options )) {
89- lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .COMMAND ) + ": "
94+ lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .COMMAND , language ) + ": "
9095 + CommandUtils .buildSyntax (command , correctLabels ));
9196 }
9297 if (hasFlag (SHOW_DESCRIPTION , options )) {
93- lines .add (ChatColor .GOLD + helpMessagesService .getMessage (SHORT_DESCRIPTION ) + ": "
98+ lines .add (ChatColor .GOLD + helpMessagesService .getMessage (SHORT_DESCRIPTION , language ) + ": "
9499 + ChatColor .WHITE + command .getDescription ());
95100 }
96101 if (hasFlag (SHOW_LONG_DESCRIPTION , options )) {
97- lines .add (ChatColor .GOLD + helpMessagesService .getMessage (DETAILED_DESCRIPTION ) + ":" );
102+ lines .add (ChatColor .GOLD + helpMessagesService .getMessage (DETAILED_DESCRIPTION , language ) + ":" );
98103 lines .add (ChatColor .WHITE + " " + command .getDetailedDescription ());
99104 }
100105 if (hasFlag (SHOW_ARGUMENTS , options )) {
101- addArgumentsInfo (command , lines );
106+ addArgumentsInfo (command , lines , language );
102107 }
103108 if (hasFlag (SHOW_PERMISSIONS , options ) && sender != null ) {
104- addPermissionsInfo (command , sender , lines );
109+ addPermissionsInfo (command , sender , lines , language );
105110 }
106111 if (hasFlag (SHOW_ALTERNATIVES , options )) {
107- addAlternativesInfo (command , correctLabels , lines );
112+ addAlternativesInfo (command , correctLabels , lines , language );
108113 }
109114 if (hasFlag (SHOW_CHILDREN , options )) {
110- addChildrenInfo (command , correctLabels , lines );
115+ addChildrenInfo (command , correctLabels , lines , language );
111116 }
112117
113118 return lines ;
@@ -165,14 +170,14 @@ private int flagFor(HelpSection section, int flag) {
165170 * @param command the command to generate arguments info for
166171 * @param lines the output collection to add the info to
167172 */
168- private void addArgumentsInfo (CommandDescription command , List <String > lines ) {
173+ private void addArgumentsInfo (CommandDescription command , List <String > lines , String language ) {
169174 if (command .getArguments ().isEmpty ()) {
170175 return ;
171176 }
172177
173- lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .ARGUMENTS ) + ":" );
178+ lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .ARGUMENTS , language ) + ":" );
174179 StringBuilder argString = new StringBuilder ();
175- String optionalText = " (" + helpMessagesService .getMessage (HelpMessage .OPTIONAL ) + ")" ;
180+ String optionalText = " (" + helpMessagesService .getMessage (HelpMessage .OPTIONAL , language ) + ")" ;
176181 for (CommandArgumentDescription argument : command .getArguments ()) {
177182 argString .setLength (0 );
178183 argString .append (" " ).append (ChatColor .YELLOW ).append (ChatColor .ITALIC ).append (argument .getName ())
@@ -192,12 +197,13 @@ private void addArgumentsInfo(CommandDescription command, List<String> lines) {
192197 * @param correctLabels labels used to access the command (sanitized)
193198 * @param lines the output collection to add the info to
194199 */
195- private void addAlternativesInfo (CommandDescription command , List <String > correctLabels , List <String > lines ) {
200+ private void addAlternativesInfo (CommandDescription command , List <String > correctLabels , List <String > lines ,
201+ String language ) {
196202 if (command .getLabels ().size () <= 1 ) {
197203 return ;
198204 }
199205
200- lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .ALTERNATIVES ) + ":" );
206+ lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .ALTERNATIVES , language ) + ":" );
201207
202208 // Label with which the command was called -> don't show it as an alternative
203209 final String usedLabel ;
@@ -227,45 +233,46 @@ private void addAlternativesInfo(CommandDescription command, List<String> correc
227233 * @param sender the command sender, used to evaluate permissions
228234 * @param lines the output collection to add the info to
229235 */
230- private void addPermissionsInfo (CommandDescription command , CommandSender sender , List <String > lines ) {
236+ private void addPermissionsInfo (CommandDescription command , CommandSender sender , List <String > lines ,
237+ String language ) {
231238 PermissionNode permission = command .getPermission ();
232239 if (permission == null ) {
233240 return ;
234241 }
235- lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .PERMISSIONS ) + ":" );
242+ lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .PERMISSIONS , language ) + ":" );
236243
237244 boolean hasPermission = permissionsManager .hasPermission (sender , permission );
238245 lines .add (String .format (" " + ChatColor .YELLOW + ChatColor .ITALIC + "%s" + ChatColor .GRAY + " (%s)" ,
239- permission .getNode (), getLocalPermissionText (hasPermission )));
246+ permission .getNode (), getLocalPermissionText (hasPermission , language )));
240247
241248 // Addendum to the line to specify whether the sender has permission or not when default is OP_ONLY
242249 final DefaultPermission defaultPermission = permission .getDefaultPermission ();
243250 String addendum = "" ;
244251 if (DefaultPermission .OP_ONLY .equals (defaultPermission )) {
245- addendum = " (" + getLocalPermissionText (defaultPermission .evaluate (sender )) + ")" ;
252+ addendum = " (" + getLocalPermissionText (defaultPermission .evaluate (sender ), language ) + ")" ;
246253 }
247- lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpMessage .DEFAULT ) + ": "
248- + ChatColor .GRAY + ChatColor .ITALIC + helpMessagesService .getMessage (defaultPermission ) + addendum );
254+ lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpMessage .DEFAULT , language ) + ": "
255+ + ChatColor .GRAY + ChatColor .ITALIC + helpMessagesService .getMessage (defaultPermission , language ) + addendum );
249256
250257 // Evaluate if the sender has permission to the command
251258 ChatColor permissionColor ;
252259 String permissionText ;
253260 if (permissionsManager .hasPermission (sender , command .getPermission ())) {
254261 permissionColor = ChatColor .GREEN ;
255- permissionText = getLocalPermissionText (true );
262+ permissionText = getLocalPermissionText (true , language );
256263 } else {
257264 permissionColor = ChatColor .DARK_RED ;
258- permissionText = getLocalPermissionText (false );
265+ permissionText = getLocalPermissionText (false , language );
259266 }
260267 lines .add (String .format (ChatColor .GOLD + " %s: %s" + ChatColor .ITALIC + "%s" ,
261- helpMessagesService .getMessage (HelpMessage .RESULT ), permissionColor , permissionText ));
268+ helpMessagesService .getMessage (HelpMessage .RESULT , language ), permissionColor , permissionText ));
262269 }
263270
264- private String getLocalPermissionText (boolean hasPermission ) {
271+ private String getLocalPermissionText (boolean hasPermission , String language ) {
265272 if (hasPermission ) {
266- return helpMessagesService .getMessage (HelpMessage .HAS_PERMISSION );
273+ return helpMessagesService .getMessage (HelpMessage .HAS_PERMISSION , language );
267274 }
268- return helpMessagesService .getMessage (HelpMessage .NO_PERMISSION );
275+ return helpMessagesService .getMessage (HelpMessage .NO_PERMISSION , language );
269276 }
270277
271278 /**
@@ -275,16 +282,17 @@ private String getLocalPermissionText(boolean hasPermission) {
275282 * @param correctLabels the labels used to access the given command (sanitized)
276283 * @param lines the output collection to add the info to
277284 */
278- private void addChildrenInfo (CommandDescription command , List <String > correctLabels , List <String > lines ) {
285+ private void addChildrenInfo (CommandDescription command , List <String > correctLabels , List <String > lines ,
286+ String language ) {
279287 if (command .getChildren ().isEmpty ()) {
280288 return ;
281289 }
282290
283- lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .CHILDREN ) + ":" );
291+ lines .add (ChatColor .GOLD + helpMessagesService .getMessage (HelpSection .CHILDREN , language ) + ":" );
284292 String parentCommandPath = String .join (" " , correctLabels );
285293 for (CommandDescription child : command .getChildren ()) {
286294 lines .add (" /" + parentCommandPath + " " + child .getLabels ().get (0 )
287- + ChatColor .GRAY + ChatColor .ITALIC + ": " + helpMessagesService .getDescription (child ));
295+ + ChatColor .GRAY + ChatColor .ITALIC + ": " + helpMessagesService .getDescription (child , language ));
288296 }
289297 }
290298
0 commit comments