setFoodLevel Function not working

Discussion in 'Plugin Development' started by _Vallee, Apr 5, 2019.

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


    I have a plugin and part of it turns off Hunger however function setFoodLevel does not work and overall i have no idea why or maybe i need to add a cast to the plugin. The code responsible for identfiying the Player is all correct however setFoodLevel is not working.
    package Set;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.FoodLevelChangeEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    public class PlayerListener implements Listener
       float Set = 0;
       public PlayerListener(System plugin)
         plugin.getServer().getPluginManager().registerEvents(this, plugin);
         public void onPlayerInteractEvent(FoodLevelChangeEvent e)
         Player player = (Player) e.getEntity();
         player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 0, false, false));
    Last edited by a moderator: Apr 5, 2019
  2. Offline


    Try using this:
    1. player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, duration, amplifier));
    2. //Duration in ticks, amplifiers same as in game.

    Just an alternative way tho.
  3. Offline


    That worked!
    I don't know if setFoodLevel() is bugged or not, it works with a string and any player event, but with any Entity event it does not work, any way thanks a lot it working great now.
Thread Status:
Not open for further replies.

Share This Page