mondocommand
Class ChatMagic

java.lang.Object
  extended by mondocommand.ChatMagic

public final class ChatMagic
extends Object

I got tired of doing ChatColor.GREEN all over the place.

This class lets you do a format string that looks like:

colorize("{BLUE}Welcome, {GREEN}%s{BLUE}! You are an %s", player.getName(), "Admin");

The system is based upon two different concepts put together. Firstly, the ability for string interpolation using printf() style interpolation in String.format(java.lang.String, java.lang.Object...) and then a simple substitution map which turns the colors available in the ChatColor class into useful interpolation strings like {BLUE}.

For speed, the template strings are cached in a dictionary lookup, so the color interpolation can be done once per template. For this reason, any variable strings should not be joined into the template string, but should be provided as %s-style interpolations.

See Also:
ChatColor, String.format(java.lang.String, java.lang.Object...)

Constructor Summary
ChatMagic()
           
 
Method Summary
static String colorize(String template, Object... args)
          Colorize this string with Bukkit ChatColors and interpolate any variables.
static void registerAlias(String alias, org.bukkit.ChatColor color)
          Register an alias for a color.
static void registerDefaultAlias(String alias, org.bukkit.ChatColor color)
          Register an alias for a color, but only if it doesn't already exist.
static void send(org.bukkit.command.CommandSender sender, String template, Object... args)
          A convenience for sending messages to a player colorized.
static void sendRaw(org.bukkit.conversations.Conversable c, String template, Object... args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatMagic

public ChatMagic()
Method Detail

registerAlias

public static void registerAlias(String alias,
                                 org.bukkit.ChatColor color)
Register an alias for a color.

For example,
registerAlias("{ERROR}", ChatColor.RED)

Parameters:
alias - The alias string to use. Must include brackets.
color - A ChatColor.
See Also:
ChatColor

registerDefaultAlias

public static void registerDefaultAlias(String alias,
                                        org.bukkit.ChatColor color)
Register an alias for a color, but only if it doesn't already exist.

Parameters:
alias - The alias string to use. Must include brackets.
color - A ChatColor.

colorize

public static String colorize(String template,
                              Object... args)
Colorize this string with Bukkit ChatColors and interpolate any variables.

Parameters:
template - A template string in printf-format.
args - As many arguments as are expected by %-interpolations.
Returns:
A string which has been color-formatted

send

public static void send(org.bukkit.command.CommandSender sender,
                        String template,
                        Object... args)
A convenience for sending messages to a player colorized.

Parameters:
sender - A CommandSender or player.
template - A Colorizing template.
args - Variadic arguments as in String.format
See Also:
colorize(java.lang.String, java.lang.Object...)

sendRaw

public static void sendRaw(org.bukkit.conversations.Conversable c,
                           String template,
                           Object... args)


Copyright © 2013. All Rights Reserved.