From 7317c6467812478bd41c2265ec423f08f3d07fdc Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Sat, 20 Jul 2019 22:37:23 +0200 Subject: [PATCH] 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 --- changelog.md | 1 + src/main/java/com/garbagemule/MobArena/ArenaImpl.java | 2 +- .../java/com/garbagemule/MobArena/steps/SetHealth.java | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 7642acc..b0d3f95 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java index cc00480..ce53d7b 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java @@ -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() diff --git a/src/main/java/com/garbagemule/MobArena/steps/SetHealth.java b/src/main/java/com/garbagemule/MobArena/steps/SetHealth.java index 48536f8..e9bcd43 100644 --- a/src/main/java/com/garbagemule/MobArena/steps/SetHealth.java +++ b/src/main/java/com/garbagemule/MobArena/steps/SetHealth.java @@ -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); }