Soup Plugin interact

Discussion in 'Plugin Development' started by NeinSpass, May 14, 2017.

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

    NeinSpass

    Hello everyone,

    I code a soup plugin. I have already done mostly everything (main, plugin.yml etc.). The plugin is working, but if I look to a block and eat a soup, the soup replaced to a bowl and I get added 3,5 (7) hearts. If I am over 13 hp (healthpoints) and look in the air (not on any kind of block) I get healed but the mushroom_stew doesnt replaces it into a bowl..

    and sry for my bad english :(

    Code:
    package at.neinspass.soup;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    
    public class Soup implements Listener{
     
        @EventHandler
        public void soupInteract(PlayerInteractEvent e) {
         
            Player p = e.getPlayer();
            double h = p.getHealth();
            ItemStack bowl = new ItemStack(Material.BOWL);
            if(e.getItem() != null) {
            if(p.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
                if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.RIGHT_CLICK_AIR)) {
                    if(h != 20){
                    if(h > 13) {
                     
                        p.setHealth(20);
                        p.setItemInHand(bowl);
                     
                    }else{
                     
                        p.setHealth(h + 7);
                        p.setItemInHand(bowl);
                    }
                    }
                }
                }
             
            }
        }
    }
    
     
    Last edited: May 14, 2017
  2. Offline

    xelatercero

    Why are u checking the e.getItem(); check the item in player hand.
    #equals(); method is used to compare Strings , use "==" instead.
     
Thread Status:
Not open for further replies.

Share This Page