|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object mondocommand.ChatMagic
public final class ChatMagic
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.
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 |
---|
public ChatMagic()
Method Detail |
---|
public static void registerAlias(String alias, org.bukkit.ChatColor color)
For example,
registerAlias("{ERROR}", ChatColor.RED)
alias
- The alias string to use. Must include brackets.color
- A ChatColor.ChatColor
public static void registerDefaultAlias(String alias, org.bukkit.ChatColor color)
alias
- The alias string to use. Must include brackets.color
- A ChatColor.public static String colorize(String template, Object... args)
template
- A template string in printf-format.args
- As many arguments as are expected by %-interpolations.
public static void send(org.bukkit.command.CommandSender sender, String template, Object... args)
sender
- A CommandSender or player.template
- A Colorizing template.args
- Variadic arguments as in String.formatcolorize(java.lang.String, java.lang.Object...)
public static void sendRaw(org.bukkit.conversations.Conversable c, String template, Object... args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |