Class ChatManager

java.lang.Object
ovh.mythmc.social.api.chat.ChatManager

public final class ChatManager extends Object
Manages chat channels, renderers and the per-session chat history.

Access the singleton via Social.getChatManager().

  • Field Details

  • Constructor Details

    • ChatManager

      public ChatManager()
  • Method Details

    • registerRenderer

      Registers a SocialChatRenderer for a given target class and returns the SocialChatRenderer.Registered wrapper.
      Type Parameters:
      T - the audience target type
      Parameters:
      targetClass - the class this renderer maps audience objects from
      renderer - the renderer implementation
      options - a builder customiser for additional options such as conditions
      Returns:
      the registered renderer handle
    • unregisterRenderer

      public <T> void unregisterRenderer(@NotNull SocialChatRenderer.Registered<T> registeredRenderer)
      Unregisters the given renderer.
      Type Parameters:
      T - the audience target type
      Parameters:
      registeredRenderer - the renderer to unregister
    • unregisterAllRenderers

      public <T> void unregisterAllRenderers(@NotNull @NotNull Class<T> targetClass)
      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, or null if 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, or null if none.
      Type Parameters:
      T - the audience target type
      Parameters:
      audience - the audience to match
      Returns:
      the matching registered renderer, or null
    • getDefault

      public ChatChannel getDefault()
      Returns the default channel as configured in settings.yml.
    • getCachedOrDefault

      public ChatChannel getCachedOrDefault(@NotNull @NotNull SocialUser user)
      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

      public Optional<GroupChatChannel> groupChannelByCode(int code)
      Returns the GroupChatChannel whose name matches "G-" + code, if any.
      Parameters:
      code - the numeric group code
      Returns:
      an optional containing the group channel
    • groupChannelByUser

      public Optional<GroupChatChannel> groupChannelByUser(@NotNull @NotNull SocialUser user)
      Returns the GroupChatChannel the 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

      public List<ChatChannel> getVisibleChannels(@NotNull @NotNull SocialUser user)
      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

      public void assignChannelsToPlayer(@NotNull @NotNull SocialUser user)
      Adds the user to every channel that has ChatChannel.joinByDefault() set and for which they have the required permission.
      Parameters:
      user - the user to assign channels to
    • hasGroup

      public boolean hasGroup(@NotNull @NotNull SocialUser user)
      Returns true if the given user is a member of any group channel.
      Parameters:
      user - the user to check
      Returns:
      true if the user is in a group
    • hasPermission

      public boolean hasPermission(@NotNull @NotNull SocialUser user, @NotNull @NotNull ChatChannel channel)
      Returns true if the user satisfies the channel's permission requirement (or the channel has no permission requirement).
      Parameters:
      user - the user to check
      channel - the channel to check against
      Returns:
      true if the user has access