Help with "Hat" command!

Discussion in 'Plugin Development' started by Skrarity, Dec 31, 2015.

Thread Status:
Not open for further replies.
  1. So yes, this code ALMOST works. So look in the code in the comments below and you will see my questions. I am not really sure HOW i should check these things, like if the player is online/existing that i can create my own error Message, PLUS how i check if the material is a material? Because if the player is doing "/hat sdf" i want an own error and how i check if it is not a material.

    Thanks.
    Code:
        @Override
        public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
            if(!(cs instanceof Player)) {
                cs.sendMessage("Only Players can use Hats");
                return true;
            }
            Player p = (Player)cs;
           
            if(args.length == 0) {
            p.sendMessage(ChatColor.RED + "/hat <material> <player>");
            } else if(args.length == 1) {
               
               
                if(p.hasPermission("hats.self")){
                   
                   
                    /**So how do i check if the material i choose below IS an actual material?**/       
             p.getInventory().setHelmet(new ItemStack(Material.getMaterial(args[0].toUpperCase())));
             p.playEffect(p.getLocation(),Effect.MOBSPAWNER_FLAMES, 5);
             p.sendMessage(ChatColor.GREEN + "You equipped " + args[0] + " as your hat!");
            
           
            }
            } else if(args.length == 2) {
                if(p.hasPermission("hats.otherplayer")){
                   
                   
                   
                    Player getter = Bukkit.getPlayer(args[1]);
                    /**How do i check if the Player IS a player / online?**/
                    /**So how do i check if the material i choose below IS an actual material?**/
                    getter.getInventory().setHelmet(new ItemStack(Material.getMaterial(args[0])));
                     getter.playEffect(p.getLocation(),Effect.MOBSPAWNER_FLAMES, 5);
                     getter.sendMessage(ChatColor.GREEN + "You got equipped " + args[0] + " as your hat by "+p.getName()+"!");
                   
                   
                   
                   
                   
                   
                }
            } else {
                p.sendMessage(ChatColor.RED + "/hat <material> <player>");
            }
           
            return true;
    }
     
  2. Offline

    mcdorli

    If getMaterial returns null, then it doesn't exist.
     
  3. Okay thanks for that one!
     
  4. Offline

    Zombie_Striker

    If the player is not online, " Bukkit.getPlayer(args[1]);" returns null. Null check to see if the player is online.
     
Thread Status:
Not open for further replies.

Share This Page