New methods in AbstractPlayerManager + new suggestions suppliers in PaperBrigadierCommand

This commit is contained in:
2022-12-13 15:17:51 +01:00
parent 33f4c1550c
commit 49024bf3f8
2 changed files with 43 additions and 0 deletions

View File

@@ -117,8 +117,33 @@ public abstract class AbstractPlayerManager<OP extends AbstractOnlinePlayer, OF
return new ArrayList<>(onlinePlayers.values());
}
/**
* Get all the players that the provided player can see.
* The default implementation returns all the players.
* Concrete subclasses should override this method, especially
* on Paper server, using the {@code Player.canSee(Player)} API.
* @return the players that the provided player can see.
*/
public List<OP> getOnlyVisibleFor(OF viewer) {
return getAll();
}
/**
* Get all the players that the provided player can see.
* The default implementation returns all the players.
* Concrete subclasses should override this method, especially
* on Paper server, using the {@code Player.canSee(Player)} API.
* @return the players that the provided player can see.
*/
public List<String> getNamesOnlyVisible(OF viewer) {
return getOnlyVisibleFor(viewer).stream()
.map(AbstractOnlinePlayer::getName)
.toList();
}
/**
* Returns an instance of {@link AbstractOffPlayer} corresponding to a player with the provided {@link UUID}.
*
* @param p the UUID of the player.
* @return an instance of {@link AbstractOffPlayer}. It can be a new instance, an {@link AbstractOnlinePlayer}
* instance if the player is online, or a cached instance of {@link AbstractOffPlayer}.