package lnmpro.Listeners;

import lnmpro.Main;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import java.util.HashMap;
import java.util.Map;

public class KitListener implements Listener {
    private final Main plugin;

    public KitListener(Main plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        if (plugin.getConfig().getString("kits.sword." + player.getUniqueId()) == null) {
            Map<String, Object> kit = new HashMap<>();
            kit.put("sword", 0);
            plugin.getConfig().set("kits.sword." + player.getUniqueId(), kit);
            plugin.saveConfig();
            plugin.reloadConfig();
        }
        if (plugin.getConfig().getString("kits.uhc." + player.getUniqueId()) == null) {
            Map<String, Object> kit = new HashMap<>();
            int[] shield = new int[]{13, 40};
            int[] water = new int[]{6, 22, 23, 24};
            int[] lava = new int[]{2, 21};
            kit.put("axe", 0);
            kit.put("sword", 1);
            kit.put("lava", lava);
            kit.put("cobweb", 3);
            kit.put("cobblestone", 4);
            kit.put("goldenapple", 5);
            kit.put("water", water);
            kit.put("crossbow", 7);
            kit.put("bow", 8);
            kit.put("arrow", 9);
            kit.put("planks", 17);
            kit.put("pickaxe", 20);
            kit.put("shield", shield);
            plugin.getConfig().set("kits.uhc." + player.getUniqueId(), kit);
            plugin.saveConfig();
            plugin.reloadConfig();
        }
        if (plugin.getConfig().getString("kits.mace." + player.getUniqueId()) == null) {
            Map<String, Object> kit = new HashMap<>();
            int[] strength = new int[]{10, 11, 12, 13, 14, 15, 16, 28, 29, 30};
            int[] speed = new int[]{19, 20, 21, 22, 23, 24, 25, 31, 32, 33};
            int[] totem = new int[]{35, 40};
            int[] enderpearl = new int[]{2, 9, 18, 27};
            int[] goldenapple = new int[]{5, 17};
            int[] windcharge = new int[]{7, 34};
            kit.put("axe", 0);
            kit.put("sword", 1);
            kit.put("enderpearl", enderpearl);
            kit.put("shield", 3);
            kit.put("density", 4);
            kit.put("goldenapple", goldenapple);
            kit.put("breach", 6);
            kit.put("windcharge", windcharge);
            kit.put("elytra", 8);
            kit.put("strength", strength);
            kit.put("speed", speed);
            kit.put("totem", totem);
            kit.put("shulker", 26);
            plugin.getConfig().set("kits.mace." + player.getUniqueId(), kit);
            plugin.saveConfig();
            plugin.reloadConfig();
        }
        if (plugin.getConfig().getString("kits.axe." + player.getUniqueId()) == null) {
            Map<String, Object> kit = new HashMap<>();
            kit.put("axe", 0);
            kit.put("sword", 1);
            kit.put("crossbow", 2);
            kit.put("bow", 3);
            kit.put("arrow", 8);
            kit.put("shield", 40);
            plugin.getConfig().set("kits.axe." + player.getUniqueId(), kit);
            plugin.saveConfig();
            plugin.reloadConfig();
        }
        if (plugin.getConfig().getString("kits.diasmp." + player.getUniqueId()) == null) {
            Map<String, Object> kit = new HashMap<>();
            int[] goldenapple = new int[]{5, 32};
            int[] strength = new int[]{7, 12, 13, 14, 15, 19, 20, 21, 22, 23, 24, 29, 30, 31, 33};
            int[] speed = new int[]{16, 25, 34};
            int[] fireresistance = new int[]{17, 26, 35};
            int[] water = new int[]{4, 10, 11};
            int[] xp = new int[]{18, 27};
            kit.put("axe", 0);
            kit.put("sword", 1);
            kit.put("enderpearl", 2);
            kit.put("log", 3);
            kit.put("water", water);
            kit.put("goldenapple", goldenapple);
            kit.put("cobweb", 6);
            kit.put("strength", strength);
            kit.put("totem", 8);
            kit.put("pickaxe", 9);
            kit.put("speed", speed);
            kit.put("fireresistance", fireresistance);
            kit.put("xp", xp);
            kit.put("chorusfruit", 28);
            kit.put("shield", 40);
            plugin.getConfig().set("kits.diasmp." + player.getUniqueId(), kit);
            plugin.saveConfig();
            plugin.reloadConfig();
        }
    }
}