package dev.micle.loginprotection.events.common;

import dev.micle.loginprotection.data.ProtectedPlayer;
import dev.micle.loginprotection.data.ProtectedPlayerManager;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class OnPlayerDamageEventHandler {
    @SubscribeEvent
    public void LivingDamageEvent(LivingDamageEvent event) {
        if (!(event.getEntity() instanceof Player player)) {
            return;
        }

        ProtectedPlayer protectedPlayer = ProtectedPlayerManager.getPlayer(player.getUUID());
        if (protectedPlayer == null || protectedPlayer.getState().equals(ProtectedPlayer.State.ACTIVE)) {
            return;
        }

        event.setCanceled(true);
    }
}
