Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
GenericCommandHelpTopic.java
1 package org.bukkit.help;
2 
3 import org.bukkit.ChatColor;
6 import org.apache.commons.lang.StringUtils;
10 import org.bukkit.help.HelpTopic;
11 
12 /**
13  * Lacking an alternative, the help system will create instances of
14  * GenericCommandHelpTopic for each command in the server's CommandMap. You
15  * can use this class as a base class for custom help topics, or as an example
16  * for how to write your own.
17  */
18 public class GenericCommandHelpTopic extends HelpTopic {
19 
20  protected Command command;
21 
22  public GenericCommandHelpTopic(Command command) {
23  this.command = command;
24 
25  if (command.getLabel().startsWith("/")) {
26  name = command.getLabel();
27  } else {
28  name = "/" + command.getLabel();
29  }
30 
31  // The short text is the first line of the description
32  int i = command.getDescription().indexOf("\n");
33  if (i > 1) {
34  shortText = command.getDescription().substring(0, i - 1);
35  } else {
36  shortText = command.getDescription();
37  }
38 
39  // Build full text
40  StringBuffer sb = new StringBuffer();
41 
42  sb.append(ChatColor.GOLD);
43  sb.append("Description: ");
44  sb.append(ChatColor.WHITE);
45  sb.append(command.getDescription());
46 
47  sb.append("\n");
48 
49  sb.append(ChatColor.GOLD);
50  sb.append("Usage: ");
51  sb.append(ChatColor.WHITE);
52  sb.append(command.getUsage().replace("<command>", name.substring(1)));
53 
54  if (command.getAliases().size() > 0) {
55  sb.append("\n");
56  sb.append(ChatColor.GOLD);
57  sb.append("Aliases: ");
58  sb.append(ChatColor.WHITE);
59  sb.append(ChatColor.WHITE + StringUtils.join(command.getAliases(), ", "));
60  }
61  fullText = sb.toString();
62  }
63 
64  public boolean canSee(CommandSender sender) {
65  if (!command.isRegistered() && !(command instanceof VanillaCommand)) {
66  // Unregistered commands should not show up in the help (ignore VanillaCommands)
67  return false;
68  }
69 
70  if (sender instanceof ConsoleCommandSender) {
71  return true;
72  }
73 
74  if (amendedPermission != null) {
75  return sender.hasPermission(amendedPermission);
76  } else {
77  return command.testPermissionSilent(sender);
78  }
79  }
80 }
boolean hasPermission(String name)
boolean testPermissionSilent(CommandSender target)