use of org.bukkit.command.defaults.HelpCommand in project Denizen-For-Bukkit by DenizenScript.
the class CommandScriptHelper method init.
public static void init() {
if (isInitialized) {
return;
}
isInitialized = true;
try {
Server server = Bukkit.getServer();
server.getPluginManager().registerEvents(instance, Denizen.getInstance());
// Get the CommandMap for the server
Field commandMapField = server.getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
CommandMap commandMap = (CommandMap) commandMapField.get(server);
// Get the knownCommands for the server's CommandMap
Field kcf = null;
Class commandMapClass = commandMap.getClass();
while (kcf == null && commandMapClass != Object.class) {
try {
kcf = commandMapClass.getDeclaredField("knownCommands");
} catch (NoSuchFieldException e) {
commandMapClass = commandMapClass.getSuperclass();
}
}
final Field knownCommandsField = kcf;
knownCommandsField.setAccessible(true);
knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
// Get the HelpMap for the server
HelpMap helpMap = server.getHelpMap();
// Get the helpTopics for the server's HelpMap
final Field helpTopicsField = helpMap.getClass().getDeclaredField("helpTopics");
helpTopicsField.setAccessible(true);
helpTopics = (Map<String, HelpTopic>) helpTopicsField.get(helpMap);
// TODO: figure out a different workaround?
if (Settings.overrideHelp()) {
new BukkitRunnable() {
@Override
public void run() {
if (knownCommands.get("help") instanceof HelpCommand) {
return;
}
knownCommands.put("help", knownCommands.get("bukkit:help"));
helpTopics.put("/help", helpTopics.get("/bukkit:help"));
}
}.runTaskLater(Denizen.getInstance(), 1);
}
} catch (Exception e) {
Debug.echoError("Error getting the server's command information! Are you running a non-CraftBukkit server?");
Debug.echoError("Command scripts will not function!");
// dB.echoError(e);
hasCommandInformation = false;
}
}
Aggregations