Class TakionLib
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
PrismaticAPI,StringApplier, and related utilities for colorization 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.static TakionLibfromPlugin(org.bukkit.plugin.Plugin plugin) Retrieves the TakionLib instance associated with the given plugin.static @NotNull TakionLibgetLib()Retrieves the TakionLib instance associated with the providing plugin (determined from the call stack).Retrieves loaded bossbar configurations.final me.croabeast.takion.message.MessageSenderReturns a copy of the preloaded MessageSender.Retrieves loaded webhook configurations.final @NotNull org.bukkit.plugin.PluginRetrieves the plugin instance associated with this TakionLib.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.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
-
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
PlaceholderManagerand aPlayerFormatterto 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
-
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.- 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
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
-