Hello, I am making a hub plugin that adds everything the server needs. Everything was great then I had a problem with the Server Selector GUI. I want that everytime someone adds to the config (under the title of ServerMenuItems) it will add an Item to the gui, I have no idea how to do this. can somebody help me??? -Config: <click here> -A little piece from the main file code: <click here> If you are having a hard time with understanding me (and my bad grammer) I mean like the known plugin "chestcommands" that you can edit a gui. -ChestCommands Plugin Site: <click here> Thanks.
i have a way, i dont think its efficient though, but here it is; Before server menu items, make a section called: ServerMenuItemNames, make it a string list. So it will be: ServerMenuItemNames: - Hub - Skywars .... Then: ServerMenuItems: Hub: Name: hub Command: '/server hub' Materialid: 7 Slot: 2 Skywars Name: Command: Etcc So if u add items in ServerMenuItems U have to put it in ServerMenuItemsNames Code: public void openInv(Player p){ ArrayList<String> s = getConfig().getStringList("ServerMenuItemNames"); for (String path: s){ if (getConfig().getString("ServerMenuItems." + path) != bull){ Get themmm } }
That could work but I am afraid to mess that up, I already did the new config but can U do a full code example for this config? #ServerMenuGUI: ServerMenuItemNames: -Hub ServerMenuItems: Hub: Name: Hub Command: '/server hub' ItemID: '138' Slot: 2
First i make this method: public String inColors(String s){ return ChatColor.translateAlternateColorCodes('&', s); } Then this: public List<String> inLoreColors(List<String> s)){ List<String> k = new ArrayList<String>(); for (String w:s){ k.add(inColors(w)); } return k; } public ItemStack createStack(Material m, String name, List<String> lore){ ItemStack stack = new ItemStack(m); ItemMeta stackm = stack.getItemMeta(); stackm.setDisplayName(inColors(name)); stackm.setLore(inLoreColors(lore)); stack.setItemMeta(stackm); return stack; } Then this: public void openMenu(Player p){ Inventory inv = Bukkit.createInventory(null, 36, inColors("&6Menu); ArrayList<String> s = getConfig().getStringList("ServerMenuItemNames); for (String k: s){ if (getConfig().getString("ServerMenuItems." + k) != null){ int itemid =Integer.parseInt(getConfig().getString ("ServerMenuItems." + k + ".ItemID)); String name = getConfig().getString("ServerMenuItems." + k + ".Name"); int itemid =Integer.parseInt(getConfig().getString ("ServerMenuItems." + k + ".Slot)); ItemStack stack = createStack( Material.getMaterial(itemid), name, new ArrayList<String>(); inv.setItem(slot, stack); } p.openInventory(inv): } @EventHandler public void onClick(InventoryClickEvent e){ If (e.getInventory().getName().contains("ServerMenu"){ ArrayList<String> s = getConfig().getStringList("ServerMenuItemNames); for (String k: s){ if (e.getCurrentItem().getName().equalsIgnoreCase( getConfig().getString("ServerMenuItems." +k + ".Name){ Bukkit.dispatchCommand(e.getWhoClicked(), getConfig().getString("ServerMenuItems." +k + ".Command); } } } } Im on phone it took me ages