import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; //===================================================================== //Class: vMinecraftChat //Use: Encapsulates all chat commands added by this mod //Author: nossr50, TrapAlice, cerevisiae //===================================================================== public class vminecraftChat { protected static final Logger log = Logger.getLogger("Minecraft"); //===================================================================== //Function: gmsg //Input: String msg: The message to be broadcast to all players //Output: None //Use: Outputs a message to everybody //===================================================================== public static void gmsg(String msg){ for (Player p : etc.getServer().getPlayerList()) { if (p != null) { p.sendMessage(msg); } } } //===================================================================== //Function: wordWrap //Input: String msg: The message to be wrapped //Output: String[]: The array of substrings //Use: Cuts the message apart into whole words short enough to fit // on one line //===================================================================== public static String[] wordWrap(String msg){ //Split each word apart String[] split = msg.split(" "); //Create an arraylist for the output ArrayList out = new ArrayList(); //While i is less than the length of the array of words int i = 0; while(i < split.length){ int len = 0; int j = i; //Loop through the words finding their length and increasing //j, the end point for the sub string while(len <= 316 && i < split.length) { len += msgLength(split[i]) + 4; if( len <= 316) i++; } //Copy the words in the selection into a new array String[] temp = new String[i - j]; System.arraycopy(split, j, temp, 0, i - j); //Merge them and add them to the output array out.add( etc.combineSplit(0, temp, " ") ); } //Convert to an array and return String[] tempout = new String[out.size()]; out.toArray(tempout); return tempout; } private static int msgLength(String str){ int length = 0; for(int x = 0; x\"*()".indexOf(str.charAt(x)) != -1) { length+=5; } else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) { length+=6; } else if("@~".indexOf(str.charAt(x)) != -1) { length+=7; } else if(str.charAt(x)==' ') { length+=4; } } return length; } public static String rainbow(String msg){ String temp = ""; //The array of colors to use String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple}; int counter=0; //Loop through the message applying the colors for(int x=0; x " + message); return true; } return false; } //===================================================================== //Function: quote //Input: Player player: The player talking // String message: The message to apply the effect to //Output: boolean: If this feature is enabled //Use: Displays a message as a quote //===================================================================== public static boolean quote(Player player, String message) { //Format the name String playerName = Colors.White + "<" + nameColor(player) + Colors.White + "> "; if(vminecraftSettings.getInstance().greentext()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> " +message); //Get the multi line array String[] msg = wordWrap(playerName + Colors.LightGreen + message); //Output the lines for(String str: msg) gmsg(Colors.LightGreen + str); return true; } return false; } //===================================================================== //Function: rage //Input: Player player: The player talking // String message: The message to apply the effect to //Output: boolean: If this feature is enabled //Use: Displays a message in red //===================================================================== public static boolean rage(Player player, String message) { //Format the name String playerName = Colors.White + "<" + nameColor(player) + Colors.White +"> "; if (vminecraftSettings.getInstance().FFF()) { log.log(Level.INFO, "<"+player.getName()+"> "+message); //Get the multi line array String[] msg = wordWrap(playerName + Colors.Red + message); //Output the message for(String str: msg) gmsg(Colors.Red + str); return true; } return false; } //===================================================================== //Function: quakeColors //Input: Player player: The player talking // String message: The message to apply the effect to //Output: boolean: If this feature is enabled //Use: Displays a message in red //===================================================================== public static boolean quakeColors(Player player, String message) { //Format the name String playerName = Colors.White + "<" + nameColor(player) + Colors.White +"> "; if(vminecraftSettings.getInstance().quakeColors() && message.length()>2) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); //Get the multi line array String[] msg = wordWrap(playerName + message); //Apply colors to the lines applyColors(msg); //Output the message for(String str: msg) gmsg(str); //Loop through the string finding the color codes and inserting them return true; } return false; } //===================================================================== //Function: applyColors //Input: String[] message: The lines to be colored //Output: String[]: The lines, but colorful //Use: Colors each line //===================================================================== private static String[] applyColors(String[] message) { //The color to start the line with String recentColor = Colors.White; //Go through each line int counter = 0; for(String msg: message) { //Start the line with the most recent color String temp = recentColor; //Loop through looking for a color code for(int x = 0; x< msg.length(); x++) { if(msg.charAt(x)=='^' && x != msg.length() - 1) { //Set the most recent color to the new color recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); temp += recentColor; x++; } else{ temp += msg.charAt(x); } } //Replace the message with the colorful message message[counter] = temp; counter++; } return message; } }