Fixed heal consumables being able to revive players when consumed late

This commit is contained in:
Jules 2024-06-21 12:52:06 -07:00
parent 672b9b6c21
commit a85b4d05c3
2 changed files with 17 additions and 12 deletions

View File

@ -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);

View File

@ -343,25 +343,26 @@ public class MMOUtils {
}
/**
* @param player Player to heal
* @param heal Heal amount
* <br>
* 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)
* <br>
* @param allowNegatives If passing a negative health value will damage the entity
* If <code>false</code>, 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