How do you add commands to your plugin?!?!

Discussion in 'Plugin Development' started by FlameHead269, Jan 15, 2011.

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

    FlameHead269

    Hello, Flame again. Me and my plugin partner are developing a plugin! But, since we're kind of new all we want to know is how to add a command to the plugin and maybe some other tips! If, you have any useful information please leave a message here!

    Thanks,
    FlameHead269,1337
     
  2. Offline

    DerpinLlama

    Use the PLAYER_COMMAND event.
     
  3. Offline

    1337

    im his plugin partner so would it be if(PLAYER_COMMAND == /whatever)?
     
  4. Offline

    DerpinLlama

    No - you need to extend the PlayerListener class and add the onCommand method.

    Like this:

    Code:
    public void onCommand(PlayerChatEvent event){
       Player player = event.getPlayer();
       String message = event.getMessage();
    }
    Of course you'll need to register PLAYER_COMMAND in your plugin's onEnable section:
    Code:
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
     
  5. Offline

    1337

    yes i got it thanks :)
     
  6. Offline

    FlameHead269

    Thanks!
    --- merged: Jan 15, 2011 2:32 PM ---
    Thanks!
     
  7. Offline

    Axalto

    Sorry to reopen this but this is an issue again for me. PLAYER_COMMAND has been removed and just changing it to SERVER_COMMAND and using a ServerHandler does not seem to work. I have searched with google but I cant seem to get it working.
     
  8. Offline

    thescreem

    Just take your onCommand method and put it into your main class.
     
  9. Offline

    Okapi

    add this to your main class
    Code:
    public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args){
        if(cmd.getName().equalsIgnoreCase("SomeCommandHere")){
            //doshit
        }
    }
     
  10. Offline

    Axalto

    Tryed it, but it did not work. I get no compiler errors but when I type in the commend it says unknown command.

    [edit] I added the following code to plugin.yml but I now get another error (it says it cannot let me access the command, OH GOD I MADE IT CRY, I AM A MONSTER)
    Code:
       ping:
          description: A command for players to make the server send a pong message back to the client.
          permission: <plugin name>.ping
          usage: /<command> [player]
    help? Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 8, 2016
  11. Offline

    Don Redhorse

    there is a very good wiki article about this... don't have the link atm but it is about writing your first plugin, it contains: commands, config etc... also the resource section is quite good
     
  12. Offline

    Axalto

    I found this one: http://wiki.bukkit.org/Plugin_Tutorial#The_onCommand.28.29_Method
    I tried what's written in there but I get the following message:
    "Bukkit sad. Bukkit want you to access command, but Bukkit cannot let you. Bukkit will leak tears :'("
     
  13. Offline

    Lolmewn

    Check out the HUGE PLUGIN TUTORIAL (that's the actual name) on wiki.bukkit.org
     
  14. Offline

    Taien

    What kind of permissions are you using? Sounds like its recognizing the command but you don't have permission. Or something.
     
  15. Offline

    Axalto

    I'm using none. It's a normal download of craftbukkit without any other plugins then my plugin.
     
  16. Offline

    Taien

    Are you opped?
     
  17. Offline

    Axalto

    Yes.
    [edit]
    This is my current plugin.yml file:
    Code:
    name: AxaltoEssentials
    main: minecraft.axalto.essentials.main.EssentialsMain
    version: 1.0
    description: >
                 Axalto's Essential Pack
    commands:
       pingserv:
          description: A command for players to make the server send a pong message back to the client.
          permission: <plugin name>.ping
          usage: /<command>
    permissions:
        <plugin name>.*:
            description: Gives access to all <plugin name> commands
            children:
                <plugin name>.pingserv: true
        <plugin name>.pingserv:
            description: Allows you to send the pingserv command to the server.
            default: not op
    [edit2]
    Found it, permission: <plugin name>.ping should be permission: <plugin name>.pingserv
    that fixed it
    [edit3]
    In the tutorial it does not add the permissions data in the command part yet, but this seems to be required for it to work.
     
  18. Offline

    Don Redhorse

    yes I think that was introduced in 1185 and hasn't found a way into the wiki yet.. glad you figured it out nevertheless
     
  19. Offline

    Zaros

Thread Status:
Not open for further replies.

Share This Page