22
33import org .broken .arrow .library .color .TextTranslator ;
44import org .broken .arrow .library .command .CommandRegister ;
5- import org .broken .arrow .library .command .builers .CommandMessages ;
65import org .broken .arrow .library .command .command .CommandProperty ;
76import org .broken .arrow .library .command .subcommand .CommandDisplayConfig ;
87import org .bukkit .Location ;
@@ -64,7 +63,7 @@ public boolean execute(@Nonnull final CommandSender sender, @Nonnull final Strin
6463 if (mainCommand != null ) {
6564 final String permission = mainCommand .getPermission ();
6665 if (permission != null && !permission .isEmpty () && !sender .hasPermission (permission )) {
67- sender .sendMessage (( colors ( placeholders (mainCommand .getPermissionMessage (), commandLabel , mainCommand )) ));
66+ sender .sendMessage (placeholders (mainCommand .getPermissionMessage (), commandLabel , mainCommand ));
6867 return false ;
6968 }
7069 boolean executeCommand = mainCommand .executeCommand (sender , commandLabel , args );
@@ -161,7 +160,7 @@ private boolean sendHelpMessage(@NonNull final MainCommandHandler commandHandler
161160 if (!executeCommand || args .length == 0 ) {
162161 final String [] usageMessage = mainCommand .getUsageMessage ();
163162 if (usageMessage .length > 0 ) {
164- sender .sendMessage (( colors ( placeholders (usageMessage , commandLabel , mainCommand )) ));
163+ sender .sendMessage (placeholders (usageMessage , commandLabel , mainCommand ));
165164 return true ;
166165 }
167166 return true ;
@@ -260,7 +259,7 @@ private void sendMessage(final CommandSender sender, final String commandLabel)
260259 final String commandLabelMessage = commandRegister .getCommandLabelMessage ();
261260 final String labelMessageNoPerms = commandRegister .getCommandLabelMessageNoPerms ();
262261 if (labelMessageNoPerms != null && !labelMessageNoPerms .isEmpty () && !permissionCheck (sender , commandRegister .getCommandLabelPermission ())) {
263- sender .sendMessage (colors ( placeholders (labelMessageNoPerms , commandLabel , (CommandProperty ) null ) ));
262+ sender .sendMessage (placeholders (labelMessageNoPerms , commandLabel , (CommandProperty ) null ));
264263
265264 } else if (commandLabelMessage != null && !commandLabelMessage .isEmpty ()) {
266265 sendToSender (sender , commandLabel , commandLabelMessage , labelMessageNoPerms );
@@ -276,10 +275,10 @@ private void sendToSender(final CommandSender sender, final String commandLabel,
276275 continue ;
277276 }
278277 if (!checkPermission (sender , subcommand ) && labelMessageNoPerms != null && !labelMessageNoPerms .isEmpty ()) {
279- sender .sendMessage (colors ( placeholders (new String []{ labelMessageNoPerms } , commandLabel , subcommand ) ));
278+ sender .sendMessage (this . placeholders (labelMessageNoPerms , commandLabel , subcommand ));
280279 }
281280 if (checkPermission (sender , subcommand )) {
282- sender .sendMessage (colors ( placeholders (new String []{ labelMessageNoPerms } , commandLabel , subcommand ) ));
281+ sender .sendMessage (this . placeholders (labelMessageNoPerms , commandLabel , subcommand ));
283282 }
284283 }
285284 }
@@ -295,7 +294,7 @@ private void sendMessage(@Nonnull final CommandSender sender, final @NonNull Mai
295294 }
296295
297296 if (labelMessageNoPerms != null && !labelMessageNoPerms .isEmpty () && !permissionCheck (sender , commandDisplayConfig .getCommandLabelPermission ())) {
298- sender .sendMessage (colors ( placeholders (labelMessageNoPerms , commandLabel , commandDisplayConfig ) ));
297+ sender .sendMessage (placeholders (labelMessageNoPerms , commandLabel , commandDisplayConfig ));
299298 } else if (commandLabelMessage != null && !commandLabelMessage .isEmpty ()) {
300299 sendBody (sender , commandLabel , commandHandler , labelMessageNoPerms );
301300 }
@@ -316,10 +315,10 @@ private void sendBody(final CommandSender sender, final String commandLabel, @No
316315 continue ;
317316 }
318317 if (!checkPermission (sender , subcommand ) && labelMessageNoPerms != null && !labelMessageNoPerms .isEmpty ()) {
319- sender .sendMessage (colors ( placeholders (labelMessageNoPerms , commandLabel , subcommand ) ));
318+ sender .sendMessage (placeholders (labelMessageNoPerms , commandLabel , subcommand ));
320319 }
321320 if (checkPermission (sender , subcommand )) {
322- sender .sendMessage (colors ( placeholders (commandLabelMessage , commandLabel , subcommand ) ));
321+ sender .sendMessage (placeholders (commandLabelMessage , commandLabel , subcommand ));
323322 }
324323 }
325324 }
@@ -350,7 +349,8 @@ private String[] placeholders(@Nullable final String[] messages, @Nonnull final
350349 String [] string = new String [messages .length ];
351350
352351 for (int i = 0 ; i < messages .length ; i ++) {
353- string [i ] = messages [i ].replace ("{label}" , "/" + commandLabel + (subcommand != null ? " " + this .formatSet (subcommand .getCommandLabels ()) : "" )).replace ("{perm}" , permission );
352+ final String message = messages [i ].replace ("{label}" , "/" + commandLabel + (subcommand != null ? " " + this .formatSet (subcommand .getCommandLabels ()) : "" )).replace ("{perm}" , permission );
353+ string [i ] = this .translateColors (message );
354354 }
355355
356356 return string ;
@@ -361,7 +361,8 @@ private String[] placeholders(@Nullable final String message, @Nonnull final Str
361361 String permission = subcommand != null ? subcommand .getPermission () : null ;
362362 if (permission == null ) permission = "" ;
363363
364- return new String []{message .replace ("{label}" , "/" + commandLabel + (subcommand != null ? " " + this .formatSet (subcommand .getCommandLabels ()) : "" )).replace ("{perm}" , permission )};
364+ final String string = message .replace ("{label}" , "/" + commandLabel + (subcommand != null ? " " + this .formatSet (subcommand .getCommandLabels ()) : "" )).replace ("{perm}" , permission );
365+ return new String []{this .translateColors (string )};
365366 }
366367
367368 private String [] placeholders (@ Nullable final String message , @ Nonnull final String commandLabel , @ Nonnull final CommandDisplayConfig displayConfig ) {
@@ -370,15 +371,16 @@ private String[] placeholders(@Nullable final String message, @Nonnull final Str
370371 String permission = labelPermission != null && !labelPermission .isEmpty () ? labelPermission : null ;
371372 if (permission == null ) permission = "" ;
372373
373- return new String []{message .replace ("{label}" , "/" + commandLabel ).replace ("{perm}" , permission )};
374+ final String string = message .replace ("{label}" , "/" + commandLabel ).replace ("{perm}" , permission );
375+ return new String []{this .translateColors (string )};
374376 }
375377
376378
377379 /**
378380 * Translate colors on a text.
379381 *
380382 * @param messages the message to check the colors.
381- * @return Arrayy of strings that has formated colors.
383+ * @return Array of strings that has formated colors.
382384 */
383385 public String [] colors (final String [] messages ) {
384386 if (messages == null ) return new String []{"" };
@@ -389,11 +391,22 @@ public String[] colors(final String[] messages) {
389391 return string ;
390392 }
391393
394+ /**
395+ * Translate colors on a text.
396+ *
397+ * @param message the message to translate the color codes.
398+ * @return Array of strings that has formated colors.
399+ */
400+ public String translateColors (final String message ) {
401+ if (message == null ) return "" ;
402+ return TextTranslator .toSpigotFormat (message );
403+ }
404+
392405 private boolean sendNoPermission (@ Nonnull final CommandSender sender , @ Nonnull final String commandLabel , @ Nonnull final CommandProperty executor ) {
393406 if (!checkPermission (sender , executor )) {
394407 String permissionMessage = executor .getPermissionMessage ();
395408 if (permissionMessage != null && !permissionMessage .isEmpty ())
396- sender .sendMessage (colors ( placeholders (permissionMessage , commandLabel , executor ) ));
409+ sender .sendMessage (placeholders (permissionMessage , commandLabel , executor ));
397410 return true ;
398411 }
399412 return false ;
@@ -414,7 +427,7 @@ private boolean sendDescriptions(CommandSender sender, String commandLabel, Stri
414427 private void sendUsageMessage (@ Nonnull final CommandSender sender , @ Nonnull final String commandLabel , @ Nonnull final CommandProperty executor , final boolean executeCommand ) {
415428 String [] message = executor .getUsageMessage ();
416429 if (message .length > 0 && !executeCommand ) {
417- sender .sendMessage (colors ( placeholders (message , commandLabel , executor ) ));
430+ sender .sendMessage (placeholders (message , commandLabel , executor ));
418431 }
419432 }
420433
0 commit comments