Healing Food Help.

Discussion in 'Plugin Development' started by Fuzzybear04, May 16, 2014.

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

    Fuzzybear04

    SOLVEDHey Guys, Fuzzybear04 here, and I need help coding my heal food plugin.
    Basically, the concept is that you Right click a food (In this instance, it is a Cookie, (Cooked) steak, Golden Apple and some Bread), and it heals a configurable amount of food.
    My problem is that Whenever you Right click with the item, It won't remove the Item from the ItemStack, even though I've specified it to, and I'm not sure where I'm going wrong
    Any help would be much appreciated.
    Thank you.

    CODE -

    package healfood;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
    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;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener{


    public void onEnable(){
    getLogger().info("FuzzyFood is now Enabled");
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    getConfig().options().copyDefaults();
    saveConfig();
    }

    public void onDisable(){
    getLogger().info("FuzzyFood is now Disabled");
    }

    @SuppressWarnings("deprecation")
    @EventHandler
    public void cookie(PlayerInteractEvent e){
    Player p = e.getPlayer();
    if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR){
    if(p.getItemInHand().getType() == Material.COOKIE){
    if(((CraftPlayer)p).getHealth() == 20){
    return;
    } else if(p.getItemInHand().getAmount() == 1 && p.getItemInHand().getType() == Material.COOKIE){
    ((CraftPlayer)p).setHealth(((CraftPlayer)p).getHealth() + getConfig().getDouble("cookie"));
    p.getItemInHand().setType(Material.AIR);
    p.updateInventory();
    }

    else {
    ItemStack i = new ItemStack(Material.COOKIE);
    i.setAmount(i.getAmount() - 1);
    ((CraftPlayer)p).setHealth(((CraftPlayer)p).getHealth() + getConfig().getDouble("cookie"));
    p.updateInventory();
    }
    }

    }
    }

    }
     

    Attached Files:

  2. Offline

    xMrPoi

    You're checking if they're just right clicking an item. I believe you could use this event.
     
Thread Status:
Not open for further replies.

Share This Page