|
7 | 7 |
|
8 | 8 | import java.io.File; |
9 | 9 | import java.io.IOException; |
10 | | -import java.util.*; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.Arrays; |
| 12 | +import java.util.Collection; |
| 13 | +import java.util.HashMap; |
| 14 | +import java.util.HashSet; |
| 15 | +import java.util.Iterator; |
| 16 | +import java.util.List; |
| 17 | +import java.util.Map; |
| 18 | +import java.util.Optional; |
| 19 | +import java.util.Set; |
11 | 20 | import java.util.function.Function; |
12 | 21 | import java.util.function.Predicate; |
13 | 22 | import java.util.logging.Level; |
14 | 23 | import java.util.logging.Logger; |
15 | 24 |
|
16 | | -import dev.jorel.commandapi.arguments.AbstractArgument; |
17 | | -import dev.jorel.commandapi.commandsenders.*; |
18 | 25 | import org.bukkit.Bukkit; |
19 | 26 | import org.bukkit.ChatColor; |
20 | 27 | import org.bukkit.Keyed; |
21 | | -import org.bukkit.command.*; |
| 28 | +import org.bukkit.command.BlockCommandSender; |
| 29 | +import org.bukkit.command.Command; |
| 30 | +import org.bukkit.command.CommandMap; |
| 31 | +import org.bukkit.command.CommandSender; |
| 32 | +import org.bukkit.command.ConsoleCommandSender; |
| 33 | +import org.bukkit.command.PluginCommand; |
| 34 | +import org.bukkit.command.ProxiedCommandSender; |
| 35 | +import org.bukkit.command.RemoteConsoleCommandSender; |
| 36 | +import org.bukkit.command.SimpleCommandMap; |
22 | 37 | import org.bukkit.entity.Player; |
23 | 38 | import org.bukkit.event.EventHandler; |
24 | 39 | import org.bukkit.event.EventPriority; |
|
38 | 53 | import com.mojang.brigadier.tree.LiteralCommandNode; |
39 | 54 | import com.mojang.brigadier.tree.RootCommandNode; |
40 | 55 |
|
| 56 | +import dev.jorel.commandapi.arguments.AbstractArgument; |
41 | 57 | import dev.jorel.commandapi.arguments.Argument; |
42 | 58 | import dev.jorel.commandapi.arguments.LiteralArgument; |
43 | 59 | import dev.jorel.commandapi.arguments.MultiLiteralArgument; |
44 | 60 | import dev.jorel.commandapi.arguments.SuggestionProviders; |
| 61 | +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; |
| 62 | +import dev.jorel.commandapi.commandsenders.AbstractPlayer; |
| 63 | +import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; |
| 64 | +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; |
| 65 | +import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; |
| 66 | +import dev.jorel.commandapi.commandsenders.BukkitEntity; |
| 67 | +import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; |
| 68 | +import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; |
| 69 | +import dev.jorel.commandapi.commandsenders.BukkitPlayer; |
| 70 | +import dev.jorel.commandapi.commandsenders.BukkitProxiedCommandSender; |
| 71 | +import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; |
45 | 72 | import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; |
46 | 73 | import dev.jorel.commandapi.nms.NMS; |
47 | 74 | import dev.jorel.commandapi.preprocessor.RequireField; |
@@ -329,56 +356,70 @@ void updateHelpForCommands(List<RegisteredCommand> commands) { |
329 | 356 | Map<String, HelpTopic> helpTopicsToAdd = new HashMap<>(); |
330 | 357 |
|
331 | 358 | for (RegisteredCommand command : commands) { |
332 | | - // Generate short description |
| 359 | + // Don't override the plugin help topic |
| 360 | + String commandPrefix = generateCommandHelpPrefix(command.commandName()); |
| 361 | + StringBuilder aliasSb = new StringBuilder(); |
333 | 362 | final String shortDescription; |
334 | | - final Optional<String> shortDescriptionOptional = command.shortDescription(); |
335 | | - final Optional<String> fullDescriptionOptional = command.fullDescription(); |
336 | | - if (shortDescriptionOptional.isPresent()) { |
337 | | - shortDescription = shortDescriptionOptional.get(); |
338 | | - } else if (fullDescriptionOptional.isPresent()) { |
339 | | - shortDescription = fullDescriptionOptional.get(); |
| 363 | + |
| 364 | + // Must be empty string, not null as defined by OBC::CustomHelpTopic |
| 365 | + final String permission = command.permission().getPermission().orElse(""); |
| 366 | + |
| 367 | + HelpTopic helpTopic; |
| 368 | + if (command.helpTopic().isPresent()) { |
| 369 | + helpTopic = (HelpTopic) command.helpTopic().get(); |
| 370 | + shortDescription = ""; |
340 | 371 | } else { |
341 | | - shortDescription = "A command by the " + config.getPlugin().getName() + " plugin."; |
342 | | - } |
343 | | - |
344 | | - // Generate full description |
345 | | - StringBuilder sb = new StringBuilder(); |
346 | | - if (fullDescriptionOptional.isPresent()) { |
347 | | - sb.append(ChatColor.GOLD).append("Description: ").append(ChatColor.WHITE).append(fullDescriptionOptional.get()).append("\n"); |
348 | | - } |
349 | | - |
350 | | - generateHelpUsage(sb, command); |
351 | | - sb.append("\n"); |
| 372 | + // Generate short description |
| 373 | + final Optional<String> shortDescriptionOptional = command.shortDescription(); |
| 374 | + final Optional<String> fullDescriptionOptional = command.fullDescription(); |
| 375 | + if (shortDescriptionOptional.isPresent()) { |
| 376 | + shortDescription = shortDescriptionOptional.get(); |
| 377 | + } else if (fullDescriptionOptional.isPresent()) { |
| 378 | + shortDescription = fullDescriptionOptional.get(); |
| 379 | + } else { |
| 380 | + shortDescription = "A command by the " + config.getPlugin().getName() + " plugin."; |
| 381 | + } |
| 382 | + |
| 383 | + // Generate full description |
| 384 | + StringBuilder sb = new StringBuilder(); |
| 385 | + if (fullDescriptionOptional.isPresent()) { |
| 386 | + sb.append(ChatColor.GOLD).append("Description: ").append(ChatColor.WHITE).append(fullDescriptionOptional.get()).append("\n"); |
| 387 | + } |
| 388 | + |
| 389 | + generateHelpUsage(sb, command); |
| 390 | + sb.append("\n"); |
| 391 | + |
| 392 | + // Generate aliases. We make a copy of the StringBuilder because we |
| 393 | + // want to change the output when we register aliases |
| 394 | + aliasSb = new StringBuilder(sb.toString()); |
| 395 | + if (command.aliases().length > 0) { |
| 396 | + sb.append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.WHITE).append(String.join(", ", command.aliases())); |
| 397 | + } |
352 | 398 |
|
353 | | - // Generate aliases. We make a copy of the StringBuilder because we |
354 | | - // want to change the output when we register aliases |
355 | | - StringBuilder aliasSb = new StringBuilder(sb.toString()); |
356 | | - if (command.aliases().length > 0) { |
357 | | - sb.append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.WHITE).append(String.join(", ", command.aliases())); |
| 399 | + helpTopic = generateHelpTopic(commandPrefix, shortDescription, sb.toString().trim(), permission); |
358 | 400 | } |
359 | | - |
360 | | - // Must be empty string, not null as defined by OBC::CustomHelpTopic |
361 | | - String permission = command.permission().getPermission().orElse(""); |
362 | | - |
363 | | - // Don't override the plugin help topic |
364 | | - String commandPrefix = generateCommandHelpPrefix(command.commandName()); |
365 | | - helpTopicsToAdd.put(commandPrefix, generateHelpTopic(commandPrefix, shortDescription, sb.toString().trim(), permission)); |
| 401 | + helpTopicsToAdd.put(commandPrefix, helpTopic); |
366 | 402 |
|
367 | 403 | for (String alias : command.aliases()) { |
368 | | - StringBuilder currentAliasSb = new StringBuilder(aliasSb.toString()); |
369 | | - currentAliasSb.append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.WHITE); |
370 | | - |
371 | | - // We want to get all aliases (including the original command name), |
372 | | - // except for the current alias |
373 | | - List<String> aliases = new ArrayList<>(Arrays.asList(command.aliases())); |
374 | | - aliases.add(command.commandName()); |
375 | | - aliases.remove(alias); |
376 | | - |
377 | | - currentAliasSb.append(ChatColor.WHITE).append(String.join(", ", aliases)); |
378 | | - |
379 | | - // Don't override the plugin help topic |
380 | | - commandPrefix = generateCommandHelpPrefix(alias); |
381 | | - helpTopicsToAdd.put(commandPrefix, generateHelpTopic(commandPrefix, shortDescription, currentAliasSb.toString().trim(), permission)); |
| 404 | + if (command.helpTopic().isPresent()) { |
| 405 | + helpTopic = (HelpTopic) command.helpTopic().get(); |
| 406 | + } else { |
| 407 | + StringBuilder currentAliasSb = new StringBuilder(aliasSb.toString()); |
| 408 | + currentAliasSb.append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.WHITE); |
| 409 | + |
| 410 | + // We want to get all aliases (including the original command name), |
| 411 | + // except for the current alias |
| 412 | + List<String> aliases = new ArrayList<>(Arrays.asList(command.aliases())); |
| 413 | + aliases.add(command.commandName()); |
| 414 | + aliases.remove(alias); |
| 415 | + |
| 416 | + currentAliasSb.append(ChatColor.WHITE).append(String.join(", ", aliases)); |
| 417 | + |
| 418 | + // Don't override the plugin help topic |
| 419 | + commandPrefix = generateCommandHelpPrefix(alias); |
| 420 | + helpTopic = generateHelpTopic(commandPrefix, shortDescription, currentAliasSb.toString().trim(), permission); |
| 421 | + } |
| 422 | + helpTopicsToAdd.put(commandPrefix, helpTopic); |
382 | 423 | } |
383 | 424 | } |
384 | 425 |
|
|
0 commit comments