Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify colors and toggle prefix in alert command #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/net/md_5/bungee/ChatColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,17 @@ public static String stripColor(final String input)

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)
{
b[i] = ChatColor.COLOR_CHAR;
b[i+1] = Character.toLowerCase(b[i+1]);
}
}
return new String(b);
}
}
15 changes: 12 additions & 3 deletions src/main/java/net/md_5/bungee/command/CommandAlert.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ public void execute(CommandSender sender, String[] args)
}
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);
Expand Down