Solved InventoryCloseEvent ItemStack returning issue

Discussion in 'Plugin Development' started by DevSock, Aug 19, 2014.

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

    DevSock

    So I was recently developing a shop plugin for a server that requested it and I ran into an issue. I'm not sure if it's just me or what because I haven't been able to test it with others.

    Basically, when you're listening for the InventoryCloseEvent, if you loop through the contents of that inventory and try to add it to the player's inventory it gets added, but it's invisible. player.updateInventory(); doesn't fix the issue either. They stay invisible until they are updated through action such as right clicking while holding one of the spots where the item should be.

    Can someone else test this and tell me if it's an issue with Bukkit? And if it IS an issue with Bukkit is there even a fix? Here's a snippet of my code.

    Code:java
    1. for(int i = 0; i < 35; i++){
    2. ItemStack invItem = event.getInventory().getItem(i);
    3. if(invItem == null) continue;
    4. if(!gch.getSellables(shopName).contains(Integer.toString(invItem.getTypeId()))){
    5. returnItem.add(invItem);
    6. event.getInventory().removeItem(invItem);
    7. continue;
    8. }
    9. cashPayed = (gch.getPayment(shopName, Integer.toString(invItem.getTypeId())) * invItem.getAmount()) + cashPayed;
    10. itemsSold = itemsSold + invItem.getAmount();
    11. }
    12. for(ItemStack item : returnItem){
    13. player.getInventory().addItem(item);
    14. }
    15. player.updateInventory();
     
  2. Offline

    St3venAU

    Just a hunch so this might not work, but try scheduling a task for 1 tick later to add the items to the player's inventory.
     
  3. Offline

    DevSock

    St3venAU
    Well, I fixed it using this method before anything was commented, but a 1 tick delay doesn't fix the issue. I found it has to be at least 3 ticks for it to visibly add the items to the player's inventory. Perhaps it's because it's being indirectly done from outside the event after it finishes? It's weird though, that's for sure.
     
Thread Status:
Not open for further replies.

Share This Page