Skip to content

Shared Contexts

Natan Vieira edited this page Nov 26, 2023 · 36 revisions

Shared Contexts consists of multiple players sharing the same context, therefore, the same inventory.

What means "sharing the same context"?

When you open a view for a player, IF creates a context that contains data related to that player and the inventory he is viewing this is exclusive to him. Each player sees their own inventory created during context creation, with its own items, title, size, etc.

Shared Contexts explores the concept that the created context is not exclusively tied to a single player, but several, thus sharing everything I mentioned above. It's useful for things like an exchange system: share a single inventory with players making the exchange.

Shared Contexts API is experimental and is not subject to the general compatibility guarantees such API may be changed or may be removed completely in any further release.

Creating a Shared Context

First, Shared Context is a concept and not a type of context thus it's a regular context like any other so a context becomes shared from the moment there is more than one player present in it.

To create a shared context you need to provide a list of players through ViewFrame's open.

// Opens "MyView" to a list of players
viewFrame.open(MyView.class, list of players);

closeForPlayer and closeForEveryone

Anything you do in a Shared Context will be propagated to all players linked to it, everything.

Some methods in IF have the suffix "forEveryone" and "forPlayer", this helps you work with shared contexts:

  • ...forPlayer Closes only to the player that is included in a given event e.g.: if a player clicks in some item and you use this method then this method will affect only this player
  • ...forEveryone Closes to everyone in the context e.g.: if a player e.g.: if a player clicks in some item and you use this method then this method will afftects all players in the context

closeForPlayer and closeForEveryone are a good example.

click.closeForEveryone();

Welcome to the Inventory Framework documentation.

▶️ Introduction

🧩 Core Topics

💡 Built-In Features

🧰 Extra Features

🤓 Advanced Usage

⚙️ Internal Mechanisms

🛠️ Tooling

You can find practical examples in the examples directory.

Clone this wiki locally