ποΈ Visibility Api
Table of content:
ποΈ Visibility Api
The visibility API works on top of Bukkit's existing hidePlayer and showPlayer apis and provide a simpler way to use it for many cases. The visibility API works by a concept of groups, each group:
Has its own members
Can see specific groups
Cannot see specific groups
Recommended use cases:
Multiple games in one server,
where players can only see their gameSpectators,
Can see players and themselves but not vice-versaVanish,
Can see other players but players shouldn't have the abilty to see themEach world has it's own players (For large open world servers),
Every world can only see it's own players
Registering and using the API
Each server should have only one manager could be create like so we will probably want to also register visibility manager
When we call the function VisibilityManager#registerListener it will have VisibilityPlayerRemoveType of ON_LEAVE,
There are two types of VisibilityPlayerRemoveType
ON_LEAVE
Remove the player from in memory state when they quitNEVER
When the player will re-join the visibility policies will be automatically applied from the same group, but it can cause a memory leak (if we never clear it)
When we use VisibilityPlayerRemoveType.NEVER we will want to handle removal by our self We could get all players in memory by calling the function VisibilityManager#getPlayers and stream to filter which players should be removes
Visibility group
First, we will want to create group with VisibilityManager#getOrCreateGroup Groups are identified by their string id, if we invoke the method with the same param on the same instance we will receive the same group (identity is guaranteed). The following method creates a group for all players in the game. It means that the players in the game will only see each other and not other players on the server.
When the game is over we will probably want to delete all the groups we have created to avoid memory leaks.
When a player is removed from the game
Initialize a spectator group. Players on the spectator group will be able to see players on the main group, but not vice versa.
Initialize a group of vanished admins, who can be seen by no-one except themselves.