@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onFoodLevelChange(final FoodLevelChangeEvent event) { if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) { event.setCancelled(true); } }
@EventHandler public void onEat(FoodLevelChangeEvent event) { if (event.getEntity() instanceof Player) { if (GameManager.INSTANCE.getSession((Player) event.getEntity()) == null) return; Player p = (Player) event.getEntity(); if (GameManager.INSTANCE.getSession(p) == null) return; int old = p.getFoodLevel(); int newLevel = event.getFoodLevel(); if (newLevel - old > 0) { p.setHealth(Math.min(p.getHealth() + 1, p.getMaxHealth())); } } }
/** * Handles player food level changes.<br> * If the player is in an arena, the game's onPlayerFoodLevelChange method is called.<br> * If the player is spectating an arena, the event is cancelled. */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onFoodLevelChange(FoodLevelChangeEvent event) { if (event.getEntity() instanceof Player) { String playerName = event.getEntity().getName(); if (ultimateGames.getPlayerManager().isPlayerInArena(playerName)) { Arena arena = ultimateGames.getPlayerManager().getPlayerArena(playerName); if (arena.getStatus() == ArenaStatus.RUNNING) { arena.getGame().getGamePlugin().onPlayerFoodLevelChange(arena, event); } else { event.setCancelled(true); } } else if (ultimateGames.getPlayerManager().isPlayerSpectatingArena(playerName)) { event.setCancelled(true); } } }