onCommand Help needed...

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

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

    Zero9195

    Hey Guys, me again
    I'm still updating my plugin and i don't know how to use the new onCommand, and can't find a tutorial or something that would help me, so can someone please give me a short example of how to use it? Would be great!
    Thanks for helping
    Zero
     
  2. Offline

    darknesschaos

    the old one works just fine.
     
  3. Offline

    Zero9195

    For me it doesn't work with my old commands, so i need to upadte it to the newer one.
     
  4. Offline

    darknesschaos

    mind if I see some code? I could help more with the older one, I haven't touched the newer one yet.
     
  5. Offline

    Zero9195

    Sure, here is some code:
    Code:
    public void onPlayerCommand(PlayerChatEvent event)
        {
            String[] split = event.getMessage().split(" ");
            Player player = event.getPlayer( );
            if ((split[0].equalsIgnoreCase("/JMod") || split[0].equalsIgnoreCase("/j")))
            {
                if ((split[1].equalsIgnoreCase("tower1") || split[1].equalsIgnoreCase("t1")))
                {
                    if(plugin.buildings == true)
                    {
                        plugin.toogleTower1(player);
                        event.setCancelled(true);
                    }
                    else if (plugin.buildings == false)
                    {
                        player.sendMessage("Buildings are disabled");
                    }
                }
    This is in my PlayerLsitener. The Event I registered doesnt exist anymore, so this wouldn't help^^
     
  6. Offline

    darknesschaos

    the / is omitted automatically, and onplayercommand goes straight into your main plugin class

    oh, and playerchatevent is quite old.
    Edit: use this

    public boolean onCommand(Player player, Command command, String commandLabel, String[] args){
    return true;
    }

    I actually advise looking at some plugins sources and ymls as the plugins have changed a lot since onplayercommand

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  7. Offline

    Zero9195

    Does not work. Sorry. Which event do I have to register?

    Oh okay, i will take a look in some Code now. Thanks for Your help!

    Works perfect now! Just had to change "onPlayerCommand" to "onPlayerCommandPreprocess". Too easy to see ;)

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

    darknesschaos

    you shouldn't use that.
     
Thread Status:
Not open for further replies.

Share This Page