onCommand not working

Discussion in 'Plugin Development' started by Fifteen, Feb 3, 2011.

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

    Fifteen

    onCommand doesn't work for me. No exception. No sign that it is even called. Nothing.

    Code:
    public void onEnable()
        {
            log.info(pdfFile.getName() + " enabled.");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_INTERACT, blockListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
            try
            {
                ...
            }
            catch (Exception ex)
            {
                
            }
        }
    
    Code:
    public void onCommand(PlayerChatEvent event)
    {
            Player p = event.getPlayer();
            String[] m = event.getMessage().split(" ");
             if (m[0].equalsIgnoreCase("/chest"))
             {
                   try
                   {
                       if (Locked.oo && !p.isOp() && !Locked.ano.contains(p.getName()))
                           return;
                       if (m[1].equalsIgnoreCase("lock"))
                       {
                           ...
                       }
                       else if (m[1].equalsIgnoreCase("unlock"))
                       {
                           ...
                       }
                       else
                       {
                           ...
                       }
                   }
                   catch (Exception ex)
                   {
                       
                   }
              }
        }
    
    Help please? [​IMG]

    Full source at: https://github.com/Fifteen/Locked
     
  2. Offline

    Shade

    Use onPlayerCommand.
     
  3. Offline

    Fifteen

    Thanks, that worked :D
    --- merged: Feb 3, 2011 10:35 PM ---
    Oh, and is there a list of correct methods? I believe I'm having the same problem with BlockDamageEvent...
     
  4. Offline

    Shade

  5. Offline

    Fifteen

    Thanks, I didn't find it in the javadocs :p
     
  6. Offline

    darknesschaos

    check out my picasso code, onCommand goes in the main class and it is not a playerChatEvent, it has different arguments.
     
  7. Offline

    Dinnerbone Bukkit Team Member

    Do not use onPlayerCommand. Use onCommand. Were you registering it in plugin.yml?
     
  8. Offline

    Plague

    Is this going to be phased out? Because it warks at the time and I'm lazy ;)
    I do read changes in the release system, but no hint there.
     
  9. Offline

    Dinnerbone Bukkit Team Member

    Not properly, because it does has its uses. But:
    - Other plugins will be able to register your command, and yours will stop working
    - Your commands are limited to chat, and not from other sources (console, IRC, other plugins)
    - Won't show up in any /help
    - Won't be visible at all to other plugins, or our online command database
    etc
     
  10. Offline

    Mhalkyer

    I had the exact same problem because I didn't register the command in the plugin.yml.
     
Thread Status:
Not open for further replies.

Share This Page