If command is not complete, return usage

Discussion in 'Spigot Plugin Development' started by BadManner, Jun 18, 2015.

  1. So I am running into an issue with my plugin it works GREAT... if it has all the correct arguments.

    My current code is
    Code (Text):
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
           
            Player p = Bukkit.getServer().getPlayer(args[0]);
            Player send = (Player) sender;
            Location blockUnderPlayerLocation = p.getLocation().subtract(0,1,0);
            Block blockUnderPlayer = blockUnderPlayerLocation.getBlock();
            Material type = blockUnderPlayer.getType();
           
            if(label.equalsIgnoreCase("freeze")){
                if(!frozen.contains(p.getName())){
                    if(send.hasPermission("gfreeze.use")){
                        if(blockUnderPlayerLocation.getBlock().getType() == Material.AIR){
                            blockUnderPlayer.setType(Material.BARRIER);
                        }
                    frozen.add(p.getName());
                    send.sendMessage(ChatColor.GREEN + "You have frozen " + ChatColor.GRAY + p.getName() + "!");
                    p.sendMessage(ChatColor.GREEN + "You have been frozen by " + ChatColor.GRAY + send.getName() + ChatColor.GREEN + " Do" + ChatColor.BOLD + " NOT" + ChatColor.GREEN + " log out or you will be banned!");  
                    }
                }
            } else if(label.equalsIgnoreCase("unfreeze")){
                if(frozen.contains(p.getName())){
                    if(send.hasPermission("gfreeze.use")){
                        if(blockUnderPlayerLocation.getBlock().getType() == Material.BARRIER){
                            blockUnderPlayer.setType(type);
                        }
                    frozen.remove(p.getName());
                    send.sendMessage(ChatColor.GREEN + "You have unfrozen " + ChatColor.GRAY + p.getName() + "!");
                    p.sendMessage(ChatColor.GREEN + "You have been unfrozen, have a nice day!");
                    }
                }
            }
            return false;
        }
    My questions is how would I get it so if the command 'freeze' or 'unfreeze' doesn't have all the correct arguments it returns the 'usage' located in the plugin.yml
     
  2. If you return false it will show the usage. Returning true will not show the usage. ;)
     
  3. Check if all the arguments are correct. If not:
    Code (Text):
    return false;
     
  4. What arguments do you have? Just the player's name?
     
  5. Yes, the variables "p" "send" "blockUnderPlayer" "blockUnderPlayerLocation"and "type"