Skip to content

Commit f807186

Browse files
committed
Fixed issue where it sends wrong message
1 parent d6c1231 commit f807186

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public List<String> tabComplete(@Nonnull final CommandSender sender, @Nonnull fi
107107
if (commandHandler != null) {
108108
CommandProperty mainCommand = commandHandler.getMainCommand();
109109
if (mainCommand != null) {
110-
final List<String> tabComplete = mainCommand.executeTabComplete(sender,alias,args);
110+
final List<String> tabComplete = mainCommand.executeTabComplete(sender, alias, args);
111111
return tabComplete != null && checkPermission(sender, mainCommand) ? tabComplete : new ArrayList<>();
112112
}
113113
if (args.length > 0) {
@@ -198,7 +198,7 @@ private boolean handleSubCommand(@NonNull final CommandSender sender, @NonNull f
198198
if (commandHandler.isSubCommandsSet()) return false;
199199

200200
if (args.length == 0) {
201-
this.sendMessage(sender, commandHandler.getCommandDisplayConfig(), commandLabel);
201+
this.sendMessage(sender, commandHandler, commandLabel);
202202
return false;
203203
}
204204

@@ -241,9 +241,24 @@ private void sendMessage(final CommandSender sender, final String commandLabel)
241241
sender.sendMessage(colors(suffixMessage));
242242
}
243243

244-
private void sendMessage(@Nonnull final CommandSender sender, @Nonnull final CommandDisplayConfig commandDisplayConfig, @Nonnull final String commandLabel) {
244+
private void sendToSender(final CommandSender sender, final String commandLabel, final String commandLabelMessage, final String labelMessageNoPerms) {
245+
for (final CommandProperty subcommand : commandRegister.getCommands()) {
246+
if (subcommand.isHideLabel() && !checkPermission(sender, subcommand)) {
247+
continue;
248+
}
249+
if (!checkPermission(sender, subcommand) && labelMessageNoPerms != null && !labelMessageNoPerms.isEmpty()) {
250+
sender.sendMessage(colors(placeholders(labelMessageNoPerms, commandLabel, subcommand)));
251+
}
252+
if (checkPermission(sender, subcommand)) {
253+
sender.sendMessage(colors(placeholders(commandLabelMessage, commandLabel, subcommand)));
254+
}
255+
}
256+
}
245257

258+
private void sendMessage(@Nonnull final CommandSender sender, final @NonNull MainCommandHandler commandHandler, @Nonnull final String commandLabel) {
259+
final CommandDisplayConfig commandDisplayConfig = commandHandler.getCommandDisplayConfig();
246260
final List<String> helpPrefixMessage = commandDisplayConfig.getPrefixMessage();
261+
247262
if (helpPrefixMessage != null && !helpPrefixMessage.isEmpty())
248263
for (final String prefixMessage : helpPrefixMessage)
249264
sender.sendMessage(colors(prefixMessage));
@@ -254,16 +269,19 @@ private void sendMessage(@Nonnull final CommandSender sender, @Nonnull final Com
254269
sender.sendMessage(colors(placeholders(labelMessageNoPerms, commandLabel, null)));
255270

256271
} else if (commandLabelMessage != null && !commandLabelMessage.isEmpty()) {
257-
sendToSender(sender, commandLabel, commandLabelMessage, labelMessageNoPerms);
272+
sendBody(sender, commandLabel, commandHandler, labelMessageNoPerms);
258273
}
259274
final List<String> helpSuffixMessage = commandDisplayConfig.getSuffixMessage();
260275
if (helpSuffixMessage != null && !helpSuffixMessage.isEmpty())
261276
for (final String suffixMessage : helpSuffixMessage)
262277
sender.sendMessage(colors(suffixMessage));
263278
}
264279

265-
private void sendToSender(final CommandSender sender, final String commandLabel, final String commandLabelMessage, final String labelMessageNoPerms) {
266-
for (final CommandProperty subcommand : commandRegister.getCommands()) {
280+
private void sendBody(final CommandSender sender, final String commandLabel, @NonNull final MainCommandHandler commandHandler, final String labelMessageNoPerms) {
281+
final CommandDisplayConfig commandDisplayConfig = commandHandler.getCommandDisplayConfig();
282+
final String commandLabelMessage = commandDisplayConfig.getCommandLabelMessage();
283+
284+
for (final CommandProperty subcommand : commandHandler.getSubcommands()) {
267285
if (subcommand.isHideLabel() && !checkPermission(sender, subcommand)) {
268286
continue;
269287
}

0 commit comments

Comments
 (0)