[SOLVED] Commands problem

Discussion in 'Plugin Development' started by RTRD, Oct 7, 2011.

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

    RTRD

    Commands problem. How to fix? :)

    Plugin.yml
    Code:
    commands:
      mcdp:
        description: Standard command MCDocsPlus
        usage: /mcdp
      mcdp help:
        permission:
        description: Shows help for MCDocsPlus
        usage: /mcdp help
      mcdp version:
        permission:
        description: Shows version of MCDocsPlus
        usage: /mcdp version
        permission: mcdocsplus.
      mcdp reload:
        description: Reloads MCDocsPlus
        usage: /mcdp reload
        permission: mcdocsplus.reload
    CODE:
    Code:
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
        {
     
            Player player = (Player)sender;
            PluginDescriptionFile pdfFile = this.plugin.getDescription();
     
            if (label.equalsIgnoreCase("mcdp"))
            {
                if(args.length == 0)
                {
                    player.sendMessage(ChatColor.RED + "[MCDocs+] Try /mcdp help");
                    return true;
                }
                else if(args[0].equalsIgnoreCase("help"))
                {
                    player.sendMessage(ChatColor.RED + "[MCDocs+] Available commands:");
                    player.sendMessage(ChatColor.WHITE + "/mcdp help - Shows available commands");
                    player.sendMessage(ChatColor.WHITE + "/mcdp reload - Reloads MCDocsPlus");
                    player.sendMessage(ChatColor.WHITE + "/mcdp version - Shows current version of MCDocsPlus");
                    return true;
                }
                else if (args[0].equalsIgnoreCase("reload"))
                {
                    if(player.hasPermission("mcdocsplus.reload"))
                    {
                        loadConfig();
                        player.sendMessage("MCDocsPlus has been reloaded.");
                        return true;
                    }
                    else
                    {
                        sender.sendMessage(ChatColor.RED + "Insufficent Permissions!");
                        return true;
                    }
                }
                else if (args[0].equalsIgnoreCase("version"))
                {
                    if(player.hasPermission("mcdocsplus.info"))
                    {
                        player.sendMessage(ChatColor.RED + "[MCDocs+] v" + pdfFile.getVersion() + "by RTRD" );
                        return true;
                    }
                    else
                    {
                        sender.sendMessage(ChatColor.RED + "Insufficent Permissions!");
                        return true;
                    }
                }
            }
            return commandLogEnabled;
        }
     
  2. Offline

    Perdog

    You forgot to check if there is an arg
    Code:
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("help")) {
            // Do stuff
        }
    }
     
  3. Offline

    RTRD

    Still not working...
     
  4. Offline

    Kohle

    I am also having this problem :/
     
  5. Sigh, I hate it when people go on the forums and are like "I haz problem" but post no details about their problems whatsoever.
    Would you do that please?

    One thing that I see right away is that you cast sender immediatly to Player without ever checking whether sender IS a player.
     
  6. Offline

    RTRD

    Maybe there is something wrong with the plugin.yml? :/

    The command is not working in-game...
     
  7. Offline

    Perdog

    What's the problem that's occurring?
     
  8. Error message in console?
     
  9. Offline

    Perdog

    Ah right
    Code:
    Player player = (Player) sender;
    if (!(sender instanceof Player)) {
        return false;
    }
    // Then everything else
     
  10. That would still throw an error, because you cast it before checking it.
     
  11. Offline

    RTRD

    There is no error in console. When I do /mcdp or any sub command it sends back this:
    Code:
    /mcdp
    And that is all...
     
  12. Offline

    Perdog

    It shouldn't? That's how my plugin is set up and it works fine.
     
  13. Offline

    Kohle

    Yeah, all my commands return the command, but no errors or anything... pretty much the same thing as @RTRD
     
  14. Write your command in the console and see what happens.

    @RTRD Try removing the
    if (label.equalsIgnoreCase("mcdp"))
    check, because your plugin shouldn't execute any commands from any other plugins anyway. You should also remove the unused Permissions: from your plugin.yml

    Other than that: Your command seems to return false, so it probably doesn't reach the inner checks.
     
  15. Offline

    Perdog

    I don't know how big of an issue this is but
    Code:
    
    commands:
     mcdp:
         description: Standard command MCDocsPlus
         usage: /mcdp
       mcdp help:
         permission:
         description: Shows help for MCDocsPlus
         usage: /mcdp help
       mcdp version:
         permission:
         description: Shows version of MCDocsPlus
         usage: /mcdp version
         permission: mcdocsplus.
       mcdp reload:
         description: Reloads MCDocsPlus
         usage: /mcdp reload
         permission: mcdocsplus.reload
    should look like
    Code:
    [/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]commands:[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]   mcdp:[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     description: Standard command MCDocsPlus[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     usage: |[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]        /mcdp[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]   mcdp help:[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     permission:[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     description: Shows help for MCDocsPlus[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     usage: |[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]        /mcdp help[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]   mcdp version:[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     permission:[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     description: Shows version of MCDocsPlus[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     usage: |[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]        /mcdp version[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     permission: mcdocsplus.[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]   mcdp reload:[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     description: Reloads MCDocsPlus[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     usage: |[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]        /mcdp reload[/FONT][/FONT][/FONT][/FONT][/FONT]
    [FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia][FONT=Georgia]     permission: mcdocsplus.reload
    [/FONT][/FONT][/FONT]

    Just the usage looks wrong to me.[/code][/code][/code]


    Woowww... That got fucked up badly...[/code][/FONT]
     
  16. Offline

    RTRD

    Ok, I will try that.

    Done, already! :p

    Fix the yml? :p

    Not working...

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

    Perdog

    Yes sorry ... no idea what happened there. For your usage space it out like
    Code:
    usage: |
        /mcmd help
    It's not meant to be used from the console though. So the error is irrelevant.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  18. Other than that... try adding some debug lines to see what happens in your code.

    It's not meant to be... there are lots of things that are not meant to be. But if people do use it from the console? The plugin errors. And then they will tell you: "Your plugin is giving me errors." and your answer would just be: "It's not meant to be used from the console?"

    Please, always assume the worst case. Make your plugin as robust as possible.


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

    RTRD

    That's ging YML errors... :p


    EDIT: Nvm....
     
  20. Offline

    Perdog

    Well the plugin is LandMines, so if someone did try to use it in the console I would question there motive :p Considering you can't plant one unless your in game.
     
  21. Refer to this page for a proper plugin.yml, there also is an example at the bottom of the page. (Just note that the indents are all wrong, you need to have 4 spaces per "tab".)
     
  22. Offline

    RTRD

    Not working that either....
     
  23. Offline

    Perdog

    Hmmmm I'd say follow the link Pandemoneus gave you, seems like the last thing it could be.
     
  24. Offline

    RTRD

    Let me clearify myself:
    YML worked. The command still does not work in-game.


    BTW going to bed now. 02:35AM here! :p
     
  25. Offline

    TopGear93

    are you using RB 1240? ive had the SAME exact issue as you. remove else from else if. then your commands should work. RB 1240 messed up commands
     
  26. Offline

    Icelaunche

    well the commands work for me but the plugin doesn't (SSD) i see the SSD (enabled) and SSD (disabled) but when it should drop smooth stone it drops cobble i tried it when the plugin was disabled and enabled...
     
  27. Offline

    RTRD

    This is how it is now:

    CODE:
    Code:
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
        {
    
    
            Player player = (Player)sender;
            PluginDescriptionFile pdfFile = this.plugin.getDescription();
    
    
            if (label.equalsIgnoreCase("mcdp")){
                if(args.length == 0){
                    if(player.hasPermission("mcdocsplus.admin")) {
                        player.sendMessage(ChatColor.RED + "[MCDocs+] Try /mcdp help");
                        return true;
                    }
                }
                if (args.length == 1) {
                    if(args[0].equalsIgnoreCase("help")) {
                        if(player.hasPermission("mcdocsplus.admin")) {
                            player.sendMessage(ChatColor.RED + "[MCDocs+] Available commands:");
                            player.sendMessage(ChatColor.WHITE + "/mcdp help - Shows available commands");
                            player.sendMessage(ChatColor.WHITE + "/mcdp reload - Reloads MCDocsPlus");
                            player.sendMessage(ChatColor.WHITE + "/mcdp version - Shows current version of MCDocsPlus");
                            return true;
                        }
                    }
                }
                if (args.length == 1) {
                    if (args[0].equalsIgnoreCase("reload")) {
                        if(player.hasPermission("mcdocsplus.reload")) {
                            loadConfig();
                            player.sendMessage("MCDocsPlus has been reloaded.");
                            return true;
                        }
                        else
                        {
                            sender.sendMessage(ChatColor.RED + "Insufficent Permissions!");
                            return true;
                        }
                    }
                }
                if (args.length == 1) {
                    if (args[0].equalsIgnoreCase("version")) {
                        if(player.hasPermission("mcdocsplus.admin")) {
                            player.sendMessage(ChatColor.RED + "[MCDocs+] v" + pdfFile.getVersion() + "by RTRD" );
                            return true;
                        }
                        else
                        {
                            sender.sendMessage(ChatColor.RED + "Insufficent Permissions!");
                            return true;
                        }
                    }
                }
            }
            return commandLogEnabled;
        }
    PLUGIN.YML:
    Code:
    name: MCDocsPlus
    main: no.rtrd.bukkit.mcdocsplus.Main
    version: 1.1.2
    description: A continuation of MCDocs
    author: RTRD
    website: http://wiki.rtrd.no/index.php?title=MCDocsPlus
    commands:
      mcdp:
        description: Standard command MCDocsPlus
        usage: |
          /mcdp
      mcdp help:
        description: Shows help for MCDocsPlus
        usage: |
          /mcmd help
      mcdp version:
        description: Shows version of MCDocsPlus
        usage: |
          /mcdp version
        permission: mcdocsplus.reload
      mcdp reload:
        description: Reloads MCDocsPlus
        usage: |
          /mcdp reload
        permission: mcdocsplus.reload
    permissions:
      mcdocsplus.*:
        description: Gives access to all MCDocsPlus commands
        children:
          mcdocsplus.reload: true
          mcdocsplus.motd: true
          mcdocsplus.admin: true
          mcdocsplus.read.*: true
      mcdocsplus.admin:
        description: Gives access to all the admin commands
        children:
          mcdocsplus.reload: true
      mcdocsplus.reload:
        description: Reloads MCDocsPlus
      mcdocsplus.motd:
        description: Shows the motd on login
        default: true
      mcdocsplus.read:
        description: The following node must be used to allow player access to the specified TXT file
        default: true
     
  28. Offline

    stelar7

    this coding is quite retarded...

    Du har mye unøvdendig kode, og plugin.yml er unødvendig lang...
     
  29. Offline

    RTRD

    Og det der skulle liksom hjelpe meg?
    ---------
    And that was supposed to help me?
     
  30. Offline

    stelar7

    Ja :p
    ----
    Yes :D
     
Thread Status:
Not open for further replies.

Share This Page