Command and "sub" command ?

Discussion in 'Plugin Development' started by Ancetras, Apr 8, 2011.

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

    Ancetras

    I'm trying to create a command which should work like this:

    /sw help - shows the list of all "sw" command
    /sw name - shows the message "name"
    /sw info - shows the message "info"

    But it doesn't work!
    What am I doing wrong? T_T

    Code:
               public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
                    String[] split = args;
                    String commandName = command.getName().toLowerCase();
                        if (sender instanceof Player) {
                            Player p = (Player) sender;
                            if (commandName.equalsIgnoreCase("/sw") && p.isOp()) {
                                if ((split.length > 0) && (split[0].equalsIgnoreCase("help"))) {
                                    p.sendMessage(ChatColor.GOLD + "iSM Help Page");
                                    p.sendMessage(ChatColor.YELLOW + "----------------------------");
                                    p.sendMessage(ChatColor.GREEN + "/sm help - Show this list.");
                                    p.sendMessage(ChatColor.GREEN + "/sm name - Show message Name");
                                    p.sendMessage(ChatColor.GREEN + "/sm info - Show message Info");
                                }else if ((split.length > 0) && (split[0].equalsIgnoreCase("info"))){
                                    p.sendMessage(ChatColor.GOLD + "Info");
                                }else if ((split.length > 0) && (split[0].equalsIgnoreCase("name"))){
                                    p.sendMessage(ChatColor.GOLD + "Name");
                                }
    
                                p.sendMessage(ChatColor.RED + "You don't have the permission to use it.");
                            }
    
                        }
                        return true;
                    }
     
    ne0nx3r0 likes this.
  2. Offline

    ssell

    Try this:

    Code:
    if( commandName.equalsIgnoreCase( "/sw" ) ...
    to

    Code:
    if( commandName.equalsIgnoreCase( "sw" ) ...
    and make sure the plugin.yml is set up correctly.
     
  3. Offline

    Ancetras

    >.< Uhm ... how can i set the plugim.yml?

    I can't find a guide >.<"
     
  4. Offline

    ssell

    Here is an old one from TentThis as an example:

    Code:
    name: TentThis
    main: ssell.TentThis.TentThis
    version: "2.0.0"
    author: ssell
    commands:
        ttTent:
            description: Sets the plugin to start waiting to build.
            usage: /<command>
        ttSchema:
            description: Set the tent schema to be built.
            usage: /<command>
        ttInfo:
            description: Reports the current schema.
            usage: /<command>
        ttNoCommand:
            description: Enables/Disables the need to enter /ttTent to build.
            usage: /<command>
        ttReload:
            description: Finds new CreationBlock without having to restart server.
            usage: /<command>
        ttLimit:
            description: Sets the tent limit for provided player or everyone.
            usage: /<command>
    
    You must make sure your spacing is correct or else it will fail.
    It also must be in your src folder.
     
  5. Offline

    Ancetras

    Thank you >_<
    I'm gonna try it right now!
    If there are some problems, I'll report you here.

    Eclipse shows me an error:

    T_T

    My plugin.yml is like this:

    Code:
    name: iSW
    main: iSW.Ancetras
    version: "0.1"
    author: ancetras
    commands:
        swHelp:
            description: Shows this list.
            usage: /<command>
        swName:
            description: Shows the message Name
            usage: /<command>
        swInfo:
            description: Shows the message Info
            usage: /<command>
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  6. Offline

    ssell

    @Ancetras

    In Eclipse, right-click your project and select 'Refresh' from the menu.

    Also, in the future if you do not quote me, then tag me like I do you, that way I am alerted of your post and don't reply 3 hours later :)
     
  7. Offline

    Ancetras

    °O° ooohh ...

    thank you!
    I'm new on this forum, didn't know about "quote" >_< sorry
     
Thread Status:
Not open for further replies.

Share This Page