player.closeInventory() crashing server

Discussion in 'Spigot Plugin Development' started by SnowGears, Jul 3, 2015.

  1. Hello everyone. I am writing a plugin and I need to close a player's open inventory.

    I have tried using player.closeInventory() and player.getOpenInventory().close() but both time out my server and crash it. Is there something I am missing or is this just a bug in the 1.8.3 spigot build? Thanks!

    Here is my code:
    Code (Java):

    Player player = event.getPlayer();
    player.closeInventory(); //this crashes my server
     
    I also tried to see if it was something wrong with the creative inventory window the player was in so I tried this but this still crashes server:
    Code (Java):

    Player player = event.getPlayer();
    Inventory myInventory = Bukkit.createInventory(null, 9, "temp inventory");
    player.openInventory(myInventory); //this works fine
    player.closeInventory(); //this crashes my server
     
    Any help would be awesome. Does closing inventories work for other people?
     
  2. Don't think it's a Spigot bug as I've been using similar code lately on the same build. What event is this inside? Could you also provide the stack trace for the crash / error ?
     
  3. Perhaps another plugin that is causing the server to crash while an InventoryCloseEvent is being fired? If you are utilizing InventoryCloseEvent it would be useful to post that here as well
     
  4. Wow. Silly mistake. Looking back I accidentally created a recursive loop by switching two lines that weren't meant to be switched. Thanks for helping!