Class TakionLib

java.lang.Object
me.croabeast.takion.TakionLib
All Implemented Interfaces:
me.croabeast.common.Colorizer

public class TakionLib extends Object implements me.croabeast.common.Colorizer
The central class of the Takion library that provides a comprehensive suite of utilities for managing messaging, logging, placeholder replacement, and other plugin functionalities.

TakionLib integrates various components including:

  • Logging: Managed via TakionLogger for both server and plugin-specific logs.
  • Channel Management: Handled by a ChannelManager to define and identify communication channels.
  • Title Management: Configured through a TitleManager implementation to display titles.
  • Placeholder Management: Managed by a PlaceholderManager to dynamically replace tokens in messages.
  • Character Management: Provided by a CharacterManager for text alignment and formatting.
  • Messaging: Facilitated by MessageSender for sending formatted messages to players.
  • Text Processing: Utilizes PrismaticAPI and a configurable ChatProcessor for 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:
  • TakionLogger
  • ChannelManager
  • TitleManager
  • PlaceholderManager
  • CharacterManager
  • MessageSender
  • PrismaticAPI
  • Constructor Summary

    Constructors
    Constructor
    Description
    TakionLib(org.bukkit.plugin.Plugin plugin)
    Constructs a new TakionLib instance and initializes all components.
  • Method Summary

    Modifier and Type
    Method
    Description
    colorize(String string)
    Colorizes a string without any player context.
    colorize(org.bukkit.entity.Player player, String string)
    Colorizes a string using a single player as context.
    colorize(org.bukkit.entity.Player target, org.bukkit.entity.Player parser, String string)
    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 TakionLib
    fromPlugin(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.ChannelManager
    Manages communication channels.
    @NotNull me.croabeast.takion.character.CharacterManager
    Manages character formatting and alignment.
    @NotNull me.croabeast.prismatic.chat.ChatProcessor
    Processor used by PrismaticAPI chat components when Takion sends interactive chat.
    @NotNull me.croabeast.takion.format.FormatManager
     
    @NotNull me.croabeast.takion.rule.GameRuleManager
     
    The language prefix displayed in messages.
    The key used to denote where the language prefix should be replaced.
    static @NotNull TakionLib
    Retrieves the TakionLib instance associated with the providing plugin (determined from the call stack).
    The delimiter used to separate lines in formatted messages.
    @NotNull TreeMap<String,org.bukkit.configuration.ConfigurationSection>
    Retrieves loaded bossbar configurations.
    final me.croabeast.takion.message.MessageSender
    Returns a copy of the preloaded MessageSender.
    @NotNull TreeMap<String,org.bukkit.configuration.ConfigurationSection>
    Retrieves loaded webhook configurations.
    me.croabeast.takion.logger.TakionLogger
    The logger for plugin-specific logs.
    @NotNull me.croabeast.takion.placeholder.PlaceholderManager
    Manages dynamic placeholder replacement.
    final @NotNull org.bukkit.plugin.Plugin
    Retrieves the plugin instance associated with this TakionLib.
    me.croabeast.scheduler.GlobalScheduler
    The global scheduler used for scheduling tasks across the server.
    me.croabeast.takion.logger.TakionLogger
    The logger for server-level logs (configured to not use plugin logger).
    @NotNull me.croabeast.takion.message.TitleManager
    Manages title messages.
    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.
    replace(org.bukkit.entity.Player parser, String string)
    Replaces placeholders and applies player formatting functions on a string.
    replace(org.bukkit.entity.Player parser, String string, boolean processPlayerHead)
     
    replacePrefixKey(String string, boolean remove)
    Replaces the language prefix key in a string with the actual language prefix or an empty string.
    void
    setCenterPrefix(String centerPrefix)
    The prefix used for center alignment in messages.
    @NotNull TakionLib
    setChatProcessor(@NotNull me.croabeast.prismatic.chat.ChatProcessor chatProcessor)
    Sets the processor used by PrismaticAPI chat components created by Takion.
    void
    setLangPrefix(String langPrefix)
    The language prefix displayed in messages.
    void
    setLangPrefixKey(String langPrefixKey)
    The key used to denote where the language prefix should be replaced.
    void
    setLineSeparator(String lineSeparator)
    The delimiter used to separate lines in formatted messages.
    void
    setLoadedSender(me.croabeast.takion.message.MessageSender loadedSender)
    A preloaded instance of MessageSender used as a template.
    void
    setLogger(me.croabeast.takion.logger.TakionLogger logger)
    The logger for plugin-specific logs.
    void
    setScheduler(me.croabeast.scheduler.GlobalScheduler scheduler)
    The global scheduler used for scheduling tasks across the server.
    void
    setServerLogger(me.croabeast.takion.logger.TakionLogger serverLogger)
    The logger for server-level logs (configured to not use plugin logger).
    Splits a string using the configured line separator with no limit.
    splitString(String s, int limit)
    Splits a string using the configured line separator, with an optional limit on the number of splits.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TakionLib

      public TakionLib(org.bukkit.plugin.Plugin plugin)
      Constructs a new TakionLib instance and initializes all components.
      Parameters:
      plugin - the plugin instance associated with this library (must not be null)
  • 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 MessageSender instance
    • 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 TreeMap mapping 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

      public String replacePrefixKey(String string, boolean remove)
      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 string
      remove - if true, the prefix is removed; otherwise, it is replaced with langPrefix
      Returns:
      the resulting string with the language prefix key replaced
    • splitString

      public String[] splitString(String s, int limit)
      Splits a string using the configured line separator, with an optional limit on the number of splits.
      Parameters:
      s - the string to split
      limit - the maximum number of splits (0 for no limit)
      Returns:
      an array of substrings
    • splitString

      public String[] splitString(String s)
      Splits a string using the configured line separator with no limit.
      Parameters:
      s - the string to split
      Returns:
      an array of substrings
    • replace

      public String replace(org.bukkit.entity.Player parser, String string)
      Replaces placeholders and applies player formatting functions on a string.

      This method uses the PlaceholderManager to process the string, and then applies a character action for further formatting.

      Parameters:
      parser - the player context for placeholder replacement
      string - the input message string
      Returns:
      the processed string after placeholder and function application
    • replace

      public String replace(org.bukkit.entity.Player parser, String string, boolean processPlayerHead)
    • 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:
      colorize in interface me.croabeast.common.Colorizer
      Parameters:
      target - the target player to receive the colored text; if null, the parser is used
      parser - the player context for formatting
      string - the input message string
      Returns:
      the final colorized and formatted message
    • colorize

      public String colorize(org.bukkit.entity.Player target, org.bukkit.entity.Player parser, String string, boolean processPlayerHead)
    • colorize

      public String colorize(org.bukkit.entity.Player player, String string)
      Colorizes a string using a single player as context.
      Parameters:
      player - the player to use for formatting context
      string - the input message string
      Returns:
      the colorized message
    • colorize

      public String colorize(String string)
      Colorizes a string without any player context.
      Parameters:
      string - the input message string
      Returns:
      the colorized message
    • fromPlugin

      public static TakionLib fromPlugin(org.bukkit.plugin.Plugin plugin)
      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

      @NotNull public static @NotNull TakionLib 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:

      
       // Schedule a task to run after 5 seconds:
       TakionLib.getLib().getScheduler().runTaskLater(() -> {
           // Your task code here
       }, 100L); // 100 ticks = 5 seconds
       
      Note: This field can be null if 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:
      • GlobalScheduler
    • 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

      public String getLangPrefix()
      The language prefix displayed in messages.
    • getLangPrefixKey

      public String getLangPrefixKey()
      The key used to denote where the language prefix should be replaced.
    • getLineSeparator

      public String getLineSeparator()
      The delimiter used to separate lines in formatted messages.

      This is stored as a regex pattern (e.g., Pattern.quote("<n>")).

    • getCenterPrefix

      public String 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:

      
       // Schedule a task to run after 5 seconds:
       TakionLib.getLib().getScheduler().runTaskLater(() -> {
           // Your task code here
       }, 100L); // 100 ticks = 5 seconds
       
      Note: This field can be null if 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:
      • GlobalScheduler
    • 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

      public void setLangPrefix(String langPrefix)
      The language prefix displayed in messages.
    • setLangPrefixKey

      public void setLangPrefixKey(String langPrefixKey)
      The key used to denote where the language prefix should be replaced.
    • setLineSeparator

      public void setLineSeparator(String lineSeparator)
      The delimiter used to separate lines in formatted messages.

      This is stored as a regex pattern (e.g., Pattern.quote("<n>")).

    • setCenterPrefix

      public void setCenterPrefix(String centerPrefix)
      The prefix used for center alignment in messages.
    • setLoadedSender

      public void setLoadedSender(me.croabeast.takion.message.MessageSender loadedSender)
      A preloaded instance of MessageSender used 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.