[UNSOLVED] [InventoryCloseEvent]: How to tell if a player switches inventory

Discussion in 'Plugin Development' started by CaptainDirt, Mar 10, 2015.

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

    CaptainDirt

    Hey all, I'm just gonna make this short and sweet, I'm using the InventoryCloseEvent but I'm not sure how I can get my code to recognise the event as a inv switch and not close. Any help?
     
  2. Offline

    teej107

    @CaptainDirt Create a custom event that gets called when a player switches inventories.
     
    mine-care likes this.
  3. Offline

    LeePMC

    or check if a player is still in an inventory after the inventoryCloseEvent and if so, check what inventory was opened
     
  4. Offline

    CaptainDirt

    Additional question: How to stop players from placing items in the inventory.
     
  5. Offline

    teej107

    That sounds like a Google search query!
     
  6. Offline

    CaptainDirt

    The late reply is real. (Mine). But trust me I did Google search it.

    How can I do this? I tried the get Top inv method but it didn't work.

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

    CaptainDirt

  8. Offline

    MajorSkillage

    I would use the InventoryOpenEvent and get the event inventory, you can check if it is a different inventory by comparing values or getting it's type :)
     
    CaptainDirt likes this.
  9. @CaptainDirt
    U can "link" some inventories to another ones, for example, I have invs 1, 2, 3 and 4. When I close the inv 3, it takes me to the 2, when I close 2 or 4 it takes me to 1 and when I close 1 it just close.
    So, u check on InventoryCloseEvent what inventory it`s, and depending on the inventory, u open another inventory 1 tick after the event (just opening it will cause the server to cash).
    To stop players from placing items in the inventory you can check on InventoryClickEvent if the currentItem is on the inventory clicked. Then check if the action is to place the item and cancel it. (I`ll recommend too to update the player`s inventory, just to prevent bugs).
     
    CaptainDirt likes this.
  10. Offline

    ResultStatic

    you could bypass the close event altogether

    Code:
    public static void openFast(Player player, Inventory inv){
            EntityPlayer ep = Nms.getCraftPlayer(player);
            Container defaultContainer = ep.defaultContainer;
            Container activeContainer = ep.activeContainer;
    
            if(defaultContainer == activeContainer){
                player.openInventory(inv);
            } else {
                //CraftEventFactory.handleInventoryCloseEvent(ep);
                ep.activeContainer = defaultContainer;
                player.openInventory(inv);
            }
        }
        
     
Thread Status:
Not open for further replies.

Share This Page