Opening a GUI / Double Chest GUI

Discussion in 'Plugin Development' started by DatCookiez, Jan 15, 2014.

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

    DatCookiez

    Hey guys!

    I was just wondering if there were any threads on how to open a GUI, can't seem to find any, I'm looking to make something when I right click a stick for example, it opens an inventory (double chest size) and it has other items in there which players can then click to get different kits etc.

    Thanks,
    DatCookiez
     
  2. Offline

    JoTyler

    yes there is . Here it is in simple form.

    Well i hope you know how to use listeners .

    Create a listener that waits for the clicking of the stick and make it run this.

    Inventory inv = Bukkit.getServer().createInventory(null, 54, "Kit Selector");

    the 54 tells it to be a double chest size . The "Kit Selector " just names the inventory.

    then in the same listener run .

    player.openInventory(inv);
     
    XvBaseballkidvX likes this.
  3. Offline

    DatCookiez


    Thank you, but how would I add items into this inventory?
     
  4. Offline

    Not2EXceL

  5. Offline

    TheLexoPlexx

  6. Offline

    DatCookiez

    I had no idea how to listen towards the stick, but I just guessed and got it straight away :) Just trial and error TheLexoPlexx
     
  7. Offline

    Not2EXceL

    TheLexoPlexx One teaches how to make the menus, the other is a utility to manage all of that with ease and cleaner code. However iconmenu has a listener bug and you have to destroy the listeners every open. Its better and simpler to just make your own. And if you can't figure it out from that, well then please learn Java.
     
  8. Offline

    DatCookiez

    Also, does anyone know how to check if a player clicks on an item in this GUI slot? I need to send a message and items to that player when they click a certain item in the GUI
     
  9. Offline

    desht

    That isn't a bug, it's how the class is supposed to work. It's just that too many people don't seem to read the description in the initial post. I quote:
     
  10. Offline

    LanteanKnight

    Create an inventory with:
    Code:java
    1. Inventory GUI = Bukkit.createInventory(<Player player>, <Integer size>, <String name>);
    2.  


    Then to add an item:
    Code:java
    1. GUI.setItem(<Integer slot>, <ItemStack item>);


    To register clicks in the inventory create a Listener that registers the InventoryClickEvent.
    Check if the name of the inventory corresponds with your GUI that's all that's to it! :)
    Code:java
    1. if(e.getInventory().getName().equals(<GUI name>)){
    2. if(e.getSlot() == <Specific slot>){
    3. YOUR CODE
    4. }
    5. }
     
    TheLexoPlexx likes this.
  11. Offline

    DatCookiez



    Could I be able to make a separate class and register the .getSlot() to that class?
     
  12. Offline

    TheLexoPlexx

    THATS what I wanted. And I was jus too stupid to make it. THANKS mate![​IMG]
     
Thread Status:
Not open for further replies.

Share This Page