Solved Best way to detect eating a golden apple

Discussion in 'Plugin Development' started by augustt198, Jan 6, 2014.

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

    augustt198

    Hi, I'm trying to find a reliable way to detect when a player eats a golden apple. I can't user PlayerInteractEvent because that doesn't necessarily mean the apple has been eaten. I also can't use FoodLevelChangeEvent, as you can eat an apple even with full health.

    Also, how can I detect whether an ItemStack is a "God Apple" or just the normal golden apple?

    Any help is appreciated!
     
  2. Offline

    Gater12

    augustt198 Have you tried PlayerItemConsumeEvent?
     
  3. Offline

    Wizehh

    1.
    Code:java
    1. public void onAppleEat(PlayerItemConsumeEvent event)

    2.
    Code:java
    1. if (event.getItem().equals(Material.GOLDEN_APPLE, 1, (short)1) {
    2. // todo
    3. }
    4.  

    I'm not sure if the second one will work or not.
     
  4. Offline

    augustt198

    Gater12 wow... must have missed that in the documentation. Thanks!

    Wizehh yeah, not sure that would work. Maybe
    Code:java
    1. if (item.getData().getData() == (byte) 1) { }

    Deprecated, though.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  5. Offline

    Wizehh

    augustt198
    Have you tried the one I posted? According to multiple other posters, it worked for them.
     
Thread Status:
Not open for further replies.

Share This Page