Allow custom colours and hide prefix

This commit is contained in:
lol768 2012-10-21 22:41:17 +02:00 committed by md_5
parent 0d443603be
commit e2c357ccb0
2 changed files with 17 additions and 8 deletions

View File

@ -139,15 +139,16 @@ public enum ChatColor
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
}
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
{
char[] b = textToTranslate.toCharArray();
for (int i = 0; i < b.length - 1; i++)
{
if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1)
if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1)
{
b[i] = ChatColor.COLOR_CHAR;
b[i+1] = Character.toLowerCase(b[i+1]);
b[i + 1] = Character.toLowerCase(b[i + 1]);
}
}
return new String(b);

View File

@ -18,15 +18,23 @@ public class CommandAlert extends Command
}
if (args.length == 0)
{
sender.sendMessage(ChatColor.RED + "Please follow this command by an announcement to make");
sender.sendMessage(ChatColor.RED + "You must supply a message.");
} else
{
StringBuilder builder = new StringBuilder();
if (!args[0].contains("&h")) //They want to hide the alert prefix
{
builder.append(ChatColor.DARK_PURPLE);
builder.append(" [Alert] ");
builder.append("[Alert] "); //No space at start.
} else
{
args[0].replaceAll("&h", ""); //Remove hide control code from message
}
for (String s : args)
{
builder.append(s);
builder.append(ChatColor.translateAlternateColorCodes('&', s)); //Allow custom colours
builder.append(" ");
}
String message = builder.substring(0, builder.length() - 1);