When the player has a chest inventory type open and you player#openInventory another chest inventory type, it will not reset the player's cursor, however, if you use the dispenser inventory type for example it will!
Works fine:
@EventHandler(priority = EventPriority.LOWEST) public void a(BlockBreakEvent event) { final Inventory inv1 = Bukkit.createInventory(null, InventoryType.CHEST); inv1.addItem(new ItemStack(Material.ACACIA_BOAT)); final Inventory inv2 = Bukkit.createInventory(null, InventoryType.CHEST); inv2.addItem(new ItemStack(Material.ANDESITE)); event.getPlayer().openInventory(inv1); Bukkit.getScheduler().runTaskLater(DevTest.getInstance(), () -> { event.getPlayer().openInventory(inv2); }, 60); }
Doesn't work and resets the player's cursor.
@EventHandler(priority = EventPriority.LOWEST) public void b(BlockPlaceEvent event) { final Inventory inv1 = Bukkit.createInventory(null, InventoryType.DISPENSER); inv1.addItem(new ItemStack(Material.ACACIA_BOAT)); final Inventory inv2 = Bukkit.createInventory(null, InventoryType.DISPENSER); inv2.addItem(new ItemStack(Material.ANDESITE)); event.getPlayer().openInventory(inv1); Bukkit.getScheduler().runTaskLater(DevTest.getInstance(), () -> { event.getPlayer().openInventory(inv2); }, 60); }