Advertisement
MSWS

Inventory

May 27th, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. public Inventory getGui(Player player, String id) {
  2.         if (!Main.plugin.config.contains(id))
  3.             return null;
  4.         ConfigurationSection gui = Main.plugin.config.getConfigurationSection(id);
  5.         Inventory inv = Bukkit.createInventory(null, gui.getInt("Size"), gui.getString("Title"));
  6.         ItemStack bg = null;
  7.         for (String res : gui.getKeys(false)) {
  8.             if (!gui.contains(res + ".Icon"))
  9.                 continue;
  10.             if (gui.contains(res + ".Permission") && !player.hasPermission(gui.getString(res + ".Permission"))) {
  11.                 continue;
  12.             }
  13.             ItemStack item = new ItemStack(Material.valueOf(gui.getString(res + ".Icon")));
  14.             if (gui.contains(res + ".Amount"))
  15.                 item.setAmount(gui.getInt(res + ".Amount"));
  16.             if (gui.contains(res + ".Data"))
  17.                 item.setDurability((short) gui.getInt(res + ".Data"));
  18.             ItemMeta meta = item.getItemMeta();
  19.             if (gui.contains(res + ".Name"))
  20.                 meta.setDisplayName(MSG.color("&r" + gui.getString(res + ".Name")));
  21.             if (gui.contains(res + ".Lore")) {
  22.                 List<String> lore = new ArrayList<String>();
  23.                 for (String temp : gui.getStringList(res + ".Lore"))
  24.                     lore.add(MSG.color("&r" + temp));
  25.                 meta.setLore(lore);
  26.             }
  27.             if (gui.contains(res + ".Enchantments")) {
  28.                 ConfigurationSection enchs = gui.getConfigurationSection(res + ".Enchantments");
  29.                 for (String enchant : enchs.getKeys(false)) {
  30.                     int level = 1;
  31.                     boolean visible = true;
  32.                     if (enchs.contains(enchant + ".Level"))
  33.                         level = enchs.getInt(enchant + ".Level");
  34.                     if (enchs.contains(enchant + ".Visible"))
  35.                         visible = enchs.getBoolean(enchant + ".Visible");
  36.                     meta.addEnchant(Enchantment.getByName(enchant.toUpperCase()), level, visible);
  37.                 }
  38.             }
  39.             item.setItemMeta(meta);
  40.             if (res.equals("BACKGROUND_ITEM")) {
  41.                 bg = item;
  42.                 continue;
  43.             }
  44.             inv.setItem(gui.getInt(res + ".Slot"), item);
  45.         }
  46.         if (bg != null) {
  47.             for (int i = 0; i < inv.getSize(); i++) {
  48.                 if (inv.getItem(i) == null || inv.getItem(i).getType() == Material.AIR) {
  49.                     inv.setItem(i, bg);
  50.                 }
  51.             }
  52.         }
  53.         return inv;
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement