Solved Commands not working ??!

Discussion in 'Plugin Development' started by Adriani6, May 6, 2014.

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

    Adriani6

    So, I have a simple class with a command which then returns a message to the sender and it doesn't do anything ?
    I have registered the command in plugin.yml and my class does extend CommandExecutor.

    For a test, I have used code from my previous project and it worked, but when I edited the method just to return a message instead of spawning items (or whatever the code was doing before) and it doesn't work..

    Code:java
    1. public class Main extends JavaPlugin implements CommandExecutor{
    2.  
    3.  
    4. public void OnEnable()
    5. {
    6. getLogger().info("OnEnable has been invoked!");
    7.  
    8. }
    9.  
    10.  
    11. @Override
    12. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    13. if (cmd.getName().equalsIgnoreCase("adrian")) {
    14. sender.sendMessage("Test");
    15. return true;
    16. }
    17. return false;
    18. }
    19.  
    20.  
    21.  
    22. }


    and my plugin.yml

    Code:
    name: Adrian
    main: adriani6.project.Main
    version: 1.0
    commands:
      adrian:
          description: This is a demo command.
          usage: /<command>
          permission: <plugin name>.basic
          permission-message: You don't have <permission>
    I also do not get anything in the console, no errors, nothing.
     
  2. Does another plugin register the command first? Also, your main class does not need to implement CommandExecutor
     
  3. Offline

    Adriani6

    No. I actually have only this plugin on the server. I know that, I am just trying everything, it's been a couple of days that I was trying to figure out the problem. I have also tried another machine (IDE + Server), and still no luck.
     
  4. Adriani6 Are you sure that <plugin name>.basic is right? Personally, I've never seen it done like that before. Also, do you get any errors on startup, and does anything at all display when you do the command? How about if you change return true to return false, does the usage display?
     
  5. Offline

    1Rogue

    Code:
          permission: <plugin name>.basic
    This isn't correct. If anything, possibly <pluginname> or <name>, but I wouldn't use either one for that, just use your actual plugin name.
     
    joethebowl likes this.
  6. Offline

    Adriani6

    Usage is displayed no matter what, and plugin.yml is just an example, which worked for me before like this.
    When server loads I get no errors, the plugin loads successfully, when I execute the command I get nothing, no errors, just a returned usage... I have tried running the plugin on 1.7.9 server and 1.7.2, it doesn't work on either.

    Changed it, still nothing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  7. Adriani6 If the usage is always displayed then the return true never happens. Check before the if statement - put in something to print to the console to make sure that the onCommand() method is actually called.
     
  8. Offline

    Adriani6

    Still nothing...

    Code:
    [14:14:25] [Server thread/INFO]: Starting minecraft server version 1.7.9
    [14:14:25] [Server thread/INFO]: Loading properties
    [14:14:25] [Server thread/INFO]: Default game type: SURVIVAL
    [14:14:25] [Server thread/INFO]: Generating keypair
    [14:14:26] [Server thread/INFO]: Starting Minecraft server on *:25565
    [14:14:26] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.2-R0.3-30-ge027d69-b3058jnks (MC: 1.7.9) (Implementing API version 1.7.9-R0.1-SNAPSHOT)
    [14:14:26] [Server thread/INFO]: [Adrian] Loading Adrian v1.0
    [14:14:26] [Server thread/INFO]: Preparing level "world"
    [14:14:26] [Server thread/INFO]: Preparing start region for level 0 (Seed: -2207734904412107946)
    [14:14:27] [Server thread/INFO]: Preparing spawn area: 68%
    [14:14:27] [Server thread/INFO]: Preparing start region for level 1 (Seed: -2207734904412107946)
    [14:14:28] [Server thread/INFO]: Preparing start region for level 2 (Seed: -2207734904412107946)
    [14:14:28] [Server thread/INFO]: [Adrian] Enabling Adrian v1.0
    [14:14:28] [Server thread/INFO]: [Adrian] [MysteryBox] Enabled !
    [14:14:28] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [14:14:28] [Server thread/INFO]: Done (2,301s)! For help, type "help" or "?"
    [14:14:42] [Server thread/INFO]: /adrian
    
    Changing return true this time actually stopped printing usage, now shows the command I executed (Which is supposed to do (I guess))
     
  9. Offline

    1Rogue

    Well of course it did, you're just changing whether or not the plugin returns a certain value. We already know which point it was returning from, changing that value won't do anything towards fixing the problem.

    Print the following things to the console when you run your command:

    • cmd.getName()
    • label
    • sender.getName()
     
  10. Offline

    Adriani6

    I've done what you've told me, still nothing comes up.
     
  11. Offline

    1Rogue


    What was the console output?
     
  12. Offline

    Adriani6

    1Rogue

    Just like before:

    Code:
    [15:15:23] [Server thread/INFO]: [Adrian] Disabling Adrian v1.0
    [15:15:23] [Server thread/INFO]: [Adrian] Loading Adrian v1.0
    [15:15:23] [Server thread/INFO]: [Adrian] Enabling Adrian v1.0
    [15:15:23] [Server thread/INFO]: [Adrian] Enabled !
    [15:15:23] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [15:15:23] [Server thread/INFO]: CONSOLE: Reload complete.
    [15:15:24] [Server thread/INFO]: /adrian
     
  13. Offline

    1Rogue


    ...so then you didn't do what I stated.
     
  14. Offline

    Adriani6

    My code:

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3.  
    4. if (cmd.getName().equalsIgnoreCase("adrian")) {
    5.  
    6. getLogger().info(cmd.getName());
    7. getLogger().info(label);
    8. getLogger().info(sender.getName());
    9.  
    10. }
    11. return true;
    12. }


    I did try printing 1 line at a time,.
     
  15. Adriani6 Put those outside all if statements. That kinda defeats the point of debugging, especially since we established earlier that part is never reached.
     
    Adriani6 likes this.
  16. Offline

    kakaruso

    Lets show you how to do this:

    Code:java
    1. public class Main extends JavaPlugin{ // no commandexecutor needed is you main class due you use extends JavaPlugin and for that read the commands from here.
    2.  
    3. public void OnEnable()
    4. {
    5. getLogger().info("OnEnable has been invoked!");
    6.  
    7. }
    8. public void OnDisable()
    9. {
    10. getLogger().info("OnDisable has been invoked!");
    11.  
    12. }
    13.  
    14. @Override
    15. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    16. if (cmd.getName().equalsIgnoreCase("adrian")) {
    17. if(sender.hasPermission("write here you permission node")){ // I prefer use permissions inside class.
    18. sender.sendMessage("Test");
    19. return true;
    20. }
    21. }
    22. return false;
    23. }
    24. }
    25.  



    Plugin.yml:

    Code:
    name: Adrian
    main: adriani6.project.Main // check your package if is right
    version: '1.0'
    authors: [Adriani6]
    commands:
        adrian:
            usage: /adrian
            description: say hello.
     
  17. Offline

    KillerOfPie

    I check for permissoin in the plugin using
    Code:java
    1. if(sender.hasPermission("Perm.name.here"))


    and i add perms using
    Code:java
    1. public Permission perm = new Permission("Perm.name.here");


    Try doing that instead of putting the perms in the plugin.yml
     
  18. Offline

    Adriani6

    AdamQpzm
    Still, same output in console..
     
  19. kakaruso Other than removing the needless implementing of CommandExecutor that he was already told about and shouldn't affect his problem, accidentally commenting out a vital piece of syntax, adding in an additional redundant print to the console, and adding a permissions check which you admit to being personal preference and not even relevant to his problem in this case... what exactly does your code do to help or even change what he already has?

    As it is, you shouldn't just post a piece of code that you say will work with no explanation on what you've changed, why, or what he was doing wrong.

    Adriani6 Show current code please?
     
  20. Offline

    kakaruso

    KillerOfPie Using only:
    Code:java
    1. if(sender.hasPermission("Perm.name.here"))


    and then given the permission to the player should be ok.
     
  21. Offline

    Adriani6

    kakaruso
    I know how to do it, I have a problem with returning a message, when I create a new project, I tried using code from previous projects as well it worked until I remove everything and leave just a message to print, then it suddenly stops working.

    Broadcasting, Logging to Console, sending to sender does not work.

    KillerOfPie
    It's not a permissions problem.
     
  22. Offline

    kakaruso

    that code is simple, there are no possible fail doing that Adam is a simple command i dont know what's the problem then....
     
  23. Offline

    Adriani6

    AdamQpzm

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. getLogger().info(cmd.getName());
    3. getLogger().info(label);
    4. getLogger().info(sender.getName());
    5. /*if (cmd.getName().equalsIgnoreCase("adrian")) {
    6.  
    7.  
    8.   getLogger().info(label);
    9.   getLogger().info(sender.getName());
    10.  
    11.   }*/
    12. return true;
    13. }
     
  24. kakaruso Actually a direct copy of the code you originally posted had no possible way of working ;) And every suggestion you made had no possible way of solving the problem, so it wasn't helpful. Either you knew it wouldn't solve it or you didn't. If you did know it wouldn't solve it, why did you bother suggesting that? If you didn't know that, you should use phrases that are more like "I'm not sure if this will affect it, but you can try this" rather than "Let's show you how to do this". The difference in tone matters.

    Adriani6 In that case, it would suggest that the onCommand() is never actually executed. Unless there's something which can mess up the logger that's returned by getLogger(), which I've never heard of before but I guess is technically possible. It might not help, but why not try chaging getLogger().info to System.out.println? (kakaruso See what I did there? :p)
     
    Adriani6 likes this.
  25. Offline

    kakaruso

    im testing the code that i posted and i get the message in both console and ingame

    I apologize if it seemed offensive but English is not my native language and I did not want to offend anyone
     
  26. Offline

    Adriani6

    Just tried System.out.println and still doesn't work. This is extremely irritating.
     
  27. kakaruso I would imagine, though, that you get the same result if you test his code.

    Adriani6 Then I only have two things that I can think of: Either you're using an old version of the file (which is actually surprisingly easy to do by mistake) or it's not compiling correctly.
     
    Adriani6 likes this.
  28. Offline

    Adriani6

    I have found the problem. I was using a craftbukkit build which seems to be broken, just downgraded to 1.7.2 from craftbukkit-1.7.9-R0.1 and exported the project again and it worked.

    Thanks for all the input :)
     
    AdamQpzm likes this.
  29. Offline

    kakaruso

    I apologize again if Adam felt offended, and I was going crazy, because I was testing it and everything worked me correctly, I created a project is just to make sure.
     
    Adriani6 likes this.
  30. Offline

    Adriani6

    It's okay, no worried, I am not offended nor is Adam probably, no hard feelings ;)
     
Thread Status:
Not open for further replies.

Share This Page