org.bukkit.event.entity.EntityRegainHealthEvent Java Examples
The following examples show how to use
org.bukkit.event.entity.EntityRegainHealthEvent.
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: DeathListener.java From Civs with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onFoodHeal(EntityRegainHealthEvent event) { if (event.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED || ConfigManager.getInstance().getFoodHealInCombat()) { return; } if (!(event.getEntity() instanceof Player)) { return; } Player player = (Player) event.getEntity(); Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId()); if (!civilian.isInCombat()) { return; } event.setCancelled(true); }
Example #2
Source File: EntityListener.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onRegainHealth(EntityRegainHealthEvent rhe) { if (rhe.getEntityType() != EntityType.PLAYER) { return; } Player player = (Player) rhe.getEntity(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } if (player.getHealth() >= player.getMaxHealth()) { game.setPlayerDamager(player, null); } }
Example #3
Source File: PercentHealthObjectiveModule.java From UHC with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void on(EntityRegainHealthEvent event) { final Entity entity = event.getEntity(); if (!(entity instanceof Player)) { return; } // If the event was cancelled, another plugin may have edited the health // Update instantly with the current health final Player player = (Player) entity; if (event.isCancelled()) { updatePlayer(player); return; } // Calculate new health based on regen amount instead of waiting for one tick final double oldHealth = player.getHealth(); final double healAmount = event.getAmount(); final double newHealth = Math.min(oldHealth + healAmount, player.getMaxHealth()); updatePlayer(player, newHealth); }
Example #4
Source File: RegainHealth.java From MarriageMaster with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onHeal(EntityRegainHealthEvent event) { if(event.getEntity() instanceof Player) { MarriagePlayer player = plugin.getPlayerData((Player) event.getEntity()); if(player.isMarried()) { Marriage marriage = player.getNearestPartnerMarriageData(); if(marriage != null && marriage.inRangeSquared(range)) { BonusHealEvent bonusHealEvent = new BonusHealEvent(player, marriage, event.getAmount() * multiplier, event.getRegainReason()); plugin.getServer().getPluginManager().callEvent(bonusHealEvent); if(!bonusHealEvent.isCancelled()) { event.setAmount(bonusHealEvent.getAmount()); } } } } }
Example #5
Source File: ViewInventoryMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void updateMonitoredHealth(final EntityRegainHealthEvent event) { if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); if (player.getHealth() == player.getMaxHealth()) return; this.scheduleCheck((Player) event.getEntity()); } }
Example #6
Source File: ViewInventoryMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void updateMonitoredHealth(final EntityRegainHealthEvent event) { if(event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); if(player.getHealth() == player.getMaxHealth()) return; this.scheduleCheck((Player) event.getEntity()); } }
Example #7
Source File: HorseHealingModule.java From UHC with MIT License | 5 votes |
@EventHandler(ignoreCancelled = true) public void on(EntityRegainHealthEvent event) { if (isEnabled()) return; if (event.getEntityType() != EntityType.HORSE) return; event.setCancelled(true); }
Example #8
Source File: IndicatorListener.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityRegainHealth(EntityRegainHealthEvent event) { if (Settings.INDICATOR_ENABLE.getValue("gainHealth")) { if ((event.getEntity() instanceof Player && Settings.INDICATOR_SHOW_FOR_PLAYERS.getValue("gainHealth")) || Settings.INDICATOR_SHOW_FOR_MOBS.getValue("gainHealth")) { Location l = event.getEntity().getLocation().clone(); l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("gainHealth")); HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("gainHealth"), true, Settings.INDICATOR_FORMAT.getValue("gainHealth", "default") + "+" + event.getAmount() + " " + HEART_CHARACTER); } } }
Example #9
Source File: BonusHealEvent.java From MarriageMaster with GNU General Public License v3.0 | 5 votes |
/** * @param player The player that gets a heal bonus. * @param marriageData The marriage data of the player. * @param amount The amount of health the entity will regain. * @param regainReason The RegainReason detailing the reason for the entity regaining health. */ public BonusHealEvent(@NotNull MarriagePlayer player, @NotNull Marriage marriageData, final double amount, @NotNull final EntityRegainHealthEvent.RegainReason regainReason) { this.player = player; this.marriageData = marriageData; this.amount = amount; this.regainReason = regainReason; }
Example #10
Source File: UHPluginListener.java From KTP with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntityRegainHealth(final EntityRegainHealthEvent ev) { if (ev.getRegainReason() == RegainReason.SATIATED) ev.setCancelled(true); if (ev.getEntity() instanceof Player) { Bukkit.getScheduler().runTaskLater(this.p, new BukkitRunnable() { @Override public void run() { p.updatePlayerListName((Player)ev.getEntity()); } }, 1L); } }
Example #11
Source File: EntityListener.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void entityRegainHealthEvent(EntityRegainHealthEvent event) { if (listenerService.shouldCancelEvent(event)) { event.setAmount(0); event.setCancelled(true); } }
Example #12
Source File: EntityListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldCancelRegainHealthEvent() { // given EntityRegainHealthEvent event = mock(EntityRegainHealthEvent.class); given(listenerService.shouldCancelEvent(event)).willReturn(true); // when listener.entityRegainHealthEvent(event); // then verify(listenerService).shouldCancelEvent(event); verify(event).setCancelled(true); verify(event).setAmount(0); }
Example #13
Source File: EntityListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldNotCancelRegainedHealth() { // given EntityRegainHealthEvent event = mock(EntityRegainHealthEvent.class); given(listenerService.shouldCancelEvent(event)).willReturn(false); // when listener.entityRegainHealthEvent(event); // then verify(listenerService).shouldCancelEvent(event); verifyNoInteractions(event); }
Example #14
Source File: ObserverModule.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onViewingEntityRegainHealth(EntityRegainHealthEvent event) { if (event.getEntity() instanceof Player) { refreshView(event.getEntity().getUniqueId()); } }
Example #15
Source File: BonusHealEvent.java From MarriageMaster with GNU General Public License v3.0 | 2 votes |
/** * Gets the reason for why the player is regaining health. * * @return A RegainReason detailing the reason for the entity regaining health. */ public @NotNull EntityRegainHealthEvent.RegainReason getRegainReason() { return regainReason; }