public void heal(EntityRegainHealthEvent source) { this.server.getPluginManager().callEvent(source); if (source.isCancelled()) { return; } float targetHealth = this.getHealth() + source.getAmount(); if (targetHealth > getMaxHealth()) targetHealth = getMaxHealth(); this.setHealth(targetHealth); }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityRegainHealth(final EntityRegainHealthEvent event) { if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers()) { event.setCancelled(true); } }
@EventHandler public void onHealthRegenerate(EntityRegainHealthEvent event) { EntityType entityType = event.getEntityType(); if (entityType.equals(EntityType.PLAYER)) { if (GameManager.INSTANCE.getSession((Player) event.getEntity()) == null) return; if (event.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.SATIATED)) { event.setCancelled(true); } } }