Untitled
package org.lifestealsmp.duelscore; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; public class InventoryManager { public void openDuelsGUI(Player player) { Inventory inv = Bukkit.createInventory(null, 27, "§4§lDuels §0§lSelect Game Mode"); ItemStack unranked = new ItemStack(Material.SOUL_CAMPFIRE); ItemMeta unrankedMeta = unranked.getItemMeta(); ArrayList<String> unrankedLore = new ArrayList<String>(); unrankedMeta.setDisplayName("§a§lUnranked Duels"); List<String> unRankedQueueList = Main.getInstance().getConfig().getStringList("Un-Ranked-Queue"); unrankedLore.add(" §7 - Current Queue: §e§l" + unRankedQueueList.size()); unrankedMeta.setLore(unrankedLore); unranked.setItemMeta(unrankedMeta); File directory = new File("plugins/Duels/players"); File playerFile = new File(directory, player.getUniqueId() + ".yml"); FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(playerFile); ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); SkullMeta headMeta = (SkullMeta) head.getItemMeta(); headMeta.setOwningPlayer(player); headMeta.setDisplayName("§cProfile Statistics"); ArrayList<String> headLore = new ArrayList<String>(); headLore.add("§7 - §aTotal Elo: §e" + playerConfig.getInt("Elo")); headLore.add(""); headLore.add("§7 - §aRanked Wins: §e" + playerConfig.getInt("Ranked-Wins")); headLore.add("§7 - §aRanked Loss: §e" + playerConfig.getInt("Ranked-Loss")); headLore.add(""); headLore.add("§7 - §aUn-Ranked Wins: §e" + playerConfig.getInt("Un-Ranked-Wins")); headLore.add("§7 - §aUn-Ranked Loss: §e" + playerConfig.getInt("Un-Ranked-Loss")); headMeta.setLore(headLore); head.setItemMeta(headMeta); ItemStack ranked = new ItemStack(Material.CAMPFIRE); ItemMeta rankedMeta = ranked.getItemMeta(); ArrayList<String> rankedLore = new ArrayList<String>(); rankedMeta.setDisplayName("§a§lRanked Duels"); List<String> RankedQueueList = Main.getInstance().getConfig().getStringList("Ranked-Queue"); rankedLore.add(" §7 - Current Queue: §e§l" + RankedQueueList.size()); rankedMeta.setLore(rankedLore); ranked.setItemMeta(rankedMeta); inv.setItem(12, unranked); inv.setItem(13, head); inv.setItem(14, ranked); ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE); ItemMeta blankMeta = blank.getItemMeta(); blankMeta.setDisplayName("§r"); blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); blank.setItemMeta(blankMeta); for (int i = 0; i < inv.getSize(); i++) { if (inv.getItem(i) == null) { inv.setItem(i, blank); } } player.openInventory(inv); } public void openUnRankedDuelsGUI(Player player) { FileConfiguration config = Main.getInstance().getConfig(); // Get your config file ConfigurationSection kitsSection = config.getConfigurationSection("Kits"); if (kitsSection == null) return; // No kits defined int kitCount = kitsSection.getKeys(false).size(); int inventorySize = ((kitCount) / 9 + 1) * 9; // Adjust inventory size to have space for JoinAll Inventory inv = Bukkit.createInventory(null, inventorySize, "§4§lDuels §0§lUnranked Kits"); // Create a blank item for empty slots ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE); ItemMeta blankMeta = blank.getItemMeta(); blankMeta.setDisplayName("§r"); blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); blank.setItemMeta(blankMeta); // Fill inventory with blank items for (int i = 0; i < inventorySize; i++) { inv.setItem(i, blank); } ItemStack JoinAll = new ItemStack(Material.EMERALD_BLOCK); ItemMeta JoinAllMeta = JoinAll.getItemMeta(); JoinAllMeta.setDisplayName("§aJoin All Un-Ranked Queues"); JoinAll.setItemMeta(JoinAllMeta); // Iterate through kits and add them to the inventory int index = 0; for (String kitKey : kitsSection.getKeys(false)) { if (kitsSection.isConfigurationSection(kitKey)) { ConfigurationSection kitSection = kitsSection.getConfigurationSection(kitKey); Material icon = Material.getMaterial(kitSection.getString("Icon", "STONE")); ItemStack kitItem = new ItemStack(icon); ItemMeta kitMeta = kitItem.getItemMeta(); kitMeta.setDisplayName( ChatColor.translateAlternateColorCodes('&', kitSection.getString("name", kitKey))); List<String> lore = kitSection.getStringList("lore").stream() .map(line -> ChatColor.translateAlternateColorCodes('&', line)).collect(Collectors.toList()); kitMeta.setLore(lore); kitItem.setItemMeta(kitMeta); inv.setItem(index++, kitItem); } } // Place JoinAll in the last slot inv.setItem(inventorySize - 1, JoinAll); player.openInventory(inv); } public void openRankedDuelsGUI(Player player) { FileConfiguration config = Main.getInstance().getConfig(); // Get your config file ConfigurationSection kitsSection = config.getConfigurationSection("Kits"); if (kitsSection == null) return; // No kits defined int kitCount = kitsSection.getKeys(false).size(); int inventorySize = ((kitCount) / 9 + 1) * 9; // Adjust inventory size to have space for JoinAll Inventory inv = Bukkit.createInventory(null, inventorySize, "§4§lDuels §0§lRanked Kits"); // Create a blank item for empty slots ItemStack blank = new ItemStack(Material.BLACK_STAINED_GLASS_PANE); ItemMeta blankMeta = blank.getItemMeta(); blankMeta.setDisplayName("§r"); blankMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); blank.setItemMeta(blankMeta); // Fill inventory with blank items for (int i = 0; i < inventorySize; i++) { inv.setItem(i, blank); } ItemStack JoinAll = new ItemStack(Material.EMERALD_BLOCK); ItemMeta JoinAllMeta = JoinAll.getItemMeta(); JoinAllMeta.setDisplayName("§aJoin All Ranked Queues"); JoinAll.setItemMeta(JoinAllMeta); // Iterate through kits and add them to the inventory int index = 0; for (String kitKey : kitsSection.getKeys(false)) { if (kitsSection.isConfigurationSection(kitKey)) { ConfigurationSection kitSection = kitsSection.getConfigurationSection(kitKey); Material icon = Material.getMaterial(kitSection.getString("Icon", "STONE")); ItemStack kitItem = new ItemStack(icon); ItemMeta kitMeta = kitItem.getItemMeta(); kitMeta.setDisplayName( ChatColor.translateAlternateColorCodes('&', kitSection.getString("name", kitKey))); List<String> lore = kitSection.getStringList("lore").stream() .map(line -> ChatColor.translateAlternateColorCodes('&', line)).collect(Collectors.toList()); kitMeta.setLore(lore); kitItem.setItemMeta(kitMeta); inv.setItem(index++, kitItem); } } // Place JoinAll in the last slot inv.setItem(inventorySize - 1, JoinAll); player.openInventory(inv); } }
Leave a Comment