void onEvent(PotionEffectRemoveEvent event) { // The NMS code assumes that a potion effect is the only way to get // absorption hearts, so when the effect is removed, it simply removes // the same amount of absorption that it added initially. If any of that // eats into the shield, we refund the difference. if(PotionEffectType.ABSORPTION.equals(event.getEffect().getType())) { double newAbsorption = Math.max(0, getAbsorption() - 4 * (1 + event.getEffect().getAmplifier())); if(newAbsorption < shieldHealth) { logger.fine("Compensating for removal of absorption " + event.getEffect().getAmplifier() + " effect, which will reduce absorption hearts to " + newAbsorption + ", which is below shield health of " + shieldHealth); addAbsorption(shieldHealth - newAbsorption); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPotionRemove(PotionEffectRemoveEvent event) { ShieldPlayerModule shield = getShield(event.getEntity()); if(shield != null) shield.onEvent(event); }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPotionEffectRemove(PotionEffectRemoveEvent event) { if (this.isObserving(event.getEntity())) { event.setCancelled(true); } }
@EventHandler(priority = EventPriority.MONITOR) public void onViewingEntityRemoveEffect(PotionEffectRemoveEvent event) { if (event.getEntity() instanceof Player) { updateNextTick((Player)event.getEntity()); } }