Skip to content

User management

In the API, every player is represented as a SocialUser. This abstraction ensures platform independence and provides additional utility methods for interacting with users.

Retrieving a SocialUser

In Bukkit-based platforms such as Spigot or Paper, SocialUser instances are implemented by the BukkitSocialUser class, which contains helper methods to retrieve users:

BukkitSocialUser userByPlayer = BukkitSocialUser.from(player);
BukkitSocialUser userBySocialUser = BukkitSocialUser.from(socialUser);
BukkitSocialUser userByUuid = BukkitSocialUser.from(uuid);

Sending messages

The SocialUser class implements Adventure's Audience. This means all standard Audience methods are available, including sendMessage:

Sending a Component
Component message = Component.text("Hello world!");
user.sendMessage(message);

Sending a parsable message

When working with social's text processing system, you may want messages to be parsed for placeholders, emojis, and other formatting features.

For this purpose, SocialUser provides the sendParsableMessage convenience method:

String message = "Hello, <gold>$(nickname)</gold>! :raw_smile:";
user.sendParsableMessage(message);

Accessing the Player instance from a BukkitSocialUser

You can retrieve the underlying Bukkit Player instance from a SocialUser using BukkitSocialUser::player.

This method returns an Optional<Player> because the user may be offline or represent a non-player entity.

Obtaining the Player instance from a SocialUser
user.player().ifPresent(player -> {
    // Code using the Player instance
});