Making GUI appear on player join

Discussion in 'Plugin Development' started by carbuilder, Aug 4, 2014.

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

    carbuilder

    im trying to make a gui appear when the player joins so they can click an item and get a certain kit. i want it to appear when the player first joins and only on their first time. here is my code: http://pastebin.com/yKxeGg6u
    problems: the item works as a test so i know they wont get another whenever they sign back into the server. whenever i click on a workbench the gui works as it should except whenever i click on the item i can pick it up and even take it, and i even added a message to be sent as a test when the item is clicked and that doesnt happen either. this is the first gui i have tried to make so any help learning this would be greatly appreciated!

    thanks in advance,
    carbuilder
     
  2. Offline

    JustinsCool15

    carbuilder
    InventoryClickEvent

    Once you're done with what you need to do e.setCanceled(true);

    That will make the item reappear where it was.
     
  3. Offline

    carbuilder

    I added it in and it still does the same thing


    @EventHandler
    public void onInventoryClick(InventoryClickEvent e) {
    if(e.getInventory().getName()
    .equalsIgnoreCase("Class Chooser")) {

    Player player = (Player) e.getWhoClicked();
    e.setCancelled(true);

    if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()) {
    player.closeInventory();
    return;
    }
    switch(e.getCurrentItem().getType()) {
    case WORKBENCH:
    //add kit
    player.sendMessage(ChatColor.BLUE + "You got your kit!");
    e.setCancelled(true);
    break;
    default:
    player.closeInventory();
    break;
    }
    }
    }
     
  4. Offline

    xXMaTTHDXx

    carbuilder please put your code in
    Code:
     
    so we can read it better, along with formatting, could you also chow the whole class?
     
  5. Offline

    carbuilder

    im not sure how to putit in that code box so here ya go!
    code: http://pastebin.com/UCBmK6gU

    Someone plz help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    xXMaTTHDXx

    I believe it was because you where cancelling it 2 times, try this:

    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent e) {
    3. if(e.getInventory().getName()
    4. .equalsIgnoreCase("Class Chooser")) {
    5.  
    6. Player player = (Player) e.getWhoClicked();
    7.  
    8. if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()) {
    9. player.closeInventory();
    10. return;
    11. }
    12.  
    13. switch(e.getCurrentItem().getType()) {
    14. case WORKBENCH:
    15. //add kit
    16. player.sendMessage(ChatColor.BLUE + "You got your kit!");
    17. e.setCancelled(true);
    18. break;
    19. default:
    20. player.closeInventory();
    21. break;
    22. }
    23. }
    24. }
    25.  
     
  7. Offline

    carbuilder

    same thing happened. i have no idea why this is

    if someone could help it would be greatly appreciated. this plugin is for a friend so im trying to finish it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  8. Offline

    KaitouKidFTW

    Something like this?

    Code:java
    1. @EventHandler
    2. public void onInventoryClickEvent(InventoryClickEvent event){
    3.  
    4. Player player = (Player) event.getWhoClicked();
    5.  
    6. if(event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR){
    7. return;
    8.  
    9. }
    10.  
    11. if(event.getInventory().getName().equals(inv.getName())){
    12. if(event.getCurrentItem().getType() == Material.WORKBENCH){
    13.  
    14. //Give kit
    15. //Send message
    16.  
    17. player.closeInventory();
    18. event.setCancelled(true);
    19.  
    20. }
    21. }
    22. }
    23. }
    24.  
     
Thread Status:
Not open for further replies.

Share This Page