^r color code for rainbow colors

This commit is contained in:
cerevisiae 2010-12-10 02:25:59 -06:00
parent 454cf22713
commit cb285b118c

View File

@ -10,6 +10,20 @@ import java.util.logging.Logger;
public class vMinecraftChat { public class vMinecraftChat {
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
protected static final int lineLength = 312; protected static final int lineLength = 312;
//The array of colors to use
protected static final String[] rainbow = new String[] {
Colors.Red,
Colors.Rose,
Colors.Gold,
Colors.Yellow,
Colors.LightGreen,
Colors.Green,
Colors.LightBlue,
Colors.Blue,
Colors.Navy,
Colors.DarkPurple,
Colors.Purple,
Colors.LightPurple};
//===================================================================== //=====================================================================
//Function: gmsg //Function: gmsg
@ -18,6 +32,9 @@ public class vMinecraftChat {
//Use: Outputs a message to everybody //Use: Outputs a message to everybody
//===================================================================== //=====================================================================
public static void gmsg(Player sender, String msg){ public static void gmsg(Player sender, String msg){
if(sender.isMuted())
sender.sendMessage(Colors.Red + "You have been muted.");
for (Player receiver : etc.getServer().getPlayerList()) { for (Player receiver : etc.getServer().getPlayerList()) {
if (receiver == null) {return;} if (receiver == null) {return;}
@ -41,6 +58,9 @@ public class vMinecraftChat {
//Use: Outputs a message to everybody //Use: Outputs a message to everybody
//===================================================================== //=====================================================================
public static void sendMessage(Player sender, Player receiver, String msg){ public static void sendMessage(Player sender, Player receiver, String msg){
if(sender.isMuted())
sender.sendMessage(Colors.Red + "You have been muted.");
//Check if the receiver has the sender ignored //Check if the receiver has the sender ignored
if(vMinecraftUsers.getProfile(receiver) == null) if(vMinecraftUsers.getProfile(receiver) == null)
return; return;
@ -116,11 +136,16 @@ public class vMinecraftChat {
//and their following color codes //and their following color codes
for(int x = 0; x<str.length(); x++) for(int x = 0; x<str.length(); x++)
{ {
int len = charLength(str.charAt(x)); if(str.charAt(x) == '^' || str.charAt(x) == Colors.White.charAt(0))
if( len > 0) {
length += len; if(colorChange(str.charAt(x + 1)) != null)
else {
x++; x++;
continue;
}
}
int len = charLength(str.charAt(x));
length += len;
} }
return length; return length;
} }
@ -189,10 +214,6 @@ public class vMinecraftChat {
//===================================================================== //=====================================================================
public static String rainbow(String msg){ public static String rainbow(String msg){
String temp = ""; String temp = "";
//The array of colors to use
String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Gold,
Colors.Yellow, Colors.LightGreen, Colors.Green, Colors.Blue,
Colors.Navy, Colors.DarkPurple, Colors.Purple, Colors.LightPurple};
int counter=0; int counter=0;
//Loop through the message applying the colors //Loop through the message applying the colors
for(int x=0; x<msg.length(); x++) for(int x=0; x<msg.length(); x++)
@ -465,6 +486,9 @@ public class vMinecraftChat {
//Go through each line //Go through each line
int counter = 0; int counter = 0;
int i = 0;
boolean taste = false;
for(String msg: message) for(String msg: message)
{ {
//Start the line with the most recent color //Start the line with the most recent color
@ -483,10 +507,47 @@ public class vMinecraftChat {
{ {
//Set the most recent color to the new color //Set the most recent color to the new color
recentColor = vMinecraftChat.colorChange(msg.charAt(x+1)); recentColor = vMinecraftChat.colorChange(msg.charAt(x+1));
//If the color specified is rainbow
if(recentColor.equals("~") || taste)
{
//Skip the quake code for rainbow
if(recentColor.equals("~"))
{
x += 2;
}
//Taste keeps it going with rainbow if there
//are more lines
taste = true;
//Loop through the message applying the colors
while(x < msg.length() && msg.charAt(x) != '^'
&& msg.charAt(x) != Colors.Red.charAt(0))
{
temp += rainbow[i] + msg.charAt(x);
if(msg.charAt(x) != ' ') i++;
if(i == rainbow.length) i = 0;
x++;
}
//If it reached another color instead of the end
if(x < msg.length() && msg.charAt(x) == '^'
|| msg.charAt(x) == Colors.Red.charAt(0) )
{
taste = false;
i = 0;
x--;
}
}
else
{
//Add the color //Add the color
temp += recentColor; temp += recentColor;
//Skip these chars //Skip these chars
x++; x++;
}
//Otherwise ignore it. //Otherwise ignore it.
} else { } else {
temp += msg.charAt(x); temp += msg.charAt(x);
@ -506,69 +567,4 @@ public class vMinecraftChat {
} }
return message; return message;
} }
//=====================================================================
//Function: applyColors
//Input: String message: The line to be colored
//Output: String: The line, but colorful
//Use: Colors a line
//=====================================================================
public static String applyColors(String message)
{
return applyColors(message, Colors.White);
}
//=====================================================================
//Function: applyColors
//Input: String message: The line to be colored
// String color: The color to start the line with
//Output: String: The line, but colorful
//Use: Colors a line
//=====================================================================
public static String applyColors(String message, String color)
{
if(message != null && !message.isEmpty())
{
//The color to start the line with
if(color == null)
color = Colors.White;
//Start the line with the most recent color
String temp = color;
//Loop through looking for a color code
for(int x = 0; x< message.length(); x++)
{
//If the char is a ^ or '<27>'
if(message.charAt(x) == '^' || message.charAt(x) == Colors.White.charAt(0))
{
if(x != message.length() - 1)
{
//If the following character is a color code
if(vMinecraftChat.colorChange(message.charAt(x+1)) != null)
{
//Set the most recent color to the new color
color = vMinecraftChat.colorChange(message.charAt(x+1));
//Add the color
temp += color;
//Skip these chars
x++;
//Otherwise ignore it.
} else {
temp += message.charAt(x);
}
//Insert the character
} else {
temp += message.charAt(x);
}
//Insert the character
} else {
temp += message.charAt(x);
}
}
message = temp;
}
return message;
}
} }