"onPlayerCommand" Not Working

Discussion in 'Plugin Development' started by RLS0812, Feb 21, 2012.

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

    RLS0812

    I have no clue were I messed this up. OnPlayerCommand will not work at all.
    YML
    Code:
    name: Gifter
    version: .00000001
    main: me.RLS0812.Gifter.Main
    commands:
      gift:
          description: ""
          usage:""
          permission: ""
          permisison-message: ""
    
    Main
    Code:
    package me.RLS0812.Gifter;
     
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
        public void onEnable(){
            PluginManager manager = this.getServer().getPluginManager();
            manager.registerEvents(new P_Commands(),this);
     
     
        }
        public void onDisable(){
            }}
    
    Commands
    Code:
    package me.RLS0812.Gifter;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
     
    public class P_Commands implements Listener {
     
    public void onPlayerCommand(CommandSender sender, Command cmd, String label, String[] args) {
    //Test Message
    Bukkit.getServer().broadcastMessage("I work ! " + args[0]);
    }}
    
     
  2. Offline

    Firefly

    Why are you using onPlayerCommand and not onCommand() ?
     
  3. Offline

    RLS0812

    Doesn't matter, "onCommand()" fails also
     
  4. Offline

    dillyg10

    Not sure this will help, but try adding an @Override
     
  5. Offline

    RLS0812

    syntax error
     
  6. Offline

    Firefly

    It shouldn't.

    PHP:
    public boolean onCommand(CommandSender senderCommand cmdString labelString[] args) {
     
      
    //Test Message
     
      
    Bukkit.getServer().broadcastMessage("I work ! " args[0]);
     
      return 
    true;
     
    }
     
  7. Offline

    nisovin

  8. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı Retired Staff

    It's onCommand, and it needs to be in a CommandExecutor (JavaPlugin is one, so your main class works) and if not in the main class it needs to be registered per command via getCommand(String).setExecutor(CommandExecutor);

    And the method is onCommand
     
  9. Offline

    RLS0812

    It works now, though I do not quite understand why. Fixed code:
    Code:
    name: Gifter
    version: .00000001
    main: me.RLS0812.Gifter.Main
    commands:
      gift:
          description: ""
          usage: /gift
          
    Code:
    package me.RLS0812.Gifter;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
        public void onEnable(){}
        public void onDisable(){}
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            //Test Message
            Bukkit.getServer().broadcastMessage("I work ! " + args[0]);
            return true;
          }
     
  10. Offline

    Jaker232

    Nothing in Enable and Disable.
     
  11. Offline

    RLS0812

    Enable and Disable are for OCD folks, if the plugin doesn't load or unload data.

    I literally have yet to find a good use for them outside of data management.
     
Thread Status:
Not open for further replies.

Share This Page