[Help] onCommand question

Discussion in 'Plugin Development' started by Bakuhatsu, Mar 26, 2011.

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

    Bakuhatsu

    I'm kinda new with making plugins and kinda trying to update one using the old PLAYER_COMMAND function, I've gotten as far as understood that it's gone and replaced with onCommand.

    However, the issue is that I kinda have no idea on how I can, if it's even possible, make an onCommand working the same way as this code line:

    Code:
    pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
    Aka, any command I do being processed to the playerListener file where all code that should handle and read commands is.. >.>
     
  2. Offline

    Edward Hand

    If you have some real reason to do so, use PLAYER_COMMAND_PREPROCESS
    (but using the new onCommand function is the advised way to do it)
     
  3. Offline

    Lolmewn

    It works a bit different now.
    It's a boolean, like this:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
    String cmdName = cmd.getName();
    if (cmdName.equalsIgnoreCase("test")) {
    Player player = ((Player)sender);
    player.sendMessage("TEST!");
    return true;
    }
    }
    Then, you need to add a plugin.yml, including this:
    Code:
    name: PLUGIN NAME
    main: THA PACKAGE
    version: 1.0
    author: YOUR NAME
    description: What the plugin does
    commands:
      test:
        description: returns a test!
        usage: /<command>
    
    usage: /<command> will result in if a player types /test, TEST will be returned.
     
  4. Offline

    Bakuhatsu

    That is as far as I've understood, the issue is that I can't figure out if it's possible to just simply make the command "transfer" to playerListener file as how it used to be before with the old command.
     
  5. Offline

    niccholaspage

    Easy.
    In player listener
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
    //Code to do
    }
    In your main plugin class file (I don't know what to call it) put this in:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
    playerListener.onCommand(sender, cmd, cmdLabel, args);
    }
     
  6. Offline

    itsatacoshop247

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
            String cmdName = cmd.getName();
            if (cmdName.equalsIgnoreCase("blackjack")) {
            Player player = ((Player)sender);
            player.sendMessage(ChatColor.YELLOW +"Blackjack test!");
            return true;
            }
           //it tells me to add a "return false;" here or else i get errors.
        }
    My YML:
    Code:
    name: Blackjack
    main: me.itsatacoshop247.Blackjack.Blackjack
    version: 1
    author: itsatacoshop247
    description: Lets players play blackjack
    commands:
       blackjack:
            description: starts the game of blackjack
            usage: /<command>
    
    It doesn't work with or without the added return statement. Whenever I type /blackjack, it just returns /blackjack in white in the chat. I finished the rest of this blackjack Plugin, I just need to make the commands work.
     
  7. Offline

    Intelli

    Commands are broken with the latest dev builds of bukkit (yay!)
    Use the (outdated) recommended build until it's fixed. If it gets fixed. No one else seems to recognize this issue. =[
     
Thread Status:
Not open for further replies.

Share This Page