onFoodLevelChange not working?

Discussion in 'Plugin Development' started by Milkshakes00, Jan 13, 2013.

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

    Milkshakes00

    Hi guys, trying to just make a quick plugin to make it so food level drains slower, and I came across a snippet of code from a few months ago and tried to use it, but it doesn't seem to be working.

    The plugin according to the console is running perfectly fine. No errors.

    Code:
    package com.gmail.Milkshakes00.HungerX
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.FoodLevelChangeEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import java.util.logging.Logger;
     
    public final class HungerX extends JavaPlugin {
       
        @Override
        public void onEnable()
        {
            getLogger().info("HungerX logger has been enabled.");
        }
        @Override
        public void onDisable()
        {
            getLogger().info("HungerX logger has been disabled.");
        }
       
        @EventHandler
        public void onFoodLevelChange(FoodLevelChangeEvent event)
        {
            if(event.isCancelled())
                return;
            event.setFoodLevel(event.getFoodLevel() + 2);
        }
    }
     
  2. Offline

    chasechocolate

    Make your class implement Listener. Also, register your events in your onEnable():
    Code:java
    1. this.getServer().getPluginManager().registerEvents(this, this);
     
  3. Offline

    Milkshakes00

    Alright. Thanks a ton. That works. :D

    Now I just need to tweak the numbers to get it so that it isn't infinite food. I've tried a bunch of settings, and nothing seems to be working. Anyone have any ideas on how to make it so that it depletes slower than normal? +1 seems to make it infinite. + .5 seems to make no difference from vanilla, since integers round down..

    Any one have any ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  4. Code:java
    1.  
    2. @EventHandler (ignoreCancelled = true) //Use this instead of checking cancelled events yourself.
    3. public void onFoodLevelChange(final FoodLevelChangeEvent evt){
    4. evt.setFoodLevel(evt.getFoodLevel() + 2);
    5. }
    6.  


    Also look at this on how to use the new events system. http://forums.bukkit.org/threads/new-event-system.55249/
     
Thread Status:
Not open for further replies.

Share This Page