1.15.2 Player Top Inventory keep Items

Discussion in 'Spigot Plugin Development' started by aufgosh, Feb 20, 2020.

  1. Is it Possible to keep the Items in the topInventory of the Player Inventory (the 2*2 crafting grid system) upon inventory close?

    I dont want these Items to be dropped so i could just clear them with an event, HOWEVER the InventoryOpen Event doesent work in this case.. and since i am using 1.15.2 achievements wont work either.

    So anyone has a solution for this?
  2. https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/inventory/InventoryCloseEvent.html or InventoryClickEvent.
  3. How would InventoryCloseEvent or ClickEvent help in this case if there is no way to load those items (from what i've understood) back up?
  4. Well you'll need to save the itemstacks. For example
    Code (Text):
    on inventoryclose:
      if inventorytype is playerinventory
        for int slot id = craftingslots
           if (inv.getitem(slot id) != null)
              getConfig().save(playerUUID.slot id, itemstack.serialize);

    on inventory open:
      if inventorytype is playerinventory && getconfig.contains(playerUUID)
        for string slot id : getconfigurationsection(playeruuid)
             inventory.setitem(itemstack.deserialize(getconfig.get(playeruuid.slot id.), Integer.parse(slot id));
  5. I've tried it myself and you can load stuff into the PlayerInventory with InventoryOpenEvent, since you dont recieve any packets when the player opens his normal inventory, only if he closes it. Also is that Script language or did you just simplify it?
  6. Do some debug but I'm pretty sure you do receive packets when the player opens his player inventory. This is java-not-spoon-feeding-simplified-example.
  7. this is literally spoon-feeding code but whatever

    you dont
  8. How is this spoon-feeding? Try to copy this code into an IDE and compile it, tell me how it goes.

    I'm gonna test this right now
    EDIT: indeed you do not, but I think you can do that with ProtocolLib (not sure tho, never used this)
  9. there has to be another way
  10. Sorry to break it to you, but there's no other way. I was doing some inventory stuff yesterday and tried a ton of stuff
    • Like Like x 1