-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
DenizenAliasHelpTopic.java
42 lines (35 loc) · 1.57 KB
/
DenizenAliasHelpTopic.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package net.aufdemrand.denizen.utilities;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.help.HelpMap;
import org.bukkit.help.HelpTopic;
public class DenizenAliasHelpTopic extends HelpTopic {
private final String aliasFor;
private final HelpMap helpMap;
public DenizenAliasHelpTopic(String alias, String aliasFor, HelpMap helpMap) {
this.aliasFor = aliasFor.startsWith("/") ? aliasFor : "/" + aliasFor;
this.helpMap = helpMap;
this.name = alias.startsWith("/") ? alias : "/" + alias;
Validate.isTrue(!this.name.equals(this.aliasFor), "Command " + this.name + " cannot be alias for itself");
this.shortText = ChatColor.YELLOW + "Alias for " + ChatColor.WHITE + this.aliasFor;
}
public String getFullText(CommandSender forWho) {
StringBuilder sb = new StringBuilder(this.shortText);
HelpTopic aliasForTopic = this.helpMap.getHelpTopic(this.aliasFor);
if (aliasForTopic != null) {
sb.append("\n");
sb.append(aliasForTopic.getFullText(forWho));
}
return sb.toString();
}
public boolean canSee(CommandSender commandSender) {
if (this.amendedPermission == null) {
HelpTopic aliasForTopic = this.helpMap.getHelpTopic(this.aliasFor);
return aliasForTopic != null && aliasForTopic.canSee(commandSender);
}
else {
return commandSender.hasPermission(this.amendedPermission);
}
}
}