Health problem

Discussion in 'Plugin Development' started by MrGermanrain, Dec 5, 2013.

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

    MrGermanrain

    I am updating one of my plugins finally and I am having problems with the Health and ItemStack, if you have any ideas please let me know :) Thanks!

    Code:java
    1. package me.mrgermanrain.moresoup;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.Event.Result;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class MoreSoupEvents extends JavaPlugin implements Listener {
    14.  
    15. Boolean sh = getConfig().getBoolean("soupheals");
    16. int hps = getConfig().getInt("hps");
    17.  
    18. @SuppressWarnings("deprecation")
    19. @EventHandler
    20. public void onPlayerFoodConsume(PlayerInteractEvent e) {
    21. Player p = e.getPlayer();
    22.  
    23. if (sh != false) {
    24. if (p.getItemInHand().getType() == Material.MUSHROOM_SOUP && p.hasPermission("moresoup.usesoup")) {
    25. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    26. e.setUseItemInHand(Result.DENY);
    27. p.getInventory().removeItem(new ItemStack(e.getItem().getTypeId(), 1));
    28. } if (p.getHealth() != 20) {
    29. p.setHealth(p.getHealth() + hps);
    30.  
    31. }
    32. }
    33. }
    34. }
    35. }
     
  2. Offline

    Windy Day

    Not sure if you are updating from before this, but health was changed to a double awhile ago.
     
  3. Offline

    MrGermanrain

    So how would I fix this? I think that I have read this before in "I didn't break your plugin." But my English isn't perfect so I didn't fully duplicate this.
     
  4. Offline

    Windy Day

    Change things like:

    Code:
    int hps = getConfig().getInt("hps");
    
    To:
    Code:
    Double hps = getConfig().getInt("hps");
    
    Code:
    } if (p.getHealth() != 20.0D) {
    //continue
    }
    
    So that you are initializing things as Doubles instead of Integers, then that should fix it. Also your English is pretty good.
     
  5. Offline

    imaboy321

    No he needs to change it to
    Code:
    double hps = getConfig().getDouble("hps");
    haha
     
  6. Offline

    xepisolonxx

    here an example i have used
    Code:
    Player target = Bukkit.getServer().getPlayer(args[0]);
                        Damageable dtarget = (Damageable)target;
                        if(target !=null){
                            sender.sendMessage(ChatColor.GOLD + "" + target.getName() +"'s" + ChatColor.RED +
                                    " health is at " + dtarget.getHealth() *5 + "%." ); 
     
  7. Am i the only one who misinterpreted the title a bit? :p
     
    Gater12 likes this.
  8. Offline

    Windy Day

    Oops, missed that part. Kinda just typed it fast outside of an IDE
     
  9. Offline

    d3v1n302418

    Make sure you aren't giving them more than 20 health or you will get an error.
     
  10. Offline

    PogoStick29

    You don't need this line:

    Damageable dtarget = (Damageable)target;

    There just is not need.
     
  11. Offline

    xepisolonxx

    i know just didnt
    I know just was to lazy to change it btw love the videos keep them up![cake]
     
  12. Offline

    PogoStick29

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page