Class WbsPlugin

java.lang.Object
org.bukkit.plugin.PluginBase
org.bukkit.plugin.java.JavaPlugin
wbs.utils.util.plugin.WbsPlugin
All Implemented Interfaces:
org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter, org.bukkit.command.TabExecutor, org.bukkit.plugin.Plugin
Direct Known Subclasses:
WbsUtils

public abstract class WbsPlugin extends org.bukkit.plugin.java.JavaPlugin
Somewhat a utility class, use this instead of extending JavaPlugin to gain access to a bunch of messaging options that allows a consistent layout throughout the plugin.
Author:
Weber588
  • Field Details

    • logger

      public Logger logger
    • pluginManager

      public org.bukkit.plugin.PluginManager pluginManager
    • prefix

      public String prefix
  • Constructor Details

    • WbsPlugin

      public WbsPlugin()
  • Method Details

    • registerListener

      protected void registerListener(org.bukkit.event.Listener listener)
    • onEnable

      public abstract void onEnable()
      Specified by:
      onEnable in interface org.bukkit.plugin.Plugin
      Overrides:
      onEnable in class org.bukkit.plugin.java.JavaPlugin
    • setDisplays

      public void setDisplays(String newPrefix, org.bukkit.ChatColor newColour, org.bukkit.ChatColor newHighlight, org.bukkit.ChatColor newErrorColour)
      Set the displays used throughout the plugin for formatting
      Parameters:
      newPrefix - The prefix to appear before standard messages
      newColour - The new default plugin colour
      newHighlight - The new highlight colour
      newErrorColour - The new errors colour
    • getColour

      public org.bukkit.ChatColor getColour()
    • getHighlight

      public org.bukkit.ChatColor getHighlight()
    • getErrorColour

      public org.bukkit.ChatColor getErrorColour()
    • dynamicColourise

      public String dynamicColourise(String string)
      Colourize based on the configured plugin colours
      Parameters:
      string - The string to colourize
      Returns:
      The colourized string
    • colouriseAll

      public List<String> colouriseAll(Collection<String> collection)
    • formatAsTextComponent

      @NotNull public @NotNull net.md_5.bungee.api.chat.TextComponent formatAsTextComponent(@NotNull @NotNull String message)
    • sendMessage

      public void sendMessage(String message, org.bukkit.command.CommandSender sender)
      Send a formatted message with "&" colour codes, where "&w" becomes the configured error colour, "&h" becomes the configured highlight colour, and "&r" resets to the configured main colour.
      Parameters:
      message - The message to send
      sender - The CommandSender to receive the message
    • buildMessage

      @Deprecated public WbsPlugin.MessageBuilder buildMessage(String message, org.bukkit.command.CommandSender sender)
      Deprecated.
      Use buildMessage(String) and pass sender in when sending
      Get a WbsPlugin.MessageBuilder that allows a message to be built using plugin-specific formatting, and supports chat events.
      Parameters:
      message - The base message to appear after the prefix.
      sender - The CommandSender to receive the message
      Returns:
      The message builder.
    • buildMessage

      public WbsMessageBuilder buildMessage(String message)
      Get a WbsPlugin.MessageBuilder that allows a message to be built using plugin-specific formatting, and supports chat events.
      Parameters:
      message - The base message to appear after the prefix.
      Returns:
      The message builder.
    • buildMessageNoPrefix

      @Deprecated public WbsPlugin.MessageBuilder buildMessageNoPrefix(String message, org.bukkit.command.CommandSender sender)
      Deprecated.
      Use buildMessageNoPrefix(String) and pass sender in when sending
      Get a WbsPlugin.MessageBuilder that allows a message to be built using plugin-specific formatting, and supports chat events.
      Parameters:
      message - The message to appear with the plugin's default colour.
      sender - The CommandSender to receive the message
      Returns:
      The message builder.
    • buildMessageNoPrefix

      public WbsMessageBuilder buildMessageNoPrefix(String message)
      Get a WbsPlugin.MessageBuilder that allows a message to be built using plugin-specific formatting, and supports chat events.
      Parameters:
      message - The message to appear with the plugin's default colour.
      Returns:
      The message builder.
    • sendPlaceholderMessage

      public void sendPlaceholderMessage(String message, org.bukkit.command.CommandSender sender)
      Same as sendMessage(String, CommandSender), but automatically fills placeholders with PlaceholderAPI if sender is a Player, and PlaceholderAPI is installed
      Parameters:
      message - The message to send after filling any placeholders
      sender - The CommandSender to receive the message
    • sendMessageNoPrefix

      public void sendMessageNoPrefix(String message, org.bukkit.command.CommandSender sender)
      Send a formatted message with no prefix and formatted "&" colour codes, where "&w" becomes the configured error colour, and "&h" becomes the configured highlight colour
      Parameters:
      message - The message to send
      sender - The CommandSender to receive the message
    • broadcast

      public void broadcast(String message)
      Send a formatted message to all online players.
      Parameters:
      message - The message to broadcast
      See Also:
    • sendActionBar

      public void sendActionBar(String message, org.bukkit.entity.Player player)
      Sends a formatted action bar to the specified player
      Parameters:
      message - The action bar message to send
      player - The player to receive the action bar
      See Also:
    • broadcastActionBar

      public void broadcastActionBar(String message, double radius, org.bukkit.Location loc)
      Sends an action bar to all players within a radius of a given location
      Parameters:
      message - The message to send
      radius - The radius to send the action bar
      loc - The location at which to center the broadcast
    • runAsync

      public int runAsync(@NotNull @NotNull Runnable runnable, @NotNull @NotNull Runnable callback)
      Runs a block of code asynchronously using a BukkitRunnable, and returns the task Id. Once the task finishes, the callback runnable is run in the main thread.
      Parameters:
      runnable - The runnable to execute asynchronously
      callback - The runnable to execute synchronously on the main thread after the async runnable executes
      Returns:
      The Id of the task created
    • runAsync

      public int runAsync(@NotNull @NotNull Runnable runnable)
      Runs a block of code asynchronously using a BukkitRunnable, and returns the task Id.
      Parameters:
      runnable - The runnable to execute asynchronously
      Returns:
      The Id of the task created
    • runSync

      public int runSync(@NotNull @NotNull Runnable runnable)
      Run a block of code in the main thread on the next tick, where it's safe to do minecraft related operations.
      Parameters:
      runnable - The block of code to run
      Returns:
      The Id of the task created
    • getAsync

      public <T> int getAsync(@NotNull @NotNull Supplier<T> getter, @NotNull @NotNull Consumer<T> consumer)