Healing a player!

Discussion in 'Plugin Development' started by filurp, Sep 29, 2012.

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

    filurp

    Hey, i am new to Java/Plugin Developing and i am creating a plugin called 'fCommands', it is a small bunch of commands like the Essentials plugin but not as good :D. I was wondering how i would heal players? I appreciate all help! Thanks you!
     
  2. Offline

    dchaosknight

    filurp
    player.setHealth(*insert health here*);
    The health is 0-20, each number is half a heart.
     
  3. Offline

    filurp

    dchaosknight
    How would i add it to this?
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(commandLabel.equalsIgnoreCase("heal")) {
                sender.sendMessage("You have been healed!");
     
  4. Offline

    Hertz

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    {

    if(cmd.getName().equalsIgnoreCase("heal"))
    {
    Player player = (Player)sender;
    player.setHealth(20);
    }

    }

    or for hunger too

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    {

    if(cmd.getName().equalsIgnoreCase("revive"))
    {
    Player player = (Player)sender;
    player.setHealth(20);
    player.setHunger(20);

    }

    }
     
  5. Offline

    newboyhun

    Do not forget to check that is the sender is player or console:
    Code:
    if (sender instanceof Player) {
                ((Player) sender).setHealth(20);
                sender.sendMessage("You have been healed!");
            } else {
                sender.sendMessage("Only in-game use.");
            }
     
  6. Offline

    LukeSFT

    Please add an [SOLVED] to your title.
     
  7. Offline

    Tirelessly

    Spamming that shit is more annoying than posts not having [SOLVED]
     
Thread Status:
Not open for further replies.

Share This Page