Java Code Examples for org.bukkit.event.entity.EntityRegainHealthEvent#isCancelled()
The following examples show how to use
org.bukkit.event.entity.EntityRegainHealthEvent#isCancelled() .
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: 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); }