package de.viper.survivalplus.listeners;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.Material;
import org.bukkit.inventory.PlayerInventory;

public class FirstJoinListener implements Listener {

    @EventHandler
    public void onPlayerFirstJoin(PlayerJoinEvent event) {
        if (event.getPlayer().hasPlayedBefore()) {
            return; // Nur für den ersten Join
        }

        // Erstelle ein ItemStack für einen Trank (z.B. Heiltrank)
        ItemStack potion = new ItemStack(Material.POTION, 1);

        if (potion.getItemMeta() instanceof PotionMeta) {
            PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
            PotionEffect effect = new PotionEffect(PotionEffectType.REGENERATION, 600, 1);
            potionMeta.addCustomEffect(effect, true);
            potion.setItemMeta(potionMeta);
        }

        // Füge das Trank-Item zum Inventar des Spielers hinzu
        PlayerInventory inventory = event.getPlayer().getInventory();
        inventory.addItem(potion);
    }
}
