better absorption

master
Default 4 years ago
parent f6cda190eb
commit a9f7f68a1b
  1. 10
      src/main/java/com/benjocraeft/sharehealth/PlayerListeners.java
  2. 14
      src/main/java/com/benjocraeft/sharehealth/Sharehealth.java

@ -51,8 +51,8 @@ public class PlayerListeners implements Listener{
break; break;
} }
} }
double originalAbsorptionDamage = -event.getOriginalDamage(DamageModifier.ABSORPTION); double absorbedDamage = -event.getOriginalDamage(DamageModifier.ABSORPTION);
Sharehealth.Instance.onPlayerGotDamage((Player) entity, damage, cause, allowed, originalAbsorptionDamage); Sharehealth.Instance.onPlayerGotDamage((Player) entity, damage, cause, allowed, absorbedDamage);
} }
} }
@ -63,7 +63,8 @@ public class PlayerListeners implements Listener{
Entity cause = event.getDamager(); Entity cause = event.getDamager();
if (entity instanceof Player) { if (entity instanceof Player) {
Sharehealth.Instance.onPlayerGotDamageByEntity((Player)entity, damage, cause); double absorbedDamage = -event.getOriginalDamage(DamageModifier.ABSORPTION);
Sharehealth.Instance.onPlayerGotDamageByEntity((Player)entity, damage, cause, absorbedDamage);
} }
} }
@ -74,7 +75,8 @@ public class PlayerListeners implements Listener{
Block cause = event.getDamager(); Block cause = event.getDamager();
if (entity instanceof Player) { if (entity instanceof Player) {
Sharehealth.Instance.onPlayerGotDamageByBlock((Player)entity, damage, cause); double absorbedDamage = -event.getOriginalDamage(DamageModifier.ABSORPTION);
Sharehealth.Instance.onPlayerGotDamageByBlock((Player)entity, damage, cause, absorbedDamage);
} }
} }

@ -99,33 +99,33 @@ public class Sharehealth extends JavaPlugin {
healthManager.updatePlayer(player); healthManager.updatePlayer(player);
} }
void onPlayerGotDamage(Player player, double damage, DamageCause cause, boolean allowed, double absorptionDamage){ void onPlayerGotDamage(Player player, double damage, DamageCause cause, boolean allowed, double absorbedDamage){
if (isFailed) if (isFailed)
return; return;
double receivedDamage = damage + absorptionDamage; double receivedDamage = damage + absorbedDamage;
if (allowed) if (allowed)
messenger.onPlayerGotDamageMessage(player, receivedDamage, cause); messenger.onPlayerGotDamageMessage(player, receivedDamage, cause);
statistics.onPlayerGotDamage(player, receivedDamage); statistics.onPlayerGotDamage(player, receivedDamage);
if (!healthManager.onPlayerGotDamage(player, damage, absorptionDamage)){ if (!healthManager.onPlayerGotDamage(player, damage, absorbedDamage)){
failed(player); failed(player);
} }
saveStatus(); saveStatus();
} }
void onPlayerGotDamageByEntity(Player player, double damage, Entity cause){ void onPlayerGotDamageByEntity(Player player, double damage, Entity cause, double absorbedDamage){
if (isFailed) if (isFailed)
return; return;
messenger.onPlayerGotDamageMessage(player, damage, cause); messenger.onPlayerGotDamageMessage(player, damage + absorbedDamage, cause);
} }
void onPlayerGotDamageByBlock(Player player, double damage, Block cause){ void onPlayerGotDamageByBlock(Player player, double damage, Block cause, double absorbedDamage){
if (isFailed) if (isFailed)
return; return;
messenger.onPlayerGotDamageMessage(player, damage, cause); messenger.onPlayerGotDamageMessage(player, damage + absorbedDamage, cause);
} }
boolean onPlayerRegainedHealth(Player player, double amount, RegainReason reason){ boolean onPlayerRegainedHealth(Player player, double amount, RegainReason reason){

Loading…
Cancel
Save