Solved Mushroom Soup = Heal?

Discussion in 'Plugin Development' started by PolarCraft, Dec 22, 2013.

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

    PolarCraft

    Okay so what I am trying to is that each time you eat mushroom soup it heals you to a certain degree. Example you eat the soup it adds 15% to your health bar.

    I have the consume event but how could I add health to the bar?
     
  2. Offline

    RawCode

    just set player's health inside event?
     
  3. Offline

    reider45

    Incase you dont already have it, you need the BukkitAPI then use p.setHealth(p.getHealth() + some number);​
     
  4. Offline

    PolarCraft

    RawCode No with a percentage. I do not want to set it. I need it so that eat time it heals it 'x' amount.
     
  5. Offline

    DrJava

    player.setHealth(player.getHealth()*(15/100.0f));

    Try that?

    EDIT: Sorry, I'm not very good with percentages :p
    It might be player.setHealth(player.getHealth()*15/100f);
     
  6. Offline

    PolarCraft

    DrJava I am having a little problem trying to get the event to work. I did a little different way than the percentage.

    Code:java
    1. package net.jc.minecraft.kit;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.block.Action;
    7. import org.bukkit.event.player.PlayerInteractEvent;
    8.  
    9. public class SoupEvent implements Listener {
    10.  
    11. public void onRightClick(PlayerInteractEvent e) {
    12. Player p = e.getPlayer();
    13. if (p.getHealth() == 20) {
    14. } else {
    15. int soup = +7;
    16. if ((e.getAction()) == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
    17. p.setHealth(p.getHealth() + soup > p.getMaxHealth() ? p.getMaxHealth() : p.getHealth() + soup);
    18. p.getItemInHand().setType(Material.BOWL);
    19. }
    20. }
    21. }
    22. }
     
  7. Offline

    DrJava

    1) What's the problem?
    2) Have you registered the event?
    3) int soup = +7 can be int soup = 7.
     
  8. Offline

    PolarCraft

    well i can not right click to heal the player.
     
  9. Offline

    DrJava

    heal the player you're clicking or yourself?
     
  10. Offline

    PolarCraft

    Player p = e.getPlayer();
     
  11. Offline

    AoH_Ruthless

    DrJava likes this.
  12. Offline

    DrJava

    PolarCraft
    Please tahg me if you need any further info.
     
Thread Status:
Not open for further replies.

Share This Page