Channel management
Channels are one of the core aspects of social. In the API, a channel is known as ChatChannel
. The built-in ChatManager
provides some utilities and allows to access registered channels:
Getting a ChatChannel from its name
final var name = "global";
ChatChannel channel = Social.get().getChatManager().getChannel(name);
Group channels
In the case of group channels, we will probably want to get channels from their code:
Getting a GroupChatChannel from its code
final var code = 491350;
GroupChatChannel channel = Social.get().getChatManager().getGroupChannelByCode(code);
We can also get a SocialUser
's group channel with:
Getting a GroupChatChannel from a SocialUser
GroupChatChannel channel = Social.get().getChatManager().getGroupChannelByUser(user);
Do note that this method may return null
and you should handle your code accordingly.
Registering a custom channel
Although we'd rather let administrators create and customize their channels, we understand that certain plugins may need to register channels for convenience. Here's an example:
Registering a ChatChannel
final String name = "example-channel";
final TextColor color = NamedTextColor.YELLOW;
final String icon = "<blue>:raw_comet:</blue>";
final boolean showHoverText = true;
final Component hoverText = Component.text("Hover text!");
final TextColor nicknameColor = NamedTextColor.WHITE;
final String textDivider = ":raw_divider:";
final String permission = "permission"; // nullable
final boolean joinByDefault = true;
final var channel = new ChatChannel(
name,
color,
icon,
showHoverText,
hoverText,
nicknameColor,
textDivider,
permission,
joinByDefault);
Social.get().getChatManager().registerChatChannel(channel);
Managing members
Now that we have a new channel, we'll want to add some members.
Adding members to a channel
channel.addMember(user);
// Or you can use a UUID:
channel.addMember(user.getUuid());
It is also possible to remove members with a similar method: