Interface Channel


public interface Channel
Represents a communication channel for sending messages to players.

A Channel defines how messages are formatted, parsed, and delivered, including support for custom prefixes, patterns, and case sensitivity settings. It supports multiple types of message delivery, such as chat, action bar, titles, boss bars, JSON, or webhook-based messages.

Key functionalities include:

  • Managing channel prefixes: Each channel can have one or more prefixes, where the first prefix is considered the primary prefix.
  • Message formatting: The channel can define a regex pattern to match messages and then format them based on a target and parser context.
  • Message delivery: Channels provide methods to send formatted messages to one or more players.
  • Flag specification: Each channel is associated with a Channel.Flag which indicates the type of message (e.g. CHAT, ACTION_BAR, etc.).

Example usage:


 // Assuming an implementation of Channel exists, e.g., ChatChannel
 Channel channel = new ChatChannel("global");
 channel.addPrefix("[Global]");
 String formatted = channel.formatString(targetPlayer, parserPlayer, "Hello, world!");
 channel.send(targetPlayers, parserPlayer, formatted);

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Enumeration of possible channel types.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    addPrefix(@NotNull String prefix)
    Adds a new prefix to the channel.
    formatString(org.bukkit.entity.Player target, org.bukkit.entity.Player parser, String string)
    Formats a message string according to the channel's formatting rules.
    Retrieves the flag that represents the type of messages sent through this channel.
    @NotNull String
    Retrieves the unique name of the channel.
    @Nullable String
    Retrieves the regex pattern used by this channel for matching messages.
    default @NotNull String
    Retrieves the primary prefix of the channel.
    @NotNull List<String>
    Retrieves the list of prefixes associated with this channel.
    boolean
    Indicates whether the channel's matching and formatting operations are case-sensitive.
    @NotNull Matcher
    matcher(String string)
    Creates a Matcher for the given input string using this channel's pattern.
    default void
    removePrefix(@NotNull String prefix)
    Removes a prefix from the channel.
    default boolean
    send(String input)
    Sends a formatted message using a default target (usually a broadcast or system message).
    default boolean
    send(Collection<? extends org.bukkit.entity.Player> targets, String input)
    Sends a formatted message to a collection of target players using no parser context.
    boolean
    send(Collection<? extends org.bukkit.entity.Player> targets, org.bukkit.entity.Player parser, String message)
    Sends a formatted message to a collection of target players.
    default boolean
    send(org.bukkit.entity.Player player, String input)
    Sends a formatted message to a single player, using that player as both target and parser.
    default boolean
    send(org.bukkit.entity.Player target, org.bukkit.entity.Player parser, String input)
    Sends a formatted message to a single player, optionally using a separate parser context.
    void
    setCaseSensitive(boolean sensitive)
    Sets whether the channel's operations should be case-sensitive.
    void
    setPattern(@Nullable String pattern)
    Sets the regex pattern to be used for matching messages in this channel.
    default void
    setPrefixes(@NotNull Collection<String> prefixes)
    Replaces the current prefixes with a new collection of prefixes.
  • Method Details

    • getName

      @NotNull @NotNull String getName()
      Retrieves the unique name of the channel.
      Returns:
      the channel name as a String
    • getPrefixes

      @NotNull @NotNull List<String> getPrefixes()
      Retrieves the list of prefixes associated with this channel.

      The first element of this list is considered the primary prefix.

      Returns:
      a List of prefix strings
    • getPrefix

      @NotNull default @NotNull String getPrefix()
      Retrieves the primary prefix of the channel.

      This is a convenience method that returns the first prefix in the list.

      Returns:
      the primary prefix as a String
    • setPrefixes

      default void setPrefixes(@NotNull @NotNull Collection<String> prefixes)
      Replaces the current prefixes with a new collection of prefixes.
      Parameters:
      prefixes - a collection of new prefix strings (must not be null)
    • addPrefix

      default void addPrefix(@NotNull @NotNull String prefix)
      Adds a new prefix to the channel.
      Parameters:
      prefix - the prefix string to add (must not be null)
    • removePrefix

      default void removePrefix(@NotNull @NotNull String prefix)
      Removes a prefix from the channel.
      Parameters:
      prefix - the prefix string to remove (must not be null)
    • isCaseSensitive

      boolean isCaseSensitive()
      Indicates whether the channel's matching and formatting operations are case-sensitive.
      Returns:
      true if case-sensitive; false otherwise
    • setCaseSensitive

      void setCaseSensitive(boolean sensitive)
      Sets whether the channel's operations should be case-sensitive.
      Parameters:
      sensitive - true for case-sensitive behavior; false for case-insensitive
    • getPattern

      @Nullable @Nullable String getPattern()
      Retrieves the regex pattern used by this channel for matching messages.
      Returns:
      the regex pattern as a String, or null if not set
    • setPattern

      void setPattern(@Nullable @Nullable String pattern)
      Sets the regex pattern to be used for matching messages in this channel.
      Parameters:
      pattern - the regex pattern as a String (can be null)
    • matcher

      @NotNull @NotNull Matcher matcher(String string)
      Creates a Matcher for the given input string using this channel's pattern.
      Parameters:
      string - the input string to match against the channel's pattern
      Returns:
      a Matcher instance for the provided string
    • formatString

      String formatString(org.bukkit.entity.Player target, org.bukkit.entity.Player parser, String string)
      Formats a message string according to the channel's formatting rules.

      The method may apply prefixes, modify cases, or perform other transformations to produce the final message.

      Parameters:
      target - the player who will receive the message
      parser - the player context used for formatting (may affect colorization, etc.)
      string - the raw message to format
      Returns:
      the formatted message as a String
    • getFlag

      Channel.Flag getFlag()
      Retrieves the flag that represents the type of messages sent through this channel.
      Returns:
      the channel's Channel.Flag
    • send

      boolean send(Collection<? extends org.bukkit.entity.Player> targets, org.bukkit.entity.Player parser, String message)
      Sends a formatted message to a collection of target players.

      The message is processed according to the channel's formatting rules before delivery.

      Parameters:
      targets - the collection of players to send the message to (if null, the channel may use a default)
      parser - the player context for formatting the message
      message - the message to send
      Returns:
      true if the message was sent successfully; false otherwise
    • send

      default boolean send(Collection<? extends org.bukkit.entity.Player> targets, String input)
      Sends a formatted message to a collection of target players using no parser context.
      Parameters:
      targets - the collection of players to send the message to
      input - the message to send
      Returns:
      true if the message was sent successfully; false otherwise
    • send

      default boolean send(org.bukkit.entity.Player target, org.bukkit.entity.Player parser, String input)
      Sends a formatted message to a single player, optionally using a separate parser context.
      Parameters:
      target - the target player to send the message to; if null, the parser is used as the target
      parser - the player context for formatting the message
      input - the message to send
      Returns:
      true if the message was sent successfully; false otherwise
    • send

      default boolean send(org.bukkit.entity.Player player, String input)
      Sends a formatted message to a single player, using that player as both target and parser.
      Parameters:
      player - the player to send the message to
      input - the message to send
      Returns:
      true if the message was sent successfully; false otherwise
    • send

      default boolean send(String input)
      Sends a formatted message using a default target (usually a broadcast or system message).
      Parameters:
      input - the message to send
      Returns:
      true if the message was sent successfully; false otherwise