Package ovh.mythmc.social.api.chat
Class ChatManager
java.lang.Object
ovh.mythmc.social.api.chat.ChatManager
Manages chat channels, renderers and the per-session chat history.
Access the singleton via
Social.getChatManager().
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the user to every channel that hasChatChannel.joinByDefault()set and for which they have the required permission.Returns the user's cached main channel, or the default channel if they don't have one.Returns the default channel as configured insettings.yml.getRegisteredRenderer(@NotNull Class<T> object) Returns the registered renderer for the given class, ornullif none exists.getRegisteredRenderer(@NotNull Audience audience) Returns the first renderer able to map the given audience object, ornullif none.Returns all channels the given user has permission to see.groupChannelByCode(int code) Returns theGroupChatChannelwhose name matches"G-" + code, if any.Returns theGroupChatChannelthe given user is currently a member of, if any.booleanhasGroup(@NotNull SocialUser user) Returnstrueif the given user is a member of any group channel.booleanhasPermission(@NotNull SocialUser user, @NotNull ChatChannel channel) Returnstrueif the user satisfies the channel's permission requirement (or the channel has no permission requirement).registerRenderer(@NotNull Class<T> targetClass, @NotNull SocialChatRenderer<T> renderer, @NotNull Function<SocialChatRenderer.Builder<T>, SocialChatRenderer.Builder<T>> options) Registers aSocialChatRendererfor a given target class and returns theSocialChatRenderer.Registeredwrapper.<T> voidunregisterAllRenderers(@NotNull Class<T> targetClass) Unregisters all renderers associated with the given target class.<T> voidunregisterRenderer(SocialChatRenderer.Registered<T> registeredRenderer) Unregisters the given renderer.
-
Field Details
-
instance
-
-
Constructor Details
-
ChatManager
public ChatManager()
-
-
Method Details
-
registerRenderer
public <T> SocialChatRenderer.Registered<T> registerRenderer(@NotNull @NotNull Class<T> targetClass, @NotNull @NotNull SocialChatRenderer<T> renderer, @NotNull @NotNull Function<SocialChatRenderer.Builder<T>, SocialChatRenderer.Builder<T>> options) Registers aSocialChatRendererfor a given target class and returns theSocialChatRenderer.Registeredwrapper.- Type Parameters:
T- the audience target type- Parameters:
targetClass- the class this renderer maps audience objects fromrenderer- the renderer implementationoptions- a builder customiser for additional options such as conditions- Returns:
- the registered renderer handle
-
unregisterRenderer
Unregisters the given renderer.- Type Parameters:
T- the audience target type- Parameters:
registeredRenderer- the renderer to unregister
-
unregisterAllRenderers
Unregisters all renderers associated with the given target class.- Type Parameters:
T- the audience target type- Parameters:
targetClass- the target class whose renderers should be removed
-
getRegisteredRenderer
@Nullable public <T> SocialChatRenderer.Registered<T> getRegisteredRenderer(@NotNull @NotNull Class<T> object) Returns the registered renderer for the given class, ornullif none exists.- Type Parameters:
T- the audience target type- Parameters:
object- the class to look up- Returns:
- the registered renderer, or
null
-
getRegisteredRenderer
@Nullable public <T> SocialChatRenderer.Registered<T> getRegisteredRenderer(@NotNull @NotNull Audience audience) Returns the first renderer able to map the given audience object, ornullif none.- Type Parameters:
T- the audience target type- Parameters:
audience- the audience to match- Returns:
- the matching registered renderer, or
null
-
getDefault
Returns the default channel as configured insettings.yml. -
getCachedOrDefault
Returns the user's cached main channel, or the default channel if they don't have one.- Parameters:
user- the user to look up- Returns:
- the resolved main channel
-
groupChannelByCode
Returns theGroupChatChannelwhose name matches"G-" + code, if any.- Parameters:
code- the numeric group code- Returns:
- an optional containing the group channel
-
groupChannelByUser
Returns theGroupChatChannelthe given user is currently a member of, if any.- Parameters:
user- the user to look up- Returns:
- an optional containing the user's group channel
-
getVisibleChannels
Returns all channels the given user has permission to see.- Parameters:
user- the user to filter channels for- Returns:
- the list of visible channels
-
assignChannelsToPlayer
Adds the user to every channel that hasChatChannel.joinByDefault()set and for which they have the required permission.- Parameters:
user- the user to assign channels to
-
hasGroup
Returnstrueif the given user is a member of any group channel.- Parameters:
user- the user to check- Returns:
trueif the user is in a group
-
hasPermission
public boolean hasPermission(@NotNull @NotNull SocialUser user, @NotNull @NotNull ChatChannel channel) Returnstrueif the user satisfies the channel's permission requirement (or the channel has no permission requirement).- Parameters:
user- the user to checkchannel- the channel to check against- Returns:
trueif the user has access
-