Java Code Examples for org.bukkit.event.entity.FoodLevelChangeEvent#setFoodLevel()

The following examples show how to use org.bukkit.event.entity.FoodLevelChangeEvent#setFoodLevel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HungerMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void handleHungerChange(final FoodLevelChangeEvent event) {
    if(event.getEntity() instanceof Player) {
        int oldFoodLevel = ((Player) event.getEntity()).getFoodLevel();
        event.setFoodLevel(oldFoodLevel);
    }
}
 
Example 2
Source File: HungerMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void handleHungerChange(final FoodLevelChangeEvent event) {
  if (event.getEntity() instanceof Player) {
    int oldFoodLevel = ((Player) event.getEntity()).getFoodLevel();
    event.setFoodLevel(oldFoodLevel);
  }
}
 
Example 3
Source File: Areas.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true,priority = EventPriority.LOW)
public void checkFood(FoodLevelChangeEvent event)
{
    Area a = getArea(new Loc(event.getEntity().getLocation(),false));
    if(a != null && !a.getAllowHunger())
    {
        event.setFoodLevel(20);
        //event.setCancelled(true);
    }
}
 
Example 4
Source File: KeepFood.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onFoodChange(FoodLevelChangeEvent event) {
    String world = event.getEntity().getWorld().getName().toLowerCase();
    if (this.foodLevelMap.containsKey(world)) {
        int food = this.foodLevelMap.get(world);
        if (food > 0 && food <= 20)
            event.setFoodLevel(food);
    }
}