Solved Two arguments on my plugin

Discussion in 'Plugin Development' started by Ewearys, May 2, 2015.

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

    Ewearys

    Hello, I have made my plugin
    If the player enters the command :
    /halcyon => he will see the list of commands available

    I want to if the player writes the command :
    /halcyon info => he sees the info

    But it does not work :(
    Here's my code :

    Code:
    package fr.axploodee.halcyon;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    
    public class CmdHalcyon implements CommandExecutor {
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("halcyon")) {
               
                sender.sendMessage(new String[] {"§6==========[§eAide - Halcyon§6]==========", "§6/halcyon : §fAffiche la liste des commandes du plugin Halcyon", "§6/site : §fOuvre le site dans le navigateur", "§6/boutique : §fOuvre la boutique dans le navigateur", "§6/forum : §fOuvre le forum dans le navigateur", "§6/vote : §fOuvre la page de vote dans le navigateur", "§6/teamspeak : §fOuvre le TeamSpeak avec votre pseudonyme", "§6/ts : §fOuvre le TeamSpeak avec votre pseudonyme"});
               
                return true;
            }
                if (args.length == 1) {
                    if (args[0].equalsIgnoreCase("info")) {
                        sender.sendMessage(new String[] {"§6Ce plugin a été développé par §cAxploOdee§6 pour le serveur     §cHalcyon§6.", "§6La version du plugin est §c1.0§6."});
                       
                        return true;
                    }
                }
           
            return false;
        }
       
    }
    What should I do ?
    Thanks :)
     
  2. @Ewearys Your second if() statement is in the wrong place. Always do it after checking that they execute the command. You need to check if the args.length == 0 first, then show the list of commands, and then check if it's 1.
     
  3. Offline

    Ewearys

    Here's my code, but it's still not working :/

    Code:
    package fr.axploodee.halcyon;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    
    public class CmdHalcyon implements CommandExecutor {
    
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
         if (cmd.getName().equalsIgnoreCase("halcyon")) {
           
           sender.sendMessage(new String[] {"§6==========[§eAide - Halcyon§6]==========", "§6/halcyon : §fAffiche la liste des commandes du plugin Halcyon", "§6/site : §fOuvre le site dans le navigateur", "§6/boutique : §fOuvre la boutique dans le navigateur", "§6/forum : §fOuvre le forum dans le navigateur", "§6/vote : §fOuvre la page de vote dans le navigateur", "§6/teamspeak : §fOuvre le TeamSpeak avec votre pseudonyme", "§6/ts : §fOuvre le TeamSpeak avec votre pseudonyme"});
           
           return true;
         }
         
       
          if (args.length == 0) {
            sender.sendMessage(new String[] {"§6==========[§eAide - Halcyon§6]==========", "§6/halcyon : §fAffiche la liste des commandes du plugin Halcyon", "§6/site : §fOuvre le site dans le navigateur", "§6/boutique : §fOuvre la boutique dans le navigateur", "§6/forum : §fOuvre le forum dans le navigateur", "§6/vote : §fOuvre la page de vote dans le navigateur", "§6/teamspeak : §fOuvre le TeamSpeak avec votre pseudonyme", "§6/ts : §fOuvre le TeamSpeak avec votre pseudonyme"});
       
            return true;
          }
    
          else if (args.length == 1) {
            if (args[0].equalsIgnoreCase("info")) {
               sender.sendMessage(new String[] {"§6Ce plugin a été développé par §cAxploOdee§6 pour le serveur  §cHalcyon§6.", "§6La version du plugin est §c1.0§6."});
       
      return true;
      }
      }
         
         return false;
      }
       
    }
    
    
    Moreover, I'd like to know if I have to to write this (in the plugin.yml) :
    Code:
    commands:
       halcyon info:
         description: Bla bla bla
         permission: halcyon.info
     
    Last edited: May 2, 2015
  4. @Ewearys
    Yes you need to register every command in the plugin.yml
    but i am not sure if space is suppoerted, probabl not
     
  5. Offline

    Ewearys

    I done this, but It still giving me the message of /halcyon
    When I write /halcyon info, it seems that just read the /halcyon, so I have the first message
    What's the problem? :confused:
     
  6. @Ewearys
    Of course it does, beccause you are right in the beginning checking if the command is halycon, then you are sending a message, and the you return true.
     
  7. Offline

    Ewearys

    How could I send a message if the command /halcyon info is typed ?
     
  8. @Ewearys
    The problem is in your first if statement you are checking if the command is halycon, and when you type /halycon info, thisis the case. Then you are sending the message. And then you are returning, so youre not reaching the other code parts.
     
  9. Offline

    Ewearys

    I'm a beginner in java, I've done my plugin with the Bukkit Plugin Tutorial, and there's nothing to help me on this tutorial.
    Could you tell me what I shall do please ?
     
  10. Offline

    CoolGamerXD

    Code:
    if (cmd.getName().equalsIgnoreCase("halcyon")) {
            
              if (args.length == 0) {
          
              sender.sendMessage(new String[] {"§6==========[§eAide - Halcyon§6]==========", "§6/halcyon : §fAffiche la liste des commandes du plugin Halcyon", "§6/site : §fOuvre le site dans le navigateur", "§6/boutique : §fOuvre la boutique dans le navigateur", "§6/forum : §fOuvre le forum dans le navigateur", "§6/vote : §fOuvre la page de vote dans le navigateur", "§6/teamspeak : §fOuvre le TeamSpeak avec votre pseudonyme", "§6/ts : §fOuvre le TeamSpeak avec votre pseudonyme"});
          
              return true;
              }
      
             else if (args.length == 1) {
               if (args[0].equalsIgnoreCase("info")) {
                  sender.sendMessage(new String[] {"§6Ce plugin a été développé par §cAxploOdee§6 pour le serveur  §cHalcyon§6.", "§6La version du plugin est §c1.0§6."});
      
         return true;
         }
         }
        
        
         }
            return true;
      
        }
    }

    @Ewearys
    Problem is that you checked 2 times "args.length == 0". Since it is if (cmd.equalsIgnoreCase("halcyon") it is taken argument 0. I have given you fixed code above
     
    Last edited: May 2, 2015
  11. Offline

    Ewearys

    Thanks it worked fine !! :D
     
Thread Status:
Not open for further replies.

Share This Page