Adding a command without putting CB in the build path and casting to CraftServer

Discussion in 'Plugin Development' started by hakelimopu, Oct 11, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    hakelimopu

    I have found the following will work to register a command not in my plugin.yml:

    (Note: MyDerivedCommand is a subclass of Command)
    Code:
       
    private void hookCommand() {
        if(Bukkit.getServer() instanceof CraftServer){
            CraftServer theServer = (CraftServer)Bukkit.getServer();
            CommandMap theCommandMap = theServer.getCommandMap();
            theCommandMap.register("nameOfCommand", new MyDerivedCommand());
        }
    }
    
    However, this requires that I put CB itself into the build path... a move that I do not like making if I don't have to.

    So, to the question.

    WITHOUT adding CB to the build path(so that Bukkit itself is the only reference needed), and subsequently casting the server to a CraftServer in order to get to the command map, how can I register a command? Or, is hacking into CB like the above the only way?
     
  2. Offline

    Ammar Askar

    Hacking/casting down into craftbukkit classes is the only way to do this at the moment, dynamic command registration doesn't exist in the bukkit api as of yet.
     
  3. Offline

    gamerzap

    Why not just add CB to the build path?
     
Thread Status:
Not open for further replies.

Share This Page