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

The following examples show how to use org.bukkit.event.entity.FoodLevelChangeEvent#setCancelled() . 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: FoodLevelChange.java    From StaffPlus with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlace(FoodLevelChangeEvent event)
{
	Entity entity = event.getEntity();
	
	if(!(entity instanceof Player))
	{
		return;
	}
	
	if(options.modeHungerLoss || !modeCoordinator.isInMode(((Player) entity).getUniqueId()))
	{
		return;
	}
	
	event.setCancelled(true);
}
 
Example 2
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onHunger(FoodLevelChangeEvent flce) {
  if (!(flce.getEntity() instanceof Player)) {
    return;
  }

  Player player = (Player) flce.getEntity();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() == GameState.RUNNING) {
    if (game.isSpectator(player) || game.getCycle().isEndGameRunning()) {
      flce.setCancelled(true);
      return;
    }

    flce.setCancelled(false);
    return;
  }

  flce.setCancelled(true);
}
 
Example 3
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents changing of hunger while having a special permission and being on your island
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onHungerChange(final FoodLevelChangeEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName() + " food level = " + ((Player)e.getEntity()).getFoodLevel() + " new food level = " + e.getFoodLevel());

    }
    // Allow food increases
    if (e.getFoodLevel() - ((Player)e.getEntity()).getFoodLevel() > 0) {
        return;
    }
    if (e.getEntity().hasPermission(Settings.PERMPREFIX + "nohunger")) {
        if(plugin.getGrid().playerIsOnIsland((Player) e.getEntity())) {
            e.setCancelled(true);
        }
    }
}
 
Example 4
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerFoodLevelChange(FoodLevelChangeEvent event) {
    final Player player = event.getEntity() instanceof Player ? (Player) event.getEntity() : null;
    if (player == null) {
        return;
    }

    GDCauseStackManager.getInstance().pushCause(player);
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
    final Boolean denyHunger = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Boolean.class), playerData.getSubject(), Options.PLAYER_DENY_HUNGER, claim);
    if (denyHunger != null && denyHunger) {
        event.setCancelled(true);
    }
}
 
Example 5
Source File: DPlayerListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) {
    GameWorld gameWorld = plugin.getGameWorld(event.getEntity().getWorld());
    if (gameWorld != null) {
        if (!gameWorld.isPlaying() || !gameWorld.getDungeon().getRules().getState(GameRule.FOOD_LEVEL)) {
            event.setCancelled(true);
        }
    }
}
 
Example 6
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerFoodChange(final FoodLevelChangeEvent event) {
    if (event.getEntity() instanceof Player && plugin.getWorldManager().isSkyWorld(event.getEntity().getWorld())) {
        Player hungerman = (Player) event.getEntity();
        float randomNum = RANDOM.nextFloat();
        if (plugin.getWorldManager().isSkyWorld(hungerman.getWorld())
                && hungerman.getFoodLevel() > event.getFoodLevel()
                && plugin.playerIsOnIsland(hungerman)) {
            Perk perk = plugin.getPerkLogic().getPerk(hungerman);
            if (randomNum <= perk.getHungerReduction()) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 7
Source File: FlagSpectate.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) {
	HumanEntity entity = event.getEntity();
	if (!(entity instanceof Player)) {
		return;
	}
	
	SpleefPlayer player = getHeavySpleef().getSpleefPlayer(entity);
	if (!isSpectating(player)) {
		return;
	}
	
	event.setCancelled(true);
}
 
Example 8
Source File: EnvironmentControlListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void noHunger(final FoodLevelChangeEvent event) {
    event.setCancelled(true);
}
 
Example 9
Source File: NoHungerLossFeature.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@GameEvent
public void onHungerDepletion(@Nonnull FoodLevelChangeEvent event) {
    event.setCancelled(true);
}
 
Example 10
Source File: ServerListener.java    From ZombieEscape with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onStarve(FoodLevelChangeEvent event) {
    event.setCancelled(true);
}
 
Example 11
Source File: Hunger.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onHungerDepletion(FoodLevelChangeEvent event) {
    if (!hungerEnabled) {
        event.setCancelled(true);
    }
}
 
Example 12
Source File: EntityListener.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.setCancelled(true);
    }
}