Chest GUI Re-Open on Cancel

Discussion in 'Plugin Development' started by jleeevinnn, May 5, 2014.

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

    jleeevinnn

    I run a minigame server that utilizes GUI Chest screens, however I am having some problems.

    When the GUI pops up, players can press ESC, or otherwise exit out of them without selecting one of the options.

    Example: Player joins the game, GUI pops up auto-magically to select a class, however the player exits out therefore they are still in the game without a class.

    Looking for any possible solutions, thanks.
     
  2. Offline

    Gater12

    jleeevinnn
    You either make up a random class selection function (for punishment of pressing ESC, muahahah) or look into InventoryCloseEvent.
     
  3. Offline

    Ytry

    Here have my most likely poorly codded psudo code that might work.
    Code:java
    1. public void onInventoryClose(InventoryCloseEvent event){
    2. if(!player.hasClass)
    3. {
    4. event.setcanceled
    5. }
    6. }
     
  4. Offline

    Gater12

    Ytry
    InventoryCloseEvent does not implement interface Cancellable.

    You can just open the inventory again. jleeevinnn
     
  5. Offline

    Ytry

    Gater12 I didn't realize my bad. Then like gater12 said just reopen the inventory when they close it if they don't have a class.
     
  6. Offline

    jleeevinnn

    How do I check if they close it? And how would I call on my method to continously call the method that checks this?
     
  7. jleeevinnn
    This should work.
    Code:java
    1. @EventHandler
    2. public void onInvClose(InventoryCloseEvent e){
    3. if(e.getInventory().getName().equalsIgnoreCase("YOUR INVENTORY DISPLAY NAME")){
    4. if(!e.getPlayer().hasClass){
    5. //Open the inventory again
    6. }
    7. }
    8. }
     
Thread Status:
Not open for further replies.

Share This Page