Arguments not working properly

Discussion in 'Plugin Development' started by bwfcwalshy, Jul 26, 2014.

Thread Status:
Not open for further replies.
  1. I am making a spleef plugin for my server but the args dont seem to be working as they should

    Here is my code (part not working):
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("spleefadmin")){
    3. if(args.length == 0){
    4. sender.sendMessage(Spleef.Prefix);
    5. sender.sendMessage(ChatColor.GREEN + "/spleefadmin create (arena name)");
    6. sender.sendMessage(ChatColor.GREEN + "/spleefadmin delete (arena name)");
    7. }else if(args.length == 1){
    8. if(args[0].equalsIgnoreCase("create")){
    9. sender.sendMessage(ChatColor.RED + "Cannot create a arena with no name!");
    10. Bukkit.getLogger().info("Create"); //Debug 1
    11. if(args.length == 2){
    12. Bukkit.getLogger().info("Create arena"); //Debug 2
    13. sender.sendMessage(ChatColor.LIGHT_PURPLE + "Creating " + args[0]);


    I put 2 debug messages number 1 works "Create" number 2 doesn't get ran.

    Console:
    Code:
    [09:44:26 INFO]: bwfcwalshy issued server command: /spleefadmin create
    [09:44:26 INFO]: Create
    [09:44:39 INFO]: bwfcwalshy issued server command: /spleefadmin create a
     
  2. Offline

    leon3001

    I'm not 100% sure but shouldn't you put a return true; behind the first debug message? (An else if statement should work too, I believe.)
     
  3. Offline

    Traks

    The if-block that includes your check for the 'create' argument is solely invoked when args.length == 1 returns true. In the second command you executed, there are however 2 arguments, which doesn't pass the initial else if-clause. Simply check if the length of the 'args' array equals 1 or is larger than 1: args.length >= 1. By the way, you might want to fix some indentation; it could help you.
     
Thread Status:
Not open for further replies.

Share This Page