Args problem

Discussion in 'Plugin Development' started by DarkSteve25, Dec 5, 2016.

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

    DarkSteve25

    Am having problems with the args again. Basically when a player does the command /toggle set <playername> God. It changes their rank to god and when a player does /toggle set <playername> God 20, it takes 20 seconds to give them their god rank. Am having problems with getting the /toggle set <playername> god 20 to work. can I get a little help? This is my code

    Code:
        @Override
        public void onCommand(CommandSender sender, Command cmd, String[] args) {
      if (args[0].equalsIgnoreCase("toggle")) {
    if(args.length == 0){
      sender.sendMessage(ChatColor.GREEN + "/toggle set <playername> god (seconds)");
      sender.sendMessage(ChatColor.GREEN + "/toggle set <playername> jesus (seconds)");
      sender.sendMessage(ChatColor.GREEN + "/toggle set <playername> gap (seconds)");
      sender.sendMessage(ChatColor.GREEN + "/toggle set <playername> pvp (seconds)");
    return true;
    }
            if (args[0].equalsIgnoreCase("set")) {
            }
    
            if (!sender.hasPermission("toggle.set")) {
                sender.sendMessage(ChatColor.RED + "You do not have access to set ranks");
                return;
            }
    
            Player target = Bukkit.getServer().getPlayer(args[1]);
            if (target == null) {
                sender.sendMessage("The player is not online!");
                return;
            }
            if (args.length == 3){
            if (args[2].equalsIgnoreCase("god")) {
                  target.sendMessage(ChatColor.GREEN + "god rank");
                    return;
                }
             
                 if (args[2].equalsIgnoreCase("jesus")) {
    target.sendMessage(ChatColor.GREEN + "jesus rank");
                    return;
    
                } else if (args[2].equalsIgnoreCase("gap")) {
    target.sendMessage(ChatColor.GREEN + "gap rank");
    
                    return;
                } else if (args[2].equalsIgnoreCase("pvp")) {
    
    target.sendMessage(ChatColor.GREEN + "pvp rank");
                    return;
    }
                    if (args[3].equalsIgnoreCase(" "))
                        ;
    
                    final Player p = (Player) sender;
    
                   target.sendMessage(ChatColor.GREEN + "wait for you rank");
                    plugin.cooldownTime.put(p, number);
                    plugin.cooldownTask.put(p, new BukkitRunnable() {
                        public void run() {
                            plugin.cooldownTime.put(p, plugin.cooldownTime.get(p) - 1);
                            if (plugin.cooldownTime.get(p) == 0) {
                                plugin.cooldownTime.remove(p);
                                plugin.cooldownTask.remove(p);
                                cancel();
                            }
                        }
                    });
    
                    plugin.cooldownTask.get(p).runTaskTimer(plugin, 20, 20);
    
                    return;
                }else{
                    sender.sendMessage("To many args");
                }
     
             
    
            }
        }
    
    Thanks
     
  2. Offline

    Zombie_Striker

    How will this ever be true? How can the first are be "toggle" If there is no first arg. Make sure you check the toggle AFTER you check the amount.
     
  3. Offline

    DoggyCode™

    PHP:
    Player p = (Player)sender;

    //First, check if the player specified a argument at all
    if(args.length==0) {
      
    //player only specified the initial command, no arguments
      
    return false;
    }

    //this will be true if the player specifies "/command toggle"
    if(args[0]).equalsIgnoreCase("toggle") {
      
    //making pre-defined variables
      //in case the player doesn't specify any
      
    Player t p;
      
    int time 0;
      if(
    args.length==2) {
        
    Bukkit.getPlayer(args[1]);
        
    //checking if specified player is online
        
    if(t==null) {
          return 
    false//player specified is not online or doesn't exist
        
    }
      }
      
    //player specified Player and time
      
    if(args.length>2) {
        
    time Integer.parseInt(args[2]);
      }

      
    //do the rest of your code, for example:
      
    p.sendMessage("You toggled " t.getName() + " for " time);
    }
    This is just an example, and you have to do it accordingly to your needs, if you want a rank variable too, insert that. It also look way nicer than doing tons of different checks.
     
Thread Status:
Not open for further replies.

Share This Page