Class TakionLib

java.lang.Object
me.croabeast.takion.TakionLib

public class TakionLib extends Object
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, 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:
  • 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.
    static TakionLib
    fromPlugin(org.bukkit.plugin.Plugin plugin)
    Retrieves the TakionLib instance associated with the given plugin.
    static @NotNull TakionLib
    Retrieves the TakionLib instance associated with the providing plugin (determined from the call stack).
    @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.
    final @NotNull org.bukkit.plugin.Plugin
    Retrieves the plugin instance associated with this TakionLib.
    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.
    replacePrefixKey(String string, boolean remove)
    Replaces the language prefix key in a string with the actual language prefix or an empty string.
    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
    • 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 and a PlayerFormatter 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
    • 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; 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 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