onCommand not intiliazing

Discussion in 'Plugin Development' started by Monckey100, Dec 7, 2013.

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

    Monckey100

    Well as title says, I removed my code completely and turns out it's not even running my commands. on the server it just shows "/runaway" so basically the usage: in the plugin.yml

    here's what I got (I didn't put the imports to keep this small):
    Code:java
    1.  
    2. public final class runaway extends JavaPlugin {
    3. @Override
    4. public void onEnable(){
    5. PluginManager serversets = getServer().getPluginManager();
    6. playerListener = new PlayerListeners(this);
    7. serversets.registerEvents(this.playerListener, this);
    8. // TODO Insert logic to be performed when the plugin is enabled
    9. }
    10.  
    11. public boolean onCommand(Command sender, Command cmd, String label, String[] args){
    12. getLogger().info("Command sent!");
    13. if(cmd.getName().equalsIgnoreCase("runaway")){ // If the player typed /basic then do the following...
    14. Player player = (Player) sender;
    15. player.sendMessage("Pass!");
    16. getLogger().info(" command works..kind of");
    17. return true;
    18. } //If this has happened the function will return true.
    19. return false;
    20. }
    21. //public final PlayerListeners playerListener = new PlayerListeners();
    22. public PlayerListeners playerListener ;
    23.  
    24. }


    Plugin.yml
    Code:java
    1.  
    2. name: runaway
    3. main: pack.runaway.runaway
    4. version: 1.0
    5. commands:
    6. runaway:
    7. description: A simple mod that increases your running speed
    8. usage: /<command> [player]
    9. permission: <plugin name>.runaway
    10. permission-message: You don't have <permission>
    11.  


    My playerlisteners are working fine but this just isn't working properly
     
  2. Offline

    The_Doctor_123

    onCommand() doesn't get called at all? Possibly change
    Code:java
    1. permission: <plugin name>.runaway

    to
    Code:java
    1. permission: runaway.runaway
     
  3. Offline

    mydeblob

    Monckey100
    I'm assuming you have correct spacing in your plugin.yml, correct?
    Second register your command, put this in your onEnable
    Code:
    getCommand("runaway").setExecutor(this);
     
  4. Offline

    The_Doctor_123

    That code is pointless. By default, commands are executed in the main class.
     
    samosaara likes this.
  5. Offline

    mydeblob

    The_Doctor_123
    Never knew that, I always had done that. Guess you learn something new everyday.
     
  6. Offline

    The_Doctor_123

    mydeblob
    Yes, JavaPlugin actually implements CommandExecutor(far down the line).
     
  7. Offline

    Monckey100

    @mydeblob

    @The_Doctor_123
    I tried both getCommand AND the plugin.yml rename, to no avail, still gives me the prompt usage and on the console side it's saying "Monckey100 issued server command: /runaway"

    Edit: there is no other plugins besides this one btw.
     
  8. Offline

    The_Doctor_123

    Monckey100
    You may want to take a closer look at this line.
    Code:java
    1. public boolean onCommand(Command sender, Command cmd, String label, String[] args){
     
  9. Offline

    PolarCraft

    Monckey100 Um...
    Code:java
    1. getLogger().info("Command sent!");

    Is not supposed to be there.
    Do:
    Code:java
    1. Player.sendmessage("Command Sent!");


    And:
    Code:java
    1. Player player = (Player) sender;

    is supposed to be above the command.

    What is this for:
    Code:java
    1. playerListener =new PlayerListeners(this);


    Also change your onCommand line to:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)


    [Edit] Sniped by The_Doctor_123
     
  10. Offline

    Wolfey

    I loled so hard.
    Code:java
    1.  
    2. public boolean onCommand(Command sender, Command cmd, String label, String[] args){
    3.  
     
  11. Offline

    The_Doctor_123

    PolarCraft
    I kinda don't understand what you're trying to say in the first four code snippets.. All the code he has(besides that one line) looks fine to me.
     
  12. Offline

    PolarCraft

    Wolfey As well did I :D. Old way of writing it.
    The_Doctor_123 If you are going to send "command sent!" the current way would send it to console -_- And usually you put the Player import above the command. Just to keep the import from being out of a method.
     
  13. Offline

    Monckey100

    That last line did the trick, super thanks!
    CommandSender hurr. I was using the wikis onCommand and I guess I clipped it by accident

    Edit: also I was debugging, all of that stuff was me being desperate
     
  14. Offline

    The_Doctor_123

    PolarCraft
    I print to the console like half the time when debugging.
     
  15. Offline

    PolarCraft

  16. Offline

    The_Doctor_123

    PolarCraft
    Code:java
    1. getLogger().info("Command sent!");
    2. if(cmd.getName().equalsIgnoreCase("runaway")){ // If the player typed /basic then do the following...
    3. Player player = (Player) sender;
    4. player.sendMessage("Pass!");
    5. getLogger().info(" command works..kind of");

    Damn, if that's his idea of a useful command..
     
  17. Offline

    PolarCraft

    The_Doctor_123 Hmm... And he said he was debugging it after i posted -_- Monckey100 What is the purpose of this plugin??
     
  18. Offline

    The_Doctor_123

    PolarCraft
    I'm sure he's just making sure everything is in order before he moves on with the real junk.
     
  19. Offline

    PolarCraft

  20. Offline

    Monckey100

    wasn't trying to make anythign super useful, I haven't developed plugins for minecraft since...well around a couple of months after bukkit started to become stable and usable back in minecraft beta...so I needed the practice
     
Thread Status:
Not open for further replies.

Share This Page