diff --git a/changelog.md b/changelog.md index af6bf43..0e47188 100644 --- a/changelog.md +++ b/changelog.md @@ -14,6 +14,7 @@ These changes will (most likely) be included in the next version. - MobArena no longer touches the `flySpeed` player attribute when players join an arena. This should fix issues where a crash would result in players being "locked in the air" when trying to fly outside of the arena. It also introduces compatibility with plugins that use flight to augment player abilities. - Fixed a bug introduced by a breaking API change in Spigot where a player with a nearly full inventory might cause item rewards to change stack amounts. - MobArena no longer uncancels teleport events that occur outside of its own context when players have the `mobarena.admin.teleport` permission. This fixes a bug where the permission could override the cancellation of events that weren't related to MobArena. +- When resetting player health, MobArena now uses the player max health attribute base value rather than a fixed value of 20. This fixes crashes associated with max health values lower than 20, and ensures that players always get a full heal with values higher than 20. Thanks to: - minoneer for help with fixing and testing the teleport bug diff --git a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java index 0c910f3..cc00480 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java @@ -35,6 +35,7 @@ import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.attribute.Attribute; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.configuration.ConfigurationSection; @@ -834,7 +835,9 @@ public class ArenaImpl implements Arena return; } - p.setHealth(20.0); + double full = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); + p.setHealth(full); + plugin.getServer().getScheduler() .scheduleSyncDelayedTask(plugin, () -> revivePlayer(p)); endArena(); diff --git a/src/main/java/com/garbagemule/MobArena/steps/SetHealth.java b/src/main/java/com/garbagemule/MobArena/steps/SetHealth.java index 1a1ecce..48536f8 100644 --- a/src/main/java/com/garbagemule/MobArena/steps/SetHealth.java +++ b/src/main/java/com/garbagemule/MobArena/steps/SetHealth.java @@ -1,9 +1,9 @@ package com.garbagemule.MobArena.steps; +import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; class SetHealth extends PlayerStep { - private static final double FULL_HEALTH = 20.0; private static final int NORMAL_FIRE = -20; private static final int NORMAL_AIR = 300; @@ -23,7 +23,9 @@ class SetHealth extends PlayerStep { player.setRemainingAir(NORMAL_AIR); player.setFireTicks(NORMAL_FIRE); - player.setHealth(FULL_HEALTH); + + double full = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); + player.setHealth(full); } @Override