org.bukkit.event.entity.FoodLevelChangeEvent Java Examples
The following examples show how to use
org.bukkit.event.entity.FoodLevelChangeEvent.
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: PlayerEvents.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * 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 #2
Source File: HungerMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@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: WindStaff.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override public ItemUseHandler getItemHandler() { return e -> { Player p = e.getPlayer(); if (p.getFoodLevel() >= 2) { if (p.getInventory().getItemInMainHand().getType() != Material.SHEARS && p.getGameMode() != GameMode.CREATIVE) { FoodLevelChangeEvent event = new FoodLevelChangeEvent(p, p.getFoodLevel() - 2); Bukkit.getPluginManager().callEvent(event); p.setFoodLevel(event.getFoodLevel()); } p.setVelocity(p.getEyeLocation().getDirection().multiply(4)); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1); p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1); p.setFallDistance(0F); } else { SlimefunPlugin.getLocalization().sendMessage(p, "messages.hungry", true); } }; }
Example #4
Source File: FoodLevelChange.java From StaffPlus with GNU General Public License v3.0 | 6 votes |
@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 #5
Source File: CoolerListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onHungerLoss(FoodLevelChangeEvent e) { if (cooler == null || cooler.isDisabled()) { return; } Player p = (Player) e.getEntity(); if (e.getFoodLevel() < p.getFoodLevel()) { for (ItemStack item : p.getInventory().getContents()) { if (cooler.isItem(item)) { if (Slimefun.hasUnlocked(p, cooler, true)) { takeJuiceFromCooler(p, item); } else { return; } } } } }
Example #6
Source File: PlayerListener.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
@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 #7
Source File: Areas.java From AnnihilationPro with MIT License | 5 votes |
@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 #8
Source File: KeepFood.java From HubBasics with GNU Lesser General Public License v3.0 | 5 votes |
@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); } }
Example #9
Source File: TestCoolerListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Test public void testCoolerUsage() throws InterruptedException { Player player = server.addPlayer(); PlayerProfile profile = TestUtilities.awaitProfile(player); PlayerBackpack backpack = profile.createBackpack(cooler.getSize()); backpack.getInventory().setItem(0, juice.getItem().clone()); ItemStack personalCooler = cooler.getItem().clone(); new BackpackListener().setBackpackId(player, personalCooler, 1, backpack.getId()); player.getInventory().setItem(7, personalCooler); FoodLevelChangeEvent event = new FoodLevelChangeEvent(player, 16); listener.onHungerLoss(event); Assertions.assertTrue(player.hasPotionEffect(PotionEffectType.HEALTH_BOOST)); }
Example #10
Source File: StormStaff.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void useItem(Player p, ItemStack item, Location loc) { loc.getWorld().strikeLightning(loc); if (p.getInventory().getItemInMainHand().getType() == Material.SHEARS) { return; } if (p.getGameMode() != GameMode.CREATIVE) { FoodLevelChangeEvent event = new FoodLevelChangeEvent(p, p.getFoodLevel() - 4); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { p.setFoodLevel(event.getFoodLevel()); } } ItemMeta meta = item.getItemMeta(); int usesLeft = meta.getPersistentDataContainer().getOrDefault(usageKey, PersistentDataType.INTEGER, MAX_USES); if (usesLeft == 1) { p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1); item.setAmount(0); } else { usesLeft--; meta.getPersistentDataContainer().set(usageKey, PersistentDataType.INTEGER, usesLeft); List<String> lore = meta.getLore(); lore.set(4, ChatColors.color("&e" + usesLeft + ' ' + (usesLeft > 1 ? "Uses" : "Use") + " &7left")); meta.setLore(lore); item.setItemMeta(meta); } }
Example #11
Source File: PlayerEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@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 #12
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 5 votes |
@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 #13
Source File: DPlayerListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@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 #14
Source File: ExprFoodLevel.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override protected Float[] get(final Event e, final Player[] source) { return get(source, new Getter<Float, Player>() { @Override public Float get(final Player p) { if (getTime() >= 0 && e instanceof FoodLevelChangeEvent && p.equals(((FoodLevelChangeEvent) e).getEntity()) && !Delay.isDelayed(e)) { return 0.5f * ((FoodLevelChangeEvent) e).getFoodLevel(); } else { return 0.5f * p.getFoodLevel(); } } }); }
Example #15
Source File: FlagSpectate.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@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 #16
Source File: HungerMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@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 #17
Source File: EntityListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldHandleSimpleEvents() { withServiceMock(listenerService) .check(listener::onFoodLevelChange, FoodLevelChangeEvent.class) .check(listener::onShoot, EntityShootBowEvent.class) .check(listener::onEntityInteract, EntityInteractEvent.class) .check(listener::onLowestEntityInteract, EntityInteractEvent.class); }
Example #18
Source File: ServerListener.java From ZombieEscape with GNU General Public License v2.0 | 4 votes |
@EventHandler public void onStarve(FoodLevelChangeEvent event) { event.setCancelled(true); }
Example #19
Source File: ObserverModule.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onViewingFoodLevelChange(FoodLevelChangeEvent event) { refreshView(event.getEntity().getUniqueId()); }
Example #20
Source File: Hunger.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onHungerDepletion(FoodLevelChangeEvent event) { if (!hungerEnabled) { event.setCancelled(true); } }
Example #21
Source File: EntityListener.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onFoodLevelChange(FoodLevelChangeEvent event) { if (listenerService.shouldCancelEvent(event)) { event.setCancelled(true); } }
Example #22
Source File: ExprFoodLevel.java From Skript with GNU General Public License v3.0 | 4 votes |
@Override public boolean setTime(final int time) { return super.setTime(time, FoodLevelChangeEvent.class, getExpr()); }
Example #23
Source File: NoHungerLossFeature.java From VoxelGamesLibv2 with MIT License | 4 votes |
@GameEvent public void onHungerDepletion(@Nonnull FoodLevelChangeEvent event) { event.setCancelled(true); }
Example #24
Source File: EnvironmentControlListener.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.NORMAL) public void noHunger(final FoodLevelChangeEvent event) { event.setCancelled(true); }
Example #25
Source File: ViewInventoryMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void updateMonitoredHunger(final FoodLevelChangeEvent event) { this.scheduleCheck((Player) event.getEntity()); }
Example #26
Source File: ViewInventoryMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void updateMonitoredHunger(final FoodLevelChangeEvent event) { this.scheduleCheck((Player) event.getEntity()); }