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: nameColor //Input: Player player: The player to get name as color //Output: String: The name colored //Use: Returns the colored name; //===================================================================== public static String nameColor(Player player){ return player.getColor() + player.getName(); } //===================================================================== //Function: colorChange //Input: char colour: The color code to find the color for //Output: String: The color that the code identified //Use: Finds a color giving a color code //===================================================================== public static String colorChange(char colour) { String color = ""; switch(colour) { case '0': color = Colors.Black; break; case '1': color = Colors.Navy; break; case '2': color = Colors.Green; break; case '3': color = Colors.Blue; break; case '4': color = Colors.Red; break; case '5': color = Colors.Purple; break; case '6': color = Colors.Gold; break; case '7': color = Colors.LightGray; break; case '8': color = Colors.Gray; break; case '9': color = Colors.DarkPurple; break; case 'a': color = Colors.LightGreen; break; case 'b': color = Colors.LightBlue; break; case 'c': color = Colors.Rose; break; case 'd': color = Colors.LightPurple; break; case 'e': color = Colors.Yellow; break; case 'f': color = Colors.White; break; case 'A': color = Colors.LightGreen; break; case 'B': color = Colors.LightBlue; break; case 'C': color = Colors.Rose; break; case 'D': color = Colors.LightPurple; break; case 'E': color = Colors.Yellow; break; case 'F': color = Colors.White; break; default: color = Colors.White; break; } return color; } //===================================================================== //Function: lengthCheck //Input: String str: The message to make sure isn't too long //Output: boolean: If the message is too long //Use: Check if a message is too long //===================================================================== public static boolean lengthCheck(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; } } if(length<=316) { return true; } else { return false; } } //===================================================================== //Function: adminChat //Input: Player player: The player talking // String message: The message to apply the effect to //Output: boolean: If this feature is enabled //Use: Sends messages only to admins //===================================================================== public static boolean adminChat(Player player, String message){ //Check if the player can use this feature if(player.isAdmin() || player.canUseCommand("/adminchat")) { //Special formatting for adminchat {Username} String adminchat = Colors.DarkPurple + "{" + player.getColor() + player.getName() + Colors.DarkPurple +"}" + Colors.White + " "; //Get the player from the playerlist to send the message to. for (Player p: etc.getServer().getPlayerList()) { //If p is not null if (p != null) { //And if p is an admin or has access to adminchat if (p.isAdmin() || (p.canUseCommand("/adminchat"))) { //Send them the message p.sendMessage(adminchat + message.substring(1, message.length())); } } } //So you can read adminchat from the server console log.log(Level.INFO, "@" + "<" + nameColor(player) + Colors.White +"> " + 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 = "<" + nameColor(player) + Colors.White +"> "; if(vminecraftSettings.getInstance().greentext()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); //Output the message gmsg(playerName + Colors.LightGreen + message); } 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 = "<" + nameColor(player) + Colors.White +"> "; if (vminecraftSettings.getInstance().FFF()) { log.log(Level.INFO, "<"+player.getName()+"> "+message); gmsg(playerName + Colors.Red + message); 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 = "<" + nameColor(player) + Colors.White +"> "; if(vminecraftSettings.getInstance().quakeColors()&&message.length()>2 && vminecraftChat.lengthCheck(playerName + message)) { //Loop through the string finding the color codes and inserting them String temp = ""; for(int x = 0; x< message.length(); x++) { if(message.charAt(x)=='^' && x != message.length() - 1) { temp += vminecraftChat.colorChange(message.charAt(x+1)); x++; } else{ temp+=message.charAt(x); } } //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); //Broadcast the message gmsg(playerName + temp + " "); return true; } return false; } }