Help?

Discussion in 'Spigot Plugin Help' started by Cuulv, Apr 21, 2017.

  1. I am creating a heal command, and I want it to set it so players can only heal other players once every 45 seconds, how do I do this?

    My Code is:
    Code (Text):

            Player player = (Player)sender;
            if(cmd.getName().equalsIgnoreCase("heal"))
            {
                if(args.length == 0)
                {
                    player.sendMessage(ChatColor.BOLD + "" + ChatColor.AQUA + " /heal self - Heal Yourself!");
                    player.sendMessage(ChatColor.BOLD + "" + ChatColor.AQUA + " /heal <player> - Heal Another Player!");
                }
                else
                {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    if(target == null)
                    {
                        player.sendMessage("Your target is either non-existent, or offline!");
                    }
                    if(player.getHealth() >= 15)
                    {
                       
                    }
                    else
                    {
                        player.sendMessage("You've Healed " + args[0]);
                        target.setHealth(15);
                    }
                   
                }
            }
            return true;
           
        }
     
  2. essentials has a heal command and in the config there is an are where you can add how long you want the cooldown to be for, and theres a permission essentials.heal.others so people can heal other people.
     
  3. i know, i just want to know how i can do it, i plan to make my heal command more advanced than the essentials one
     
  4. hope you dont mind me asking, but how do you make a heal command more advanced?? all it does is heal players...
     
  5. Strahan

    Benefactor

    I don't know if it is the best way, but I would have a map with players and time the command was last used. When a player goes to use it, if the player isn't in the map the command works. If they are in the map, it checks the time for the player and if it meets criteria, the command works. Then afterwords it either adds the player with the current time or updates the time for the existing player entry.

    Yea, heal is heal but I can still understand wanting to do it anyway. It's a good learning experience.