Solved Command help

Discussion in 'Plugin Development' started by ArthurHoeke, Oct 30, 2013.

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

    ArthurHoeke

    Hello!
    I made that if you type /themagegames
    But how to make that you can do the command
    /themagegames setup
    ?
     
  2. Offline

    scarletomato

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
        if(commandLabel.equals("themagegames") && args.length > 0 && args[0].equals( "setup")){
              //do something
        }
     
  3. Offline

    CodingEyes

    You would do this:

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if (sender instanceof Player) {
    3. }
    4. if (cmd.getName().equalsIgnoreCase("themagegames")) {
    5. if (args.length == 1) {
    6. if (args[0].equalsIgnoreCase("setup")){
    7. //Do something when /themagegames setup is typed.
    8. return true;
    9. }
    10. }
    11. }
    12. return false;
    13. }


    args.length == 1 This means that if there is 1 argument after your original command,
    /themagegames (Original command) setup (argument)

    args[0].equalsIgnoreCase("setup") This means that if takes the argument after the command (args[0]) and checks if it is ''setup''

    Hope I helped :)
     
  4. Offline

    DenialMC

    The proper way to handle this is:

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
    2. if (cmdLabel.equalsIgnoreCase("themagegames")) {
    3. if (args.length == 0) {
    4. // handle /themagegames command
    5. } else if (args[0].equalsIgnoreCase("setup")) {
    6. // handle /themagegames setup command
    7. } else {
    8. // handle /themagegames command
    9. }
    10. }
    11. return true;
    12. }
    13.  


    Daniel
     
  5. Offline

    ArthurHoeke

    I got this
    Code:
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
          if(cmd.getName().equalsIgnoreCase("themagegames")) {
              sender.sendMessage(ChatColor.GOLD + "o0--------------------TheMageGames-----------------o0");
              sender.sendMessage(ChatColor.GREEN + "/TheMageGames " + ChatColor.GOLD + "Shows this screen" );
              sender.sendMessage(ChatColor.GREEN + "/TheMageGames help " + ChatColor.GOLD + "Shows this screen" );
              sender.sendMessage(ChatColor.GREEN + "/TheMageGames arenasetup " + ChatColor.GOLD + "Arena setup");
              sender.sendMessage(ChatColor.GREEN + "/TheMageGames signsetup " + ChatColor.GOLD + "Sign Setup");
              sender.sendMessage(ChatColor.GOLD + "o0-------------------------------------------------o0");
          }
        return false;
      }
          public boolean onCommand2(CommandSender sender, Command cmd, String commandLabel, String[] args){
                if(commandLabel.equals("themagegames") && args.length > 0 && args[0].equals( "setup")){
                      sender.sendMessage(ChatColor.GREEN + "/TheMageGames signsetup " + ChatColor.GOLD + "Sign Setup");
                }
        return false; 
      }
    }
    
    But it dont works..
    In the plugin.yml i put the command setup:
     
  6. Offline

    Ripp3rZ

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("themagegames")) {
    3. if(args.length > 0) {
    4. if(args[0].equalsIgnoreCase("setup")) {
    5. sender.sendMessage("§2Yeah, u did it!");
    6. return true;
    7. } // here you can add other args if you not only want setup
    8. // do it like this:
    9. // else if(args[0].equalsIgnoreCase("join") {
    10. // //your code
    11. // }
    12. sender.sendMessage("§4:o I don't know this argument, do you ?");
    13. return true;
    14. }
    15. sender.sendMessag("§4Please, not that many arguments..");
    16. return true;
    17. }
    18. sender.sendMessage("§4Hey Dude, sth went wrong!");
    19. return true;
    20. }
     
  7. Offline

    ArthurHoeke

    DenialMC Also dont works!
    This is the code i got now
    Code:
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
          if(cmd.getName().equalsIgnoreCase("themagegames")) {
              sender.sendMessage(ChatColor.GOLD + "o0--------------------TheMageGames-----------------o0");
              sender.sendMessage(ChatColor.GREEN + "/TheMageGames " + ChatColor.GOLD + "Shows this screen" );
              sender.sendMessage(ChatColor.GREEN + "/TheMageGames help " + ChatColor.GOLD + "Shows this screen" );
              sender.sendMessage(ChatColor.GREEN + "/TheMageGames arenasetup " + ChatColor.GOLD + "Arena setup");
              sender.sendMessage(ChatColor.GREEN + "/TheMageGames signsetup " + ChatColor.GOLD + "Sign Setup");
              sender.sendMessage(ChatColor.GOLD + "o0-------------------------------------------------o0");     
              if (args.length == 1 && args.equals("setup")) {
                  sender.sendMessage(ChatColor.GREEN + "/TheMageGames arenasetup " + ChatColor.GOLD + "Arena setup");
                return true;
              }
          }
        return false;
      }
    }
     
  8. Offline

    The_Coder

    ArthurHoeke
    You only use one onCommand(). Next your yml is wrong you put in the command setup which is not a command it is a command args. Start with learning java and the bukkit api here: http://wiki.bukkit.org/Plugin_Tutorial. Get a handle on that first. Sorry if I sound mean here but these are the basics of plugin development.

    More links:
    Great tutorials on bukkit
    Great java tutorials
     
  9. Offline

    ArthurHoeke

    I already installed eclipse -,-
    But how to fix this.....
     
  10. Offline

    Fred12i12i

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("themagegames")) {
    3. if(args.length == 0){
    4. sender.sendMessage(ChatColor.GOLD + "o0--------------------TheMageGames-----------------o0");
    5. sender.sendMessage(ChatColor.GREEN + "/TheMageGames " + ChatColor.GOLD + "Shows this screen" );
    6. sender.sendMessage(ChatColor.GREEN + "/TheMageGames help " + ChatColor.GOLD + "Shows this screen" );
    7. sender.sendMessage(ChatColor.GREEN + "/TheMageGames arenasetup " + ChatColor.GOLD + "Arena setup");
    8. sender.sendMessage(ChatColor.GREEN + "/TheMageGames signsetup " + ChatColor.GOLD + "Sign Setup");
    9. sender.sendMessage(ChatColor.GOLD + "o0-------------------------------------------------o0");
    10. }
    11. return true;
    12. }
    13. if(args.length == 1){
    14. if(args[0].equalsIgnoreCase("setup")){
    15. if(commandLabel.equals("themagegames") && args.length > 0 && args[0].equals( "setup")){
    16. sender.sendMessage(ChatColor.GREEN + "/TheMageGames signsetup " + ChatColor.GOLD + "Sign Setup");
    17. }
    18. }
    19. }
    20. }
    21. }
     
  11. Offline

    The_Coder

    ArthurHoeke
    If you go to those people's channels you will find all of their video on this stuff. Not just installing the ide.
     
  12. Offline

    Fred12i12i

  13. Offline

    ArthurHoeke

    Fred12i12i No ;(

    :( Help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  14. Offline

    Fred12i12i

    ArthurHoeke i have tested this and it should work
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("themagegames")) {
    3. if(args.length == 0){
    4. sender.sendMessage(ChatColor.GOLD + "o0--------------------TheMageGames-----------------o0");
    5. sender.sendMessage(ChatColor.GREEN + "/TheMageGames " + ChatColor.GOLD + "Shows this screen" );
    6. sender.sendMessage(ChatColor.GREEN + "/TheMageGames help " + ChatColor.GOLD + "Shows this screen" );
    7. sender.sendMessage(ChatColor.GREEN + "/TheMageGames arenasetup " + ChatColor.GOLD + "Arena setup");
    8. sender.sendMessage(ChatColor.GREEN + "/TheMageGames signsetup " + ChatColor.GOLD + "Sign Setup");
    9. sender.sendMessage(ChatColor.GOLD + "o0-------------------------------------------------o0");
    10. }
    11. if(args.length == 1){
    12. if(args[0].equalsIgnoreCase("setup")){
    13. sender.sendMessage(ChatColor.GREEN + "/TheMageGames signsetup " + ChatColor.GOLD + "Sign Setup");
    14.  
    15. }
    16. }
    17. }
    18. return false;
    19. }
    20. }
     
  15. Offline

    ArthurHoeke

Thread Status:
Not open for further replies.

Share This Page