Use max health value instead of base value in SetHealth step.

This commit changes the SetHealth step such that it uses the player's own value for max health rather than the generic base value. As a result, players who join holding items that lower their max health will be missing health as soon as they join the lobby. But because food levels are maxed and locked, the health will quickly regenerate.

Unfortunately, players who join with a higher health value than the base max health value will have their health capped to the base max health value on the way out of the arena. This was also the case before this commit, but it is worth mentioning again for completeness.

These odd side effects are currently "necessary" because the effects of items that change max health values for players don't take immediate effect in the same tick as they are added/removed, so because MobArena's join sequence is synchronous, we can't feasibly "get it right".

Fixes #545
This commit is contained in:
Andreas Troelsen 2019-07-20 22:37:23 +02:00
parent 88ddbe5ac6
commit 7317c64678
3 changed files with 7 additions and 3 deletions

View File

@ -11,6 +11,7 @@ These changes will (most likely) be included in the next version.
## [Unreleased]
- MobArena no longer crashes when players try to join with items that lower their max health below the default of 20. Players with lower max health will notice missing health in the lobby, but it will quickly regenerate to full.
- Food levels no longer deplete for players in the lobby and spectator area.
## [0.103.2] - 2019-04-23

View File

@ -835,7 +835,7 @@ public class ArenaImpl implements Arena
return;
}
double full = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
double full = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
p.setHealth(full);
plugin.getServer().getScheduler()

View File

@ -24,13 +24,16 @@ class SetHealth extends PlayerStep {
player.setRemainingAir(NORMAL_AIR);
player.setFireTicks(NORMAL_FIRE);
double full = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
double full = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
player.setHealth(full);
}
@Override
public void undo() {
player.setHealth(health);
double max = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double capped = Math.min(health, max);
player.setHealth(capped);
player.setFireTicks(fire);
player.setRemainingAir(air);
}