Solved Help! How can i use args in Eclipse?

Discussion in 'Spigot Plugin Development' started by StijnSimons, May 16, 2016.

  1. No, i mean that when they type a wrong argument
     
  2. False, args 1 is the second work, args 0 is the first word
     
  3. if (!args[0].equalsIgnoreCase("Heal") {
    sender.sendMessage("WRONG COMMAND")
    }
     
  4. Ok, lemme try this
     
  5. if(!(args[0].equalsIgnoreCase("help"))){
    player.sendMessage("usage: /command help");
    }
     
  6. Haha, beat you to that one ^_^
     
  7. :(
     
  8. If I was wrong then why does this work?

    Code (Text):
    if (cmd.getName().equalsIgnoreCase("message")) {
         
            if (player.hasPermission("dz.message")) {
                if (args.length < 2) {
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lMessaging &8&l> &7Usage: /message <user> <message>!"));
                } else if (args.length == 2) {
                    Player target = Bukkit.getServer().getPlayer(args[0]);
                    if (target == null) {
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lMessaging &8&l> &7That player is not online!"));
                    } else if (target == player) {
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lMessaging &8&l> &7You can't message yourself!"));
                    } else if (this.disabled.contains(target.getName())){
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lMessaging &8&l> &7Sorry but this player has private messaging disabled!"));
                    } else {
                        StringBuilder st = new StringBuilder();
                     
                        for (int i = 1 ; i < args.length ; i++) {
                            st.append(args[i] + " ");
                        }
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&a&l" + player.getName() + " &8&l> " + args[0] + " &7" + st));
                        target.sendMessage(ChatColor.translateAlternateColorCodes('&', "&a&l" + player.getName() + " &8&l> " + args[0] + " &7" + st));
                    }
                }
            } else {
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lPermissions &8&l> &7Sorry you don't have perms tho!"));
            }
     
  9. Idk, but what I said works for me and what I think most people use.
     
  10. ew ugly code xD, try using a method returniung string for the color code translation.
     
  11. Works!
    Thanks, you guys are gods!
     
    • Friendly Friendly x 1
  12. xD
     
  13. No problem! Glad you've got it working.
     
  14. shhhhhhh I'm still learning plz xD
     
  15. So, what are you guys working on? (Resource)
     
  16. Chat
     
  17. Oh cool, PS; you should try updating your 'Greetings 1.5.jar' to 1.9
     
  18. You want it for 1.9??
     
  19. Yea, and another thing (xD): how can i make it so when they type '/omegafun' without the 'help' argument it would say:
    'Error: use '/omegafun help'!