I want that if the player takes damage and the player permanently loses that hearts.
import org.bukkit.entity.Player;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.EventHandler;
@EventHandler
public void EntityDamage(EntityDamageEvent event) {
Entity e = event.getEntity();
if (e instanceof Player) {
Player player = (Player) e;
double newhealth = player.getHealth();
player.setMaxHealth(newhealth);
}
}
i use this code but this only reduces hearts after the second damage event
player.getHealth()gets you the health of the player before its modification. By looking into the event's documentation i found this solution :You can calculate the new health with
event.getFinalDamage():Hope it will help you !
PS: If you just want the player not to regenerate you can change the 'NaturalRegeneration' gamerule (but it will still allow the regeneration effect)