Execute console commands from plugins...

Discussion in 'Plugin Development' started by bekvon, Feb 23, 2011.

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

    bekvon

    Just wondering if anyone knows a way to do it using only the bukkit API, or if its planned for a future bukkit version. I have a plugin that allows Telnet access to your server console, but to get it to work I have to call console commands from the MinecraftServer class itself rather then bukkit.
     
  2. Offline

    Nohup

    In CraftBukkit the server implementation has the following method:


    Code:
        public boolean dispatchCommand(CommandSender sender, String commandLine) {
            return commandMap.dispatch(sender, commandLine);
        }
    
    To use this you would just have to include CraftBukkit as one of your referenced jars and then cast the Server object in your plugin as CraftServer:

    Code:
        if (server instanceof CraftServer)
        {
            ((CraftServer) server).dispatchCommand(...);
        }
    
    P.S. I haven't tried this, just read through the code based on what you are asking. There may be an easier way that more-seasoned folks would know.
     
  3. Offline

    bekvon

    Hey, Thanks for the response :) I tried out your suggestion (was easy to try since I'm already referencing Craftbukkit.jar) but alas got nothing. Tried a couple different ways

    Code:
     ((CraftServer)getServer()).dispatchCommand(this,commandString);
    
    Since my class implements CommandSender I can use "this" in the above command.

    Also tried
    Code:
    ((CraftServer)getServer()).dispatchCommand(new ConsoleCommandSender(getServer()), commandString);
    
    Just to see if it would work with the ConsoleCommandSender class, but also no go.

    Anyway, thanks for the suggestion, maybe its just broken or unimplemented right now and will be fixed later.
     
Thread Status:
Not open for further replies.

Share This Page