Solved check when food level goes down

Discussion in 'Plugin Development' started by vtg_the_kid, Jan 8, 2014.

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

    vtg_the_kid

    how can i use foodlevelchangeevent to find out when the food level goes down, not just when it changes?
     
  2. Offline

    metalhedd

    compare the value in the event to the current food level of the player to determine if it's gone up or down.
     
  3. Offline

    pookeythekid

    How would you find out? Via console, or via sending the player a message?

    I suppose you'd know how to send a player a message, but maybe this helps if you don't know how to via console.

    Code:
    final Logger logger = Logger.getLogger("Minecraft");
    this.logger.info("Player has lost a food level");
    Just put this after your EventHandler void thingy.

    Edit: Oops. I didn't see that you meant if it goes down. I'm not in the mood for overthinking right now... :p Ignore this whole message!
     
    vtg_the_kid likes this.
  4. Offline

    adam753

    Check the difference between the old and new food level, like so:
    Code:java
    1.  
    2. @EventHandler
    3. public void onFoodLevelChange (FoodLevelChangeEvent event) {
    4.  
    5. if(event.getEntity() instanceof Player) { //Safety check since we need to cast
    6. Player player = (Player)event.getEntity();
    7.  
    8. int oldFoodLevel = player.getFoodLevel();
    9. int newFoodLevel = event.getFoodLevel();
    10.  
    11. if(oldFoodLevel > newFoodLevel) {
    12. //Food level decreased
    13. }
    14. }
    15. }
    16.  
     
    vtg_the_kid likes this.
  5. Offline

    vtg_the_kid

    adam753
    thanks, i just wasn't sure which one was the old and new food level
     
Thread Status:
Not open for further replies.

Share This Page