diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java
index d2eb8929..31c21f25 100644
--- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java
+++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RestoreHealth.java
@@ -23,6 +23,10 @@ public class RestoreHealth extends DoubleStat implements PlayerConsumable {
@Override
public void onConsume(@NotNull VolatileMMOItem mmo, @NotNull Player player, boolean vanillaEating) {
+
+ // (Fixes MMOItems#1579) Cannot restore health if player is dying
+ if (player.isDead() || player.getHealth() <= 0) return;
+
if (!mmo.hasData(ItemStats.RESTORE_HEALTH)) return;
final DoubleData d = (DoubleData) mmo.getData(ItemStats.RESTORE_HEALTH);
diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java
index 58590938..e6b68020 100644
--- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java
+++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/MMOUtils.java
@@ -343,25 +343,26 @@ public class MMOUtils {
}
/**
- * @param player Player to heal
- * @param heal Heal amount
- *
- * Negative values are just ignored
+ * @param entity Player to heal
+ * @param heal Heal amount. Negative values are just ignored
*/
- public static void heal(@NotNull LivingEntity player, double heal) {
- heal(player, heal, true);
+ public static void heal(@NotNull LivingEntity entity, double heal) {
+ heal(entity, heal, true);
}
/**
- * @param player Player to heal
+ * @param entity Living entity to heal
* @param heal Heal amount
- * @param allowNegatives If passing a negative health value will damage the entity x)
- *
+ * @param allowNegatives If passing a negative health value will damage the entity
* If false
, negative values are just ignored
*/
- public static void heal(@NotNull LivingEntity player, double heal, boolean allowNegatives) {
- if (heal > 0 || allowNegatives)
- player.setHealth(Math.min(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), player.getHealth() + heal));
+ public static void heal(@NotNull LivingEntity entity, double heal, boolean allowNegatives) {
+ if (heal == 0) return;
+ if (entity.isDead() || entity.getHealth() <= 0) return;
+ if (heal < 0 && !allowNegatives) return;
+
+ final double maxHealth = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
+ entity.setHealth(Math.min(maxHealth, entity.getHealth() + heal));
}
//endregion