Skip to content

Commit 33cbb08

Browse files
committed
Fixed so it does not send empty strings in command
Make sure it does not send empty string if the message is not set.
1 parent 002a44c commit 33cbb08

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

Commands/src/main/java/org/broken/arrow/library/command/commandhandler/CommandExecutor.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,20 @@ private String[] placeholders(@Nullable final String[] messages, @Nonnull final
340340
if (messages == null) return new String[]{""};
341341
String permission = subcommand != null ? subcommand.getPermission() : null;
342342
if (permission == null) permission = "";
343-
String[] string = new String[messages.length];
343+
List<String> resultList = new ArrayList<>();
344344

345-
for (int i = 0; i < messages.length; i++) {
346-
final String message = messages[i].replace("{label}", "/" + commandLabel + (subcommand != null ? " " + this.formatSet(subcommand.getCommandLabels()) : "")).replace("{perm}", permission);
347-
string[i] = this.translateColors(message);
348-
}
345+
for (String message : messages) {
346+
if(message != null) {
347+
final String messageFormated = message
348+
.replace("{label}", "/" + commandLabel + (subcommand != null ? " " + this.formatSet(subcommand.getCommandLabels()) : ""))
349+
.replace("{perm}", permission);
349350

350-
return string;
351+
if (!messageFormated.isEmpty()) {
352+
resultList.add(this.translateColors(messageFormated));
353+
}
354+
}
355+
}
356+
return resultList.toArray(new String[0]);
351357
}
352358

353359
private String[] placeholders(@Nullable final String message, @Nonnull final String commandLabel, @Nullable final CommandProperty subcommand) {
@@ -421,7 +427,9 @@ private boolean sendDescriptions(CommandSender sender, String commandLabel, Stri
421427
private void sendUsageMessage(@Nonnull final CommandSender sender, @Nonnull final String commandLabel, @Nonnull final CommandProperty executor, final boolean executeCommand) {
422428
String[] message = executor.getUsageMessage();
423429
if (message.length > 0 && !executeCommand) {
424-
sender.sendMessage(placeholders(message, commandLabel, executor));
430+
String[] placeholders = placeholders(message, commandLabel, executor);
431+
if (placeholders.length > 0)
432+
sender.sendMessage(placeholders);
425433
}
426434
}
427435

0 commit comments

Comments
 (0)