WampyCakes WampyCakes - 4 months ago 23
Java Question

player.setFoodLevel doesn't work

I am making a KitPvP plugin for Bukkit. I have run across an error, and I was wondering if someone could help me.

So, I have a

Main.java
as my Main Class. I use
Hunger.java
for my extra class that my code won't work in. I registered the events in
Hunger.java
but the code won't execute in Minecraft all the other aspects of the plugin work so far besides this. Here is the code for
Hunger.java
:

package com.lobbyist.junk.kitpvp;

import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;

public class Hunger implements Listener{

public void onPlayerInteractEvent(PlayerInteractEvent event){
Player player = event.getPlayer();
player.setFoodLevel(20);
}

}


How do I make Player.setFoodLevel work?

EDIT: I just forgot to add an EventHandler annotation.

Answer

From what I gather from the documentation, you have not registered this event handler as an EventHandler.

Something like:

@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    player.setFoodLevel(20);
}
Comments