Package me.croabeast.takion.channel
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.Flagwhich 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 ClassesModifier and TypeInterfaceDescriptionstatic enumEnumeration of possible channel types. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidAdds 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.getFlag()Retrieves the flag that represents the type of messages sent through this channel.@NotNull StringgetName()Retrieves the unique name of the channel.@Nullable StringRetrieves the regex pattern used by this channel for matching messages.default @NotNull StringRetrieves the primary prefix of the channel.Retrieves the list of prefixes associated with this channel.booleanIndicates whether the channel's matching and formatting operations are case-sensitive.@NotNull MatcherCreates aMatcherfor the given input string using this channel's pattern.default voidremovePrefix(@NotNull String prefix) Removes a prefix from the channel.default booleanSends a formatted message using a default target (usually a broadcast or system message).default booleansend(Collection<? extends org.bukkit.entity.Player> targets, String input) Sends a formatted message to a collection of target players using no parser context.booleansend(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 booleanSends a formatted message to a single player, using that player as both target and parser.default booleanSends a formatted message to a single player, optionally using a separate parser context.voidsetCaseSensitive(boolean sensitive) Sets whether the channel's operations should be case-sensitive.voidsetPattern(@Nullable String pattern) Sets the regex pattern to be used for matching messages in this channel.default voidsetPrefixes(@NotNull Collection<String> prefixes) Replaces the current prefixes with a new collection of prefixes.
-
Method Details
-
getName
Retrieves the unique name of the channel.- Returns:
- the channel name as a
String
-
getPrefixes
Retrieves the list of prefixes associated with this channel.The first element of this list is considered the primary prefix.
- Returns:
- a
Listof prefix strings
-
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
Replaces the current prefixes with a new collection of prefixes.- Parameters:
prefixes- a collection of new prefix strings (must not benull)
-
addPrefix
Adds a new prefix to the channel.- Parameters:
prefix- the prefix string to add (must not benull)
-
removePrefix
Removes a prefix from the channel.- Parameters:
prefix- the prefix string to remove (must not benull)
-
isCaseSensitive
boolean isCaseSensitive()Indicates whether the channel's matching and formatting operations are case-sensitive.- Returns:
trueif case-sensitive;falseotherwise
-
setCaseSensitive
void setCaseSensitive(boolean sensitive) Sets whether the channel's operations should be case-sensitive.- Parameters:
sensitive-truefor case-sensitive behavior;falsefor case-insensitive
-
getPattern
Retrieves the regex pattern used by this channel for matching messages.- Returns:
- the regex pattern as a
String, ornullif not set
-
setPattern
Sets the regex pattern to be used for matching messages in this channel.- Parameters:
pattern- the regex pattern as aString(can benull)
-
matcher
Creates aMatcherfor the given input string using this channel's pattern.- Parameters:
string- the input string to match against the channel's pattern- Returns:
- a
Matcherinstance 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 messageparser- 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 (ifnull, the channel may use a default)parser- the player context for formatting the messagemessage- the message to send- Returns:
trueif the message was sent successfully;falseotherwise
-
send
Sends a formatted message to a collection of target players using no parser context.- Parameters:
targets- the collection of players to send the message toinput- the message to send- Returns:
trueif the message was sent successfully;falseotherwise
-
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; ifnull, the parser is used as the targetparser- the player context for formatting the messageinput- the message to send- Returns:
trueif the message was sent successfully;falseotherwise
-
send
Sends a formatted message to a single player, using that player as both target and parser.- Parameters:
player- the player to send the message toinput- the message to send- Returns:
trueif the message was sent successfully;falseotherwise
-
send
Sends a formatted message using a default target (usually a broadcast or system message).- Parameters:
input- the message to send- Returns:
trueif the message was sent successfully;falseotherwise
-