Adding Items to GUI in Config

Discussion in 'Plugin Development' started by Glass_Eater84, May 28, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Glass_Eater84

    Hello Everybody!

    Today, I am trying to create a GUI plugin that has commands binded to the items in the GUI.

    However I want to make it so the user can add the items that are going to be in the GUI to the config, As

    well, as the command be binded to said item, and last but not least the name and lore (with color support)

    Thank you all in advance!
    (I will also display parts of my code if you wish)
    Best Regards,
    Glass
     
  2. Offline

    Tomasko

    You can put data about command in YAML like block, name lore etc and then
    Code:java
    1. getConfig().getConfigurationSection("commands").getValues(false)

    Get how many "commands are in config"(lenght of set) and then calculate, how many 9 slots you need
    in case 10 command you need 2x 9 slot(1 row in inventory)
    Then create inventory and add contest for all commands
    Code:java
    1. public static Inventory myInventory = Bukkit.createInventory(null, rows, "MyUltraCommands");
    And then put commands in arraylist that you will loop
    Code:java
    1. int actual = 0;
    2. for(String comm : commands) {
    3. ItemStack is = new ItemStack(config.get("commands."+comm+".id"),1,0);
    4. //wathever stuff with is
    5. myInventory.setItem(actual, is);
    6. actual++;
    7. }

    and then if you have commands in array register listener for InventoryClickEvent and you can check for inventory and item, then execute whatever you want
    Code:java
    1. Bukkit().getServer().dispatchCommand(player, cmd);
     
  3. Offline

    Glass_Eater84

    I will try this when I get back from school.
    Thanks for quick response.
    Glass

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
Thread Status:
Not open for further replies.

Share This Page