Why doesn't it check for arguments?

Discussion in 'Spigot Plugin Development' started by Raizi, Dec 2, 2018.

Thread Status:
Not open for further replies.
  1. Hi guys!
    Why I do not want to check on the arguments? If you enter> 4, the command is canceled; if you enter <= 4, the code is executed.
    Maybe I'm confused with return true or false?
    Help me please!
    Code (Java):
        public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) {
            Player p = (Player) sender;
            String nick = p.getName();
            if ((args.length == 0)) {
              sender.sendMessage("Usage /prefix <name>.");
              return false;
            if (args.length > 4) {
                return true;      
            if (args.length <= 4) {
                StringBuilder sb = new StringBuilder();
                for (String s : args) {
                String color = ChatColor.LIGHT_PURPLE + "[" + sb + "]" + " \"";
                String f = sb.toString();
                Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "pex user " + nick + " prefix \"" + color);
                sender.sendMessage("Prefix successfully installed.");
                return true;              
            return false;

  2. I have no clue what you're saying...
    Can you explain again?
  3. I get what your saying so basically you want to register the args (placement) if that works for you to understand.

    Simple do this

    Code (Text):
                if (args[0].equalsIgnoreCase("example")) {
    The code above where it states args[0] actually means for example - /command example


    would be something like - /command example example since in java you always start with a 0 and not a 1.

    Hope this helps!
    • Like Like x 2
Thread Status:
Not open for further replies.

Share This Page