Class TakionLib
- All Implemented Interfaces:
me.croabeast.common.Colorizer
TakionLib integrates various components including:
- Logging: Managed via
TakionLoggerfor both server and plugin-specific logs. - Channel Management: Handled by a
ChannelManagerto define and identify communication channels. - Title Management: Configured through a
TitleManagerimplementation to display titles. - Placeholder Management: Managed by a
PlaceholderManagerto dynamically replace tokens in messages. - Character Management: Provided by a
CharacterManagerfor text alignment and formatting. - Messaging: Facilitated by
MessageSenderfor sending formatted messages to players. - Text Processing: Utilizes
PrismaticAPIand a configurableChatProcessorfor colorization, component parsing, and string modifications.
The library is designed to be initialized by a plugin. Instances of TakionLib are managed in a global map
(via TakionPlugin) and can be retrieved using static methods such as fromPlugin(Plugin) and getLib().
Example usage:
// Initialize TakionLib in your plugin's onEnable method:
TakionLib lib = new TakionLib(this);
// Send a message to a player:
lib.getLoadedSender().addPlaceholder("{player}", player.getName())
.send("Hello, {player}! Welcome to our server.");
// Format a title and send it:
lib.getTitleManager().builder("Welcome", "Enjoy your stay!").send(player);
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTakionLib(org.bukkit.plugin.Plugin plugin) Constructs a newTakionLibinstance and initializes all components. -
Method Summary
Modifier and TypeMethodDescriptionColorizes a string without any player context.Colorizes a string using a single player as context.Colorizes a string and replaces placeholders for a target and parser.colorize(org.bukkit.entity.Player target, org.bukkit.entity.Player parser, String string, boolean processPlayerHead) static TakionLibfromPlugin(org.bukkit.plugin.Plugin plugin) Retrieves the TakionLib instance associated with the given plugin.The prefix used for center alignment in messages.@NotNull me.croabeast.takion.channel.ChannelManagerManages communication channels.@NotNull me.croabeast.takion.character.CharacterManagerManages character formatting and alignment.@NotNull me.croabeast.prismatic.chat.ChatProcessorProcessor used by PrismaticAPI chat components when Takion sends interactive chat.@NotNull me.croabeast.takion.format.FormatManager@NotNull me.croabeast.takion.rule.GameRuleManagerThe language prefix displayed in messages.The key used to denote where the language prefix should be replaced.static @NotNull TakionLibgetLib()Retrieves the TakionLib instance associated with the providing plugin (determined from the call stack).The delimiter used to separate lines in formatted messages.Retrieves loaded bossbar configurations.final me.croabeast.takion.message.MessageSenderReturns a copy of the preloaded MessageSender.Retrieves loaded webhook configurations.me.croabeast.takion.logger.TakionLoggerThe logger for plugin-specific logs.@NotNull me.croabeast.takion.placeholder.PlaceholderManagerManages dynamic placeholder replacement.final @NotNull org.bukkit.plugin.PluginRetrieves the plugin instance associated with this TakionLib.me.croabeast.scheduler.GlobalSchedulerThe global scheduler used for scheduling tasks across the server.me.croabeast.takion.logger.TakionLoggerThe logger for server-level logs (configured to not use plugin logger).@NotNull me.croabeast.takion.message.TitleManagerManages title messages.loadMapFromConfiguration(org.bukkit.configuration.ConfigurationSection section) Loads a mapping from string keys to configuration sections from the provided configuration.Replaces placeholders and applies player formatting functions on a string.replacePrefixKey(String string, boolean remove) Replaces the language prefix key in a string with the actual language prefix or an empty string.voidsetCenterPrefix(String centerPrefix) The prefix used for center alignment in messages.@NotNull TakionLibsetChatProcessor(@NotNull me.croabeast.prismatic.chat.ChatProcessor chatProcessor) Sets the processor used by PrismaticAPI chat components created by Takion.voidsetLangPrefix(String langPrefix) The language prefix displayed in messages.voidsetLangPrefixKey(String langPrefixKey) The key used to denote where the language prefix should be replaced.voidsetLineSeparator(String lineSeparator) The delimiter used to separate lines in formatted messages.voidsetLoadedSender(me.croabeast.takion.message.MessageSender loadedSender) A preloaded instance ofMessageSenderused as a template.voidsetLogger(me.croabeast.takion.logger.TakionLogger logger) The logger for plugin-specific logs.voidsetScheduler(me.croabeast.scheduler.GlobalScheduler scheduler) The global scheduler used for scheduling tasks across the server.voidsetServerLogger(me.croabeast.takion.logger.TakionLogger serverLogger) The logger for server-level logs (configured to not use plugin logger).String[]Splits a string using the configured line separator with no limit.String[]splitString(String s, int limit) Splits a string using the configured line separator, with an optional limit on the number of splits.
-
Constructor Details
-
TakionLib
public TakionLib(org.bukkit.plugin.Plugin plugin) Constructs a newTakionLibinstance and initializes all components.- Parameters:
plugin- the plugin instance associated with this library (must not benull)
-
-
Method Details
-
getPlugin
@NotNull public final @NotNull org.bukkit.plugin.Plugin getPlugin()Retrieves the plugin instance associated with this TakionLib.- Returns:
- the plugin (never
null) - Throws:
NullPointerException- if the plugin is not set
-
getLoadedSender
public final me.croabeast.takion.message.MessageSender getLoadedSender()Returns a copy of the preloaded MessageSender.This allows modifications and sending of messages without altering the original sender.
- Returns:
- a copied
MessageSenderinstance
-
setChatProcessor
@NotNull public @NotNull TakionLib setChatProcessor(@NotNull @NotNull me.croabeast.prismatic.chat.ChatProcessor chatProcessor) Sets the processor used by PrismaticAPI chat components created by Takion.Changing this value affects interactive chat parsing, including messages sent through the chat channel. Use the default processor unless a plugin needs to inject additional preprocessing.
- Parameters:
chatProcessor- processor to use for interactive chat components- Returns:
- this library instance
- Since:
- 1.6.3
-
loadMapFromConfiguration
@NotNull protected @NotNull TreeMap<String,org.bukkit.configuration.ConfigurationSection> loadMapFromConfiguration(org.bukkit.configuration.ConfigurationSection section) Loads a mapping from string keys to configuration sections from the provided configuration.Only keys with a corresponding non-null configuration section are included.
- Parameters:
section- the configuration section to load from- Returns:
- a
TreeMapmapping keys to their respective configuration sections
-
getLoadedWebhooks
@NotNull public @NotNull TreeMap<String,org.bukkit.configuration.ConfigurationSection> getLoadedWebhooks()Retrieves loaded webhook configurations.- Returns:
- an empty
TreeMap(to be implemented as needed)
-
getLoadedBossbars
@NotNull public @NotNull TreeMap<String,org.bukkit.configuration.ConfigurationSection> getLoadedBossbars()Retrieves loaded bossbar configurations.- Returns:
- an empty
TreeMap(to be implemented as needed)
-
replacePrefixKey
Replaces the language prefix key in a string with the actual language prefix or an empty string.This is used to dynamically insert the plugin's language prefix into messages.
- Parameters:
string- the input stringremove- iftrue, the prefix is removed; otherwise, it is replaced withlangPrefix- Returns:
- the resulting string with the language prefix key replaced
-
splitString
Splits a string using the configured line separator, with an optional limit on the number of splits.- Parameters:
s- the string to splitlimit- the maximum number of splits (0 for no limit)- Returns:
- an array of substrings
-
splitString
Splits a string using the configured line separator with no limit.- Parameters:
s- the string to split- Returns:
- an array of substrings
-
replace
Replaces placeholders and applies player formatting functions on a string.This method uses the
PlaceholderManagerto process the string, and then applies a character action for further formatting.- Parameters:
parser- the player context for placeholder replacementstring- the input message string- Returns:
- the processed string after placeholder and function application
-
replace
-
colorize
public String colorize(org.bukkit.entity.Player target, org.bukkit.entity.Player parser, String string) Colorizes a string and replaces placeholders for a target and parser.- Specified by:
colorizein interfaceme.croabeast.common.Colorizer- Parameters:
target- the target player to receive the colored text; ifnull, the parser is usedparser- the player context for formattingstring- the input message string- Returns:
- the final colorized and formatted message
-
colorize
-
colorize
Colorizes a string using a single player as context.- Parameters:
player- the player to use for formatting contextstring- the input message string- Returns:
- the colorized message
-
colorize
Colorizes a string without any player context.- Parameters:
string- the input message string- Returns:
- the colorized message
-
fromPlugin
Retrieves the TakionLib instance associated with the given plugin.- Parameters:
plugin- the plugin for which to retrieve the TakionLib instance- Returns:
- the corresponding TakionLib instance, or the default if not found
-
getLib
Retrieves the TakionLib instance associated with the providing plugin (determined from the call stack).Not recommended for use in any context other than the main plugin class.
- Returns:
- the TakionLib instance, or the default instance if none is found
-
getScheduler
public me.croabeast.scheduler.GlobalScheduler getScheduler()The global scheduler used for scheduling tasks across the server.This scheduler is used for managing asynchronous tasks and periodic operations that need to run independently of the plugin's lifecycle.
Example usage:
Note: This field can be// Schedule a task to run after 5 seconds: TakionLib.getLib().getScheduler().runTaskLater(() -> { // Your task code here }, 100L); // 100 ticks = 5 secondsnullif the plugin is not set or if the scheduler is not available. It is recommended to check for null before using the scheduler.- See Also:
-
getServerLogger
public me.croabeast.takion.logger.TakionLogger getServerLogger()The logger for server-level logs (configured to not use plugin logger). -
getLogger
public me.croabeast.takion.logger.TakionLogger getLogger()The logger for plugin-specific logs. -
getChannelManager
@NotNull public @NotNull me.croabeast.takion.channel.ChannelManager getChannelManager()Manages communication channels. -
getTitleManager
@NotNull public @NotNull me.croabeast.takion.message.TitleManager getTitleManager()Manages title messages. -
getPlaceholderManager
@NotNull public @NotNull me.croabeast.takion.placeholder.PlaceholderManager getPlaceholderManager()Manages dynamic placeholder replacement. -
getCharacterManager
@NotNull public @NotNull me.croabeast.takion.character.CharacterManager getCharacterManager()Manages character formatting and alignment. -
getFormatManager
@NotNull public @NotNull me.croabeast.takion.format.FormatManager getFormatManager() -
getGameRuleManager
@NotNull public @NotNull me.croabeast.takion.rule.GameRuleManager getGameRuleManager() -
getLangPrefix
The language prefix displayed in messages. -
getLangPrefixKey
The key used to denote where the language prefix should be replaced. -
getLineSeparator
The delimiter used to separate lines in formatted messages.This is stored as a regex pattern (e.g., Pattern.quote("<n>")).
-
getCenterPrefix
The prefix used for center alignment in messages. -
setScheduler
public void setScheduler(me.croabeast.scheduler.GlobalScheduler scheduler) The global scheduler used for scheduling tasks across the server.This scheduler is used for managing asynchronous tasks and periodic operations that need to run independently of the plugin's lifecycle.
Example usage:
Note: This field can be// Schedule a task to run after 5 seconds: TakionLib.getLib().getScheduler().runTaskLater(() -> { // Your task code here }, 100L); // 100 ticks = 5 secondsnullif the plugin is not set or if the scheduler is not available. It is recommended to check for null before using the scheduler.- See Also:
-
setServerLogger
public void setServerLogger(me.croabeast.takion.logger.TakionLogger serverLogger) The logger for server-level logs (configured to not use plugin logger). -
setLogger
public void setLogger(me.croabeast.takion.logger.TakionLogger logger) The logger for plugin-specific logs. -
setLangPrefix
The language prefix displayed in messages. -
setLangPrefixKey
The key used to denote where the language prefix should be replaced. -
setLineSeparator
The delimiter used to separate lines in formatted messages.This is stored as a regex pattern (e.g., Pattern.quote("<n>")).
-
setCenterPrefix
The prefix used for center alignment in messages. -
setLoadedSender
public void setLoadedSender(me.croabeast.takion.message.MessageSender loadedSender) A preloaded instance ofMessageSenderused as a template. -
getChatProcessor
@NotNull public @NotNull me.croabeast.prismatic.chat.ChatProcessor getChatProcessor()Processor used by PrismaticAPI chat components when Takion sends interactive chat.The default processor keeps Takion behavior intact by applying placeholder replacement, small-caps formatting, character alignment, colorization, and the configured line separator. Plugins can replace it through
setChatProcessor(ChatProcessor)when they need custom component preprocessing.
-