Solved Reopen inventory, when closed

Discussion in 'Plugin Development' started by mcdorli, Oct 9, 2015.

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

    mcdorli

    Hey there, I'm trying to make a plugin, that involves reopening inventory, when it's not empty (custom inventory). I got the not empty part done, but when I try to open a another inventory, it throws a stackoverflow exception. I'm using inventoryCloseEvent. Thanks!
     
  2. Offline

    Scimiguy

    Post code, post stacktrace
     
  3. Offline

    mcdorli

    I don't really have code, and I don't ask, because I don't know, what's causing the problem, I post because I want to know, If there is a way, to open am inventory, and not trigger the inventory close event.

    The code is literally just

    Inventory close event begin

    Check if inventory is the correct one and not empty

    Create and open inventory

    End of if statement

    End of event listener

    This is pseudo code, of course, it is in java.
     
    Last edited: Oct 9, 2015
  4. Offline

    boomboompower

    Maybe try checking if the inventory is your custom one. Because if people open a chest inventory for example, it would be bad if every time they tried to get out of it, it opened again.
     
  5. Offline

    Xerox262

    He said he was checking already.

    If you don't have code then how do you know it is throwing a stackoverflow?

    And why reopen the inventory rather than just cancel the close event?
     
  6. Offline

    Scimiguy

    If you don't have a StackOverflow, how do you know it's throwing a.. nvm

    Post Error
     
  7. Offline

    mcdorli

    The inventory close event is not cancellable, and I have code, but not much goimg on with it (5 rows of code)

    @timtower, do you hace an idea?
     
  8. Offline

    RoboticPlayer

    If you post the stack trace then we can help you with what is actually happening.
     
  9. Offline

    mcdorli

    Because it is a stackoverflow, it takes up like 20 pages
     
  10. Offline

    Scimiguy

    Put it on pastebin then and give us a link
     
  11. Offline

    mcdorli

    http://pastebin.com/U4EDaJw4 BTW.: The error is on the 20th line, wich is the ev.getPlayer.opentInventory(inv) line
     
  12. Offline

    Scimiguy

    I do hope you mean ev.getPlayer().openInventory(inv);

    Try setting a runnable to open the inventory after a few ticks instead
     
  13. Offline

    Langsdorf

    Try this:
    Code:
       
    
     public static Inventory inv;
        public static void a() {
            inv = Bukkit.createInventory(null, 54, "Hey");
            inv.addItem(new ItemStack(Material.WOOD));
        }
        @EventHandler
        public void a(InventoryCloseEvent e) {
            if (e.getInventory().getTitle() == "Hey") {
                ItemStack id = new ItemStack(Material.AIR);
                for (int i = 0; i < 55; i++) {
                    if (e.getInventory().getItem(i) != id) {
                        e.getPlayer().openInventory(inv);
                    }
                }
            }
        }
     
  14. Offline

    RoboticPlayer

    Can you show us the onInventoryClose method (not even the whole class, just the method)?
     
  15. Offline

    Xerox262

    You realise that we're not going to stop asking can we see the code until you show us it? Even if you think it's just 5 lines and it isn't needed we still need to see.
     
  16. Offline

    mcdorli

    @Xerox262 @henderry2019

    Code:
    Inventory inv = ev.getInventory();
            if (inv.getName() == "Your prize:") {
                for (int i = 0; i < 9; i++) {
                    if (inv.getContents()[i] != null && inv.getContents()[i].getType() != Material.AIR) {
                        Inventory inv2 = Bukkit.createInventory(ev.getPlayer(), 9, "Your prize:");
                        inv2.setContents(inv.getContents());
                        ev.getPlayer().openInventory(inv2);
                        return;
                    }
                }
              
            }
    
    
     
  17. Offline

    Xerox262

    nv.getName() == "Your prize:"
    should use .equals()
    and did you try just using ev.getPlayer().openInventory(ev.getInventory())
     
  18. Offline

    mcdorli

    Yes I tried

    This worked, thanks, i just needed to do a 1 tick delay.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
Thread Status:
Not open for further replies.

Share This Page