Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
34 kB
1
Indexable
Never
package org.lifestealsmp.itemskinner;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

import dev.lone.itemsadder.api.CustomStack;
import dev.lone.itemsadder.api.ItemsAdder;
import shwendel.durabilityapi.DurabilityAPI;


public class main extends JavaPlugin implements Listener{
	
	private FileConfiguration data;
    private File dfile;
    
    private FileConfiguration furnitures;
    private File ffile;
    
    private FileConfiguration hats;
    private File hfile;
    
    private FileConfiguration helmets;
    private File helmetsFile;

    public void onEnable() {
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
        saveDefaultConfig();

        setupFiles();
    }
    
    @EventHandler
	public void onPlayerInteract(PlayerInteractEvent event) {
	    Player player = event.getPlayer();
	    ItemStack item = player.getInventory().getItemInMainHand();

	    // Check if the player is holding an item
	    if (item == null || !item.hasItemMeta()) {
	        return;
	    }

	    ItemMeta meta = item.getItemMeta();
	    
	    // Message the player the type of item they are holding
	    Material itemType = item.getType();
	    player.sendMessage(ChatColor.YELLOW + "You are holding: " + itemType.toString());

	    // Send the current durability of the item using ItemsAdder API
	    int currentDurability = ItemsAdder.getCustomItemDurability(item);
	    int maxDurability = ItemsAdder.getCustomItemMaxDurability(item);
	    if (maxDurability > 0) { // Assuming a value of 0 means it's not damageable
	        player.sendMessage(ChatColor.BLUE + "Current durability: " + currentDurability + "/" + maxDurability);
	    } else {
	        player.sendMessage(ChatColor.GRAY + "This item doesn't have durability.");
	    }

	    // Check if the item has custom model data
	    if (meta.hasCustomModelData()) {
	        int customModelData = meta.getCustomModelData();
	        player.sendMessage(ChatColor.GREEN + "This item has Custom Model Data: " + customModelData);
	    } else {
	        player.sendMessage(ChatColor.RED + "This item does not have Custom Model Data.");
	    }
	}

    public void setupFiles() {
        // data.yml setup
        dfile = new File(this.getDataFolder(), "data.yml");
        setupFile(dfile);
        data = YamlConfiguration.loadConfiguration(dfile);
        
        // furnitures.yml setup
        ffile = new File(this.getDataFolder(), "furnitures.yml");
        setupFile(ffile);
        furnitures = YamlConfiguration.loadConfiguration(ffile);

        // hats.yml setup
        hfile = new File(this.getDataFolder(), "hats.yml");
        setupFile(hfile);
        hats = YamlConfiguration.loadConfiguration(hfile);

        // helmets.yml setup
        helmetsFile = new File(this.getDataFolder(), "helmets.yml");
        setupFile(helmetsFile);
        helmets = YamlConfiguration.loadConfiguration(helmetsFile);
    }

    public void setupFile(File file) {
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create " + file.getName() + "!");
            }
        }
    }

    public FileConfiguration getData() {
        return data;
    }

    public FileConfiguration getFurnitures() {
        return furnitures;
    }

    public FileConfiguration getHats() {
        return hats;
    }

    public FileConfiguration getHelmets() {
        return helmets;
    }

    public void saveData() {
        saveFile(data, dfile);
    }

    public void saveFurnitures() {
        saveFile(furnitures, ffile);
    }

    public void saveHats() {
        saveFile(hats, hfile);
    }

    public void saveHelmets() {
        saveFile(helmets, helmetsFile);
    }

    public void saveFile(FileConfiguration config, File file) {
        try {
            config.save(file);
        } catch (IOException e) {
            Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save " + file.getName() + "!");
        }
    }

    public void reloadData() {
        data = YamlConfiguration.loadConfiguration(dfile);
    }

    public void reloadFurnitures() {
        furnitures = YamlConfiguration.loadConfiguration(ffile);
    }

    public void reloadHats() {
        hats = YamlConfiguration.loadConfiguration(hfile);
    }

    public void reloadHelmets() {
        helmets = YamlConfiguration.loadConfiguration(helmetsFile);
    }
	
	@Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		if(cmd.getName().equalsIgnoreCase("skin") || cmd.getName().equalsIgnoreCase("skins")) {
			if (sender instanceof Player) {
				Player player = (Player) sender;
				SkinStationInventory(player);
			} else {
	            sender.sendMessage("This command can only be run by a player!");
	        }
		}
		return false;
	}
	
	public void SkinStationInventory(Player player) {
		Inventory inv = Bukkit.createInventory(null, 27, "Skin Station");
		ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
		ItemMeta blankMeta = blank.getItemMeta();

		blankMeta.setDisplayName("§r"); // The §r is a reset color code which effectively hides the item name.
		blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
		blank.setItemMeta(blankMeta);

		// Fill empty slots with the blank item
	    for (int i = 0; i < inv.getSize(); i++) {
	        if (inv.getItem(i) == null) {
	            inv.setItem(i, blank);
	        }
	    }
	    // Create the Furniture item
	    ItemStack furniture = new ItemStack(Material.PAPER);
	    ItemMeta furnitureMeta = furniture.getItemMeta();
	    furnitureMeta.setDisplayName("Furniture");
	    furnitureMeta.setCustomModelData(10029);
	    furnitureMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    furniture.setItemMeta(furnitureMeta);

	    // Create the Hats item
	    ItemStack hats = new ItemStack(Material.FEATHER);
	    ItemMeta hatsMeta = hats.getItemMeta();
	    hatsMeta.setDisplayName("Hats");
	    hatsMeta.setCustomModelData(10000);
	    hatsMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    hats.setItemMeta(hatsMeta);

	    // Create the Armor item
	    ItemStack armor = new ItemStack(Material.DIAMOND_CHESTPLATE);
	    ItemMeta armorMeta = armor.getItemMeta();
	    armorMeta.setDisplayName("Armor");
	    armorMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    armor.setItemMeta(armorMeta);

	    // Create the Tools item
	    ItemStack tools = new ItemStack(Material.DIAMOND_SWORD);
	    ItemMeta toolsMeta = tools.getItemMeta();
	    toolsMeta.setDisplayName("Tools");
	    toolsMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
	    toolsMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    tools.setItemMeta(toolsMeta);

	    // Add the items to the specified slots (0-based index)
	    inv.setItem(10, furniture); // Slot 11
	    inv.setItem(12, hats);      // Slot 13
	    inv.setItem(14, armor);     // Slot 15
	    inv.setItem(16, tools);     // Slot 17
	    player.openInventory(inv);
	}
	
	private Map<UUID, Integer> currentPages = new HashMap<>();
	private Map<UUID, Map<String, Long>> lastFurnitureClaim = new HashMap<>();


	public void FurnitureInventory(Player player, int page) {
	    Inventory inv = Bukkit.createInventory(null, 27, "Furniture Skins");
	    ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
	    ItemMeta blankMeta = blank.getItemMeta();

	    blankMeta.setDisplayName("§r"); // The §r is a reset color code which effectively hides the item name.
	    blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
	    blank.setItemMeta(blankMeta);

	    ItemStack backButton = new ItemStack(Material.RED_WOOL);
	    ItemMeta backMeta = backButton.getItemMeta();
	    backMeta.setDisplayName("Back Page");
	    backButton.setItemMeta(backMeta);

	    ItemStack forwardButton = new ItemStack(Material.GREEN_WOOL);
	    ItemMeta forwardMeta = forwardButton.getItemMeta();
	    forwardMeta.setDisplayName("Next Page");
	    forwardButton.setItemMeta(forwardMeta);

	    inv.setItem(21, backButton);
	    inv.setItem(23, forwardButton);

	    String uuid = player.getUniqueId().toString();

	    FileConfiguration dataConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "data.yml"));
	    List<String> playerFurnitures = dataConfig.contains(uuid) ? dataConfig.getStringList(uuid + ".Furnitures") : new ArrayList<>();

	    // Check for ItemSkinner.MVP permission and replace player's furniture list with all furnitures if they have it.
	    if (player.hasPermission("ItemSkinner.MVP")) {
	        playerFurnitures = new ArrayList<>(getFurnitures().getKeys(false));
	    }

	    int startIndex = page * 18;
	    int endIndex = Math.min(startIndex + 18, playerFurnitures.size());

	    Map<String, Long> playerFurnitureCooldowns = lastFurnitureClaim.getOrDefault(player.getUniqueId(), new HashMap<>());

	    for (int i = startIndex; i < endIndex; i++) {
	        String furniture = playerFurnitures.get(i);

	        if (getFurnitures().contains(furniture)) {
	            String itemType = getFurnitures().getString(furniture + ".Item_Type");
	            int customModelData = getFurnitures().getInt(furniture + ".Custom Model Data");
	            String displayName = getFurnitures().getString(furniture + ".Display_Name");
	            int cooldownMinutes = getFurnitures().getInt(furniture + ".Cooldown");

	            ItemStack itemStack = new ItemStack(Material.valueOf(itemType));
	            ItemMeta meta = itemStack.getItemMeta();

	            meta.setCustomModelData(customModelData);
	            meta.setDisplayName(displayName);

	            long lastClaimTime = playerFurnitureCooldowns.getOrDefault(furniture, 0L);
	            long remainingCooldownMillis = (cooldownMinutes * 60 * 1000) - (System.currentTimeMillis() - lastClaimTime);

	            if (remainingCooldownMillis > 0) {
	                long remainingMinutes = TimeUnit.MILLISECONDS.toMinutes(remainingCooldownMillis);
	                List<String> lore = new ArrayList<>();
	                lore.add("Cooldown: " + remainingMinutes + " mins");
	                meta.setLore(lore);
	            }

	            meta.getPersistentDataContainer().set(new NamespacedKey(this, "furnitureKey"), PersistentDataType.STRING, furniture);
	            itemStack.setItemMeta(meta);
	            inv.addItem(itemStack);
	        }
	    }

	    for (int i = 0; i < inv.getSize(); i++) {
	        if (inv.getItem(i) == null) {
	            inv.setItem(i, blank);
	        }
	    }

	    player.openInventory(inv);
	}


	
	private Map<UUID, Integer> hatCurrentPages = new HashMap<>();
	private Map<UUID, Map<String, Long>> lastHatClaim = new HashMap<>();

	public void HatsInventory(Player player, int page) {
	    Inventory inv = Bukkit.createInventory(null, 27, "Hat Skins");
	    ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
	    ItemMeta blankMeta = blank.getItemMeta();

	    blankMeta.setDisplayName("§r"); // The §r is a reset color code which effectively hides the item name.
	    blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
	    blank.setItemMeta(blankMeta);

	    ItemStack backButton = new ItemStack(Material.RED_WOOL);
	    ItemMeta backMeta = backButton.getItemMeta();
	    backMeta.setDisplayName("Back Page");
	    backButton.setItemMeta(backMeta);

	    ItemStack forwardButton = new ItemStack(Material.GREEN_WOOL);
	    ItemMeta forwardMeta = forwardButton.getItemMeta();
	    forwardMeta.setDisplayName("Next Page");
	    forwardButton.setItemMeta(forwardMeta);

	    inv.setItem(21, backButton);
	    inv.setItem(23, forwardButton);

	    String uuid = player.getUniqueId().toString();

	    FileConfiguration dataConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "data.yml"));
	    List<String> playerHats = dataConfig.contains(uuid) ? dataConfig.getStringList(uuid + ".Hats") : new ArrayList<>();

	    // Check for ItemSkinner.MVP permission and replace player's hats list with all hats if they have it.
	    if (player.hasPermission("ItemSkinner.MVP")) {
	        playerHats = new ArrayList<>(getHats().getKeys(false));
	    }

	    int startIndex = page * 18;
	    int endIndex = Math.min(startIndex + 18, playerHats.size());

	    Map<String, Long> playerHatCooldowns = lastHatClaim.getOrDefault(player.getUniqueId(), new HashMap<>());

	    for (int i = startIndex; i < endIndex; i++) {
	        String hat = playerHats.get(i);

	        if (getHats().contains(hat)) {
	            String itemType = getHats().getString(hat + ".Item_Type");
	            int customModelData = getHats().getInt(hat + ".Custom Model Data");
	            String displayName = getHats().getString(hat + ".Display_Name");
	            int cooldownMinutes = getHats().getInt(hat + ".Cooldown");

	            ItemStack itemStack = new ItemStack(Material.valueOf(itemType));
	            ItemMeta meta = itemStack.getItemMeta();

	            meta.setCustomModelData(customModelData);
	            meta.setDisplayName(displayName);

	            long lastClaimTime = playerHatCooldowns.getOrDefault(hat, 0L);
	            long remainingCooldownMillis = (cooldownMinutes * 60 * 1000) - (System.currentTimeMillis() - lastClaimTime);

	            if (remainingCooldownMillis > 0) {
	                long remainingMinutes = TimeUnit.MILLISECONDS.toMinutes(remainingCooldownMillis);
	                List<String> lore = new ArrayList<>();
	                lore.add("Cooldown: " + remainingMinutes + " mins");
	                meta.setLore(lore);
	            }

	            meta.getPersistentDataContainer().set(new NamespacedKey(this, "hatKey"), PersistentDataType.STRING, hat);
	            itemStack.setItemMeta(meta);
	            inv.addItem(itemStack);
	        }
	    }

	    for (int i = 0; i < inv.getSize(); i++) {
	        if (inv.getItem(i) == null) {
	            inv.setItem(i, blank);
	        }
	    }

	    player.openInventory(inv);
	}
	
	public void ArmorCategoriesInventory(Player player) {
	    Inventory inv = Bukkit.createInventory(null, 27, "Armor Categories");
	    ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
	    ItemMeta blankMeta = blank.getItemMeta();

	    blankMeta.setDisplayName("§r"); // The §r is a reset color code which effectively hides the item name.
	    blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
	    blank.setItemMeta(blankMeta);

	    // Fill empty slots with the blank item
	    for (int i = 0; i < inv.getSize(); i++) {
	        if (inv.getItem(i) == null) {
	            inv.setItem(i, blank);
	        }
	    }

	 // Creating the Diamond Helmet item
	    ItemStack helmet = new ItemStack(Material.DIAMOND_HELMET);
	    ItemMeta helmetMeta = helmet.getItemMeta();
	    helmetMeta.setDisplayName("Helmet Skins");
	    helmetMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    helmet.setItemMeta(helmetMeta);

	    // Creating the Diamond Chestplate item
	    ItemStack chestplate = new ItemStack(Material.DIAMOND_CHESTPLATE);
	    ItemMeta chestplateMeta = chestplate.getItemMeta();
	    chestplateMeta.setDisplayName("Chestplate Skins");
	    chestplateMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    chestplate.setItemMeta(chestplateMeta);

	    // Creating the Diamond Leggings item
	    ItemStack leggings = new ItemStack(Material.DIAMOND_LEGGINGS);
	    ItemMeta leggingsMeta = leggings.getItemMeta();
	    leggingsMeta.setDisplayName("Leggings Skins");
	    leggingsMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    leggings.setItemMeta(leggingsMeta);

	    // Creating the Diamond Boots item
	    ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS);
	    ItemMeta bootsMeta = boots.getItemMeta();
	    bootsMeta.setDisplayName("Boots Skins");
	    bootsMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    boots.setItemMeta(bootsMeta);


	    // Setting the items to the respective slots in the inventory
	    inv.setItem(10, helmet);      // Slot 10 (0-based index)
	    inv.setItem(12, chestplate); // Slot 12 (0-based index)
	    inv.setItem(14, leggings);   // Slot 14 (0-based index)
	    inv.setItem(16, boots);      // Slot 16 (0-based index)

	    // Adding the back button
	    ItemStack backButton = new ItemStack(Material.RED_WOOL);
	    ItemMeta backMeta = backButton.getItemMeta();
	    backMeta.setDisplayName("Back");
	    backButton.setItemMeta(backMeta);

	    inv.setItem(22, backButton); // Slot 21 (0-based index)

	    player.openInventory(inv);
	}
	
	public void ToolCategoriesInventory(Player player) {
	    Inventory inv = Bukkit.createInventory(null, 27, "Tool Categories");
	    ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
	    ItemMeta blankMeta = blank.getItemMeta();

	    blankMeta.setDisplayName("§r"); // The §r is a reset color code which effectively hides the item name.
	    blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
	    blank.setItemMeta(blankMeta);

	    // Fill empty slots with the blank item
	    for (int i = 0; i < inv.getSize(); i++) {
	        if (inv.getItem(i) == null) {
	            inv.setItem(i, blank);
	        }
	    }

	    // Creating the Diamond Pickaxe item
	    ItemStack pickaxe = new ItemStack(Material.DIAMOND_PICKAXE);
	    ItemMeta pickaxeMeta = pickaxe.getItemMeta();
	    pickaxeMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    pickaxe.setItemMeta(pickaxeMeta);

	    // Creating the Diamond Sword item
	    ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
	    ItemMeta swordMeta = sword.getItemMeta();
	    swordMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    sword.setItemMeta(swordMeta);

	    // Creating the Diamond Axe item
	    ItemStack axe = new ItemStack(Material.DIAMOND_AXE);
	    ItemMeta axeMeta = axe.getItemMeta();
	    axeMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    axe.setItemMeta(axeMeta);

	    // Creating the Diamond Shovel item
	    ItemStack shovel = new ItemStack(Material.DIAMOND_SHOVEL);
	    ItemMeta shovelMeta = shovel.getItemMeta();
	    shovelMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
	    shovel.setItemMeta(shovelMeta);

	    // Setting the items to the respective slots in the inventory
	    inv.setItem(10, pickaxe);  // Slot 10 (0-based index)
	    inv.setItem(12, sword);   // Slot 12 (0-based index)
	    inv.setItem(14, axe);     // Slot 14 (0-based index)
	    inv.setItem(16, shovel);  // Slot 16 (0-based index)

	    // Adding the back button
	    ItemStack backButton = new ItemStack(Material.RED_WOOL);
	    ItemMeta backMeta = backButton.getItemMeta();
	    backMeta.setDisplayName("Back");
	    backButton.setItemMeta(backMeta);

	    inv.setItem(22, backButton); // Slot 21 (0-based index)

	    player.openInventory(inv);
	}
	
	private Map<UUID, Integer> helmetCurrentPages = new HashMap<>();
	private Map<UUID, Map<String, Long>> lastHelmetClaim = new HashMap<>();

	public void HelmetSkinsInventory(Player player, int page) {
	    Inventory inv = Bukkit.createInventory(null, 27, "Helmet Skins");
	    ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
	    ItemMeta blankMeta = blank.getItemMeta();

	    blankMeta.setDisplayName("§r"); // The §r is a reset color code which effectively hides the item name.
	    blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
	    blank.setItemMeta(blankMeta);

	    ItemStack backButton = new ItemStack(Material.RED_WOOL);
	    ItemMeta backMeta = backButton.getItemMeta();
	    backMeta.setDisplayName("Back Page");
	    backButton.setItemMeta(backMeta);

	    ItemStack forwardButton = new ItemStack(Material.GREEN_WOOL);
	    ItemMeta forwardMeta = forwardButton.getItemMeta();
	    forwardMeta.setDisplayName("Next Page");
	    forwardButton.setItemMeta(forwardMeta);

	    inv.setItem(21, backButton);
	    inv.setItem(23, forwardButton);

	    String uuid = player.getUniqueId().toString();

	    FileConfiguration dataConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "data.yml"));
	    List<String> playerHelmets = dataConfig.contains(uuid) ? dataConfig.getStringList(uuid + ".HelmetSkins") : new ArrayList<>();

	    if (player.hasPermission("ItemSkinner.MVP")) {
	        playerHelmets = new ArrayList<>(getHelmets().getKeys(false));
	    }

	    int startIndex = page * 18;
	    int endIndex = Math.min(startIndex + 18, playerHelmets.size());

	    Map<String, Long> playerHelmetCooldowns = lastHelmetClaim.getOrDefault(player.getUniqueId(), new HashMap<>());

	    for (int i = startIndex; i < endIndex; i++) {
	        String helmet = playerHelmets.get(i);

	        if (getHelmets().contains(helmet)) {
	            String itemType = getHelmets().getString(helmet + ".Item_Type");
	            int customModelData = getHelmets().getInt(helmet + ".Custom Model Data");
	            String displayName = getHelmets().getString(helmet + ".Display_Name");
	            int cooldownMinutes = getHelmets().getInt(helmet + ".Cooldown");

	            ItemStack itemStack = new ItemStack(Material.valueOf(itemType));
	            ItemMeta meta = itemStack.getItemMeta();
	            meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);

	            meta.setCustomModelData(customModelData);
	            meta.setDisplayName(displayName);

	            long lastClaimTime = playerHelmetCooldowns.getOrDefault(helmet, 0L);
	            long remainingCooldownMillis = (cooldownMinutes * 60 * 1000) - (System.currentTimeMillis() - lastClaimTime);

	            if (remainingCooldownMillis > 0) {
	                long remainingMinutes = TimeUnit.MILLISECONDS.toMinutes(remainingCooldownMillis);
	                List<String> lore = new ArrayList<>();
	                lore.add("Cooldown: " + remainingMinutes + " mins");
	                meta.setLore(lore);
	            }

	            meta.getPersistentDataContainer().set(new NamespacedKey(this, "helmetKey"), PersistentDataType.STRING, helmet);
	            itemStack.setItemMeta(meta);
	            inv.addItem(itemStack);
	        }
	    }

	    for (int i = 0; i < inv.getSize(); i++) {
	        if (inv.getItem(i) == null) {
	            inv.setItem(i, blank);
	        }
	    }

	    player.openInventory(inv);
	}
	
	@EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
		Player player = (Player) event.getWhoClicked();
		if(event.getView().getTitle().startsWith("Skin Station")) {
			event.setCancelled(true);
			if(event.getSlot() == 10) {
				FurnitureInventory(player, 0);
			}
			if(event.getSlot() == 12) {
				HatsInventory(player, 0);
			}
			if(event.getSlot() == 14) {
				ArmorCategoriesInventory(player);
				
			}
			if(event.getSlot() == 16) {
				ToolCategoriesInventory(player);
			}
		}
		if(event.getView().getTitle().startsWith("Furniture Skins")) {
	        event.setCancelled(true);
	        
	        int currentPage = currentPages.getOrDefault(player.getUniqueId(), 0);

	        if(event.getSlot() == 21) {
	            if(currentPage > 0) {
	                FurnitureInventory(player, currentPage - 1);
	                currentPages.put(player.getUniqueId(), currentPage - 1);
	            } else {
	                SkinStationInventory(player); // You have this function elsewhere in your code.
	            }
	        } else if (event.getSlot() == 23) {
	            FurnitureInventory(player, currentPage + 1);
	            currentPages.put(player.getUniqueId(), currentPage + 1);
	        } else {
	            ItemStack clickedItem = event.getCurrentItem();
	            if (clickedItem != null && clickedItem.hasItemMeta()) {
	                NamespacedKey key = new NamespacedKey(this, "furnitureKey");
	                String furniture = clickedItem.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.STRING);
	                
	                if (furniture != null) {
	                    Map<String, Long> playerCooldowns = lastFurnitureClaim.getOrDefault(player.getUniqueId(), new HashMap<>());
	                    long lastClaimTime = playerCooldowns.getOrDefault(furniture, 0L);
	                    int cooldownMinutes = getFurnitures().getInt(furniture + ".Cooldown");
	                    long remainingCooldownMillis = (cooldownMinutes * 60 * 1000) - (System.currentTimeMillis() - lastClaimTime);
	                    
	                    if (remainingCooldownMillis <= 0) {
	                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "iagive " + player.getName() + " " + furniture + " 1");
	                        playerCooldowns.put(furniture, System.currentTimeMillis());
	                        lastFurnitureClaim.put(player.getUniqueId(), playerCooldowns);

	                        // Refresh the inventory to display the cooldown lore.
	                        FurnitureInventory(player, currentPage);
	                        player.sendMessage(ChatColor.GREEN + "You've claimed " + ChatColor.BOLD + furniture + ChatColor.GREEN + "!");
	                    } else {
	                        player.sendMessage(ChatColor.RED + "This item is on cooldown. Please wait.");
	                    }
	                }
	            }
	        }
	    }
		if(event.getView().getTitle().startsWith("Hat Skins")) {
		    event.setCancelled(true);
		    
		    int currentPage = hatCurrentPages.getOrDefault(player.getUniqueId(), 0);

		    if(event.getSlot() == 21) {
		        if(currentPage > 0) {
		            HatsInventory(player, currentPage - 1);
		            hatCurrentPages.put(player.getUniqueId(), currentPage - 1);
		        } else {
		            SkinStationInventory(player); // You have this function elsewhere in your code.
		        }
		    } else if (event.getSlot() == 23) {
		        HatsInventory(player, currentPage + 1);
		        hatCurrentPages.put(player.getUniqueId(), currentPage + 1);
		    } else {
		        ItemStack clickedItem = event.getCurrentItem();
		        if (clickedItem != null && clickedItem.hasItemMeta()) {
		            NamespacedKey key = new NamespacedKey(this, "hatKey");
		            String hat = clickedItem.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.STRING);
		            
		            if (hat != null) {
		                Map<String, Long> playerCooldowns = lastHatClaim.getOrDefault(player.getUniqueId(), new HashMap<>());
		                long lastClaimTime = playerCooldowns.getOrDefault(hat, 0L);
		                int cooldownMinutes = getHats().getInt(hat + ".Cooldown");
		                long remainingCooldownMillis = (cooldownMinutes * 60 * 1000) - (System.currentTimeMillis() - lastClaimTime);
		                
		                if (remainingCooldownMillis <= 0) {
		                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "iagive " + player.getName() + " " + hat + " 1");
		                    playerCooldowns.put(hat, System.currentTimeMillis());
		                    lastHatClaim.put(player.getUniqueId(), playerCooldowns);

		                    // Refresh the inventory to display the cooldown lore.
		                    HatsInventory(player, currentPage);
		                    player.sendMessage(ChatColor.GREEN + "You've claimed " + ChatColor.BOLD + hat + ChatColor.GREEN + "!");
		                } else {
		                    player.sendMessage(ChatColor.RED + "This item is on cooldown. Please wait.");
		                }
		            }
		        }
		    }
		}
		if(event.getView().getTitle().startsWith("Armor Categories")) {
			event.setCancelled(true);
			if(event.getSlot() == 22) {
				SkinStationInventory(player);
			}
			if(event.getSlot() == 10) {
				HelmetSkinsInventory(player, 0);
			}
		}
		if (event.getView().getTitle().startsWith("Helmet Skins")) {
		    event.setCancelled(true);

		    int currentPage = helmetCurrentPages.getOrDefault(player.getUniqueId(), 0);

		    ItemStack helmetInHand = player.getInventory().getItemInMainHand();
		    if (helmetInHand == null || !(helmetInHand.getType().toString().endsWith("_HELMET"))) {
		        player.sendMessage(ChatColor.RED + "Hold the helmet you're wanting to skin");
		        player.closeInventory();
		        return;
		    }

		    if(event.getSlot() == 21) {
		        if(currentPage > 0) {
		            HelmetSkinsInventory(player, currentPage - 1);
		            helmetCurrentPages.put(player.getUniqueId(), currentPage - 1);
		        } else {
		            SkinStationInventory(player);
		        }
		    } else if (event.getSlot() == 23) {
		        HelmetSkinsInventory(player, currentPage + 1);
		        helmetCurrentPages.put(player.getUniqueId(), currentPage + 1);
		    } else {
		    	ItemStack clickedItem = event.getCurrentItem();
		    	if (clickedItem != null && clickedItem.hasItemMeta()) {
		    	    NamespacedKey key = new NamespacedKey(this, "helmetKey");
		    	    String helmet = clickedItem.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.STRING);

		    	    if (helmet != null) {
		    	        Map<String, Long> playerCooldowns = lastHelmetClaim.getOrDefault(player.getUniqueId(), new HashMap<>());
		    	        long lastClaimTime = playerCooldowns.getOrDefault(helmet, 0L);
		    	        int cooldownMinutes = getHelmets().getInt(helmet + ".Cooldown");
		    	        long remainingCooldownMillis = (cooldownMinutes * 60 * 1000) - (System.currentTimeMillis() - lastClaimTime);

		    	        if (remainingCooldownMillis <= 0) {
		    	            CustomStack stack = CustomStack.getInstance(helmet);
		    	            if (stack != null) {
		    	                ItemStack newItem = stack.getItemStack();
		    	                ItemMeta newMeta = newItem.getItemMeta();

		    	                Map<Enchantment, Integer> oldEnchants = helmetInHand.getEnchantments();
		    	                newItem.addEnchantments(oldEnchants);

		    	                List<String> lore = newMeta.hasLore() ? newMeta.getLore() : new ArrayList<>();
		    	                lore.add("Type: " + helmetInHand.getType().toString());
		    	                newMeta.setLore(lore);

		    	                newItem.setItemMeta(newMeta);
		    	                player.getInventory().setItemInMainHand(newItem);
		    	                
		    	                ItemStack finalItem = player.getInventory().getItemInMainHand();
		    	                ItemMeta finalMeta = finalItem.getItemMeta();
		    	                finalMeta.removeAttributeModifier(Attribute.GENERIC_ARMOR);
		    	                finalMeta.removeAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS);
		    	                
		    	                AttributeModifier armorModifier;
		    	        	    AttributeModifier toughnessModifier;
		    	                armorModifier = new AttributeModifier(UUID.randomUUID(), "generic.armor", 3.0, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HEAD);
		    		            toughnessModifier = new AttributeModifier(UUID.randomUUID(), "generic.armorToughness", 2.0, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HEAD);
		    	                finalMeta.addAttributeModifier(Attribute.GENERIC_ARMOR, armorModifier);
		    	                finalMeta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, toughnessModifier);
		    	                finalItem.setItemMeta(finalMeta);
		    	                player.getInventory().setItemInMainHand(finalItem);
		    	                
		    	                ItemStack durabilityMaxItem = player.getInventory().getItemInMainHand();
		    	                durabilityMaxItem = DurabilityAPI.setItemMaxDurability(durabilityMaxItem, 363);
		    	                player.getInventory().setItemInMainHand(ItemsAdder.setCustomItemDurability(durabilityMaxItem, 363));

		    	                playerCooldowns.put(helmet, System.currentTimeMillis());
		    	                lastHelmetClaim.put(player.getUniqueId(), playerCooldowns);

		    	                HelmetSkinsInventory(player, currentPage);
		    	                player.sendMessage(ChatColor.GREEN + "You've claimed " + ChatColor.BOLD + helmet + ChatColor.GREEN + "!");
		    	            } else {
		    	                player.sendMessage(ChatColor.RED + "No custom item found with that id.");
		    	            }
		    	        } else {
		    	            player.sendMessage(ChatColor.RED + "This item is on cooldown. Please wait.");
		    	        }
		    	    }
		    	}

		    }
		}
		if(event.getView().getTitle().startsWith("Tool Categories")) {
			event.setCancelled(true);
			if(event.getSlot() == 22) {
				SkinStationInventory(player);
			}
		}
	}
}