Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Inventory getGui(Player player, String id) {
- if (!Main.plugin.config.contains(id))
- return null;
- ConfigurationSection gui = Main.plugin.config.getConfigurationSection(id);
- Inventory inv = Bukkit.createInventory(null, gui.getInt("Size"), gui.getString("Title"));
- ItemStack bg = null;
- for (String res : gui.getKeys(false)) {
- if (!gui.contains(res + ".Icon"))
- continue;
- if (gui.contains(res + ".Permission") && !player.hasPermission(gui.getString(res + ".Permission"))) {
- continue;
- }
- ItemStack item = new ItemStack(Material.valueOf(gui.getString(res + ".Icon")));
- if (gui.contains(res + ".Amount"))
- item.setAmount(gui.getInt(res + ".Amount"));
- if (gui.contains(res + ".Data"))
- item.setDurability((short) gui.getInt(res + ".Data"));
- ItemMeta meta = item.getItemMeta();
- if (gui.contains(res + ".Name"))
- meta.setDisplayName(MSG.color("&r" + gui.getString(res + ".Name")));
- if (gui.contains(res + ".Lore")) {
- List<String> lore = new ArrayList<String>();
- for (String temp : gui.getStringList(res + ".Lore"))
- lore.add(MSG.color("&r" + temp));
- meta.setLore(lore);
- }
- if (gui.contains(res + ".Enchantments")) {
- ConfigurationSection enchs = gui.getConfigurationSection(res + ".Enchantments");
- for (String enchant : enchs.getKeys(false)) {
- int level = 1;
- boolean visible = true;
- if (enchs.contains(enchant + ".Level"))
- level = enchs.getInt(enchant + ".Level");
- if (enchs.contains(enchant + ".Visible"))
- visible = enchs.getBoolean(enchant + ".Visible");
- meta.addEnchant(Enchantment.getByName(enchant.toUpperCase()), level, visible);
- }
- }
- item.setItemMeta(meta);
- if (res.equals("BACKGROUND_ITEM")) {
- bg = item;
- continue;
- }
- inv.setItem(gui.getInt(res + ".Slot"), item);
- }
- if (bg != null) {
- for (int i = 0; i < inv.getSize(); i++) {
- if (inv.getItem(i) == null || inv.getItem(i).getType() == Material.AIR) {
- inv.setItem(i, bg);
- }
- }
- }
- return inv;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement