vminecraftChat.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import java.util.logging.Level;
  2. import java.util.logging.Logger;
  3. //=====================================================================
  4. //Class: vMinecraftChat
  5. //Use: Encapsulates all chat commands added by this mod
  6. //Author: nossr50, TrapAlice, cerevisiae
  7. //=====================================================================
  8. public class vminecraftChat {
  9. protected static final Logger log = Logger.getLogger("Minecraft");
  10. //=====================================================================
  11. //Function: gmsg
  12. //Input: String msg: The message to be broadcast to all players
  13. //Output: None
  14. //Use: Outputs a message to everybody
  15. //=====================================================================
  16. public static void gmsg(String msg){
  17. for (Player p : etc.getServer().getPlayerList()) {
  18. if (p != null) {
  19. p.sendMessage(msg);
  20. }
  21. }
  22. }
  23. //=====================================================================
  24. //Function: nameColor
  25. //Input: Player player: The player to get name as color
  26. //Output: String: The name colored
  27. //Use: Returns the colored name;
  28. //=====================================================================
  29. public static String nameColor(Player player){
  30. return player.getColor() + player.getName();
  31. }
  32. //=====================================================================
  33. //Function: colorChange
  34. //Input: char colour: The color code to find the color for
  35. //Output: String: The color that the code identified
  36. //Use: Finds a color giving a color code
  37. //=====================================================================
  38. public static String colorChange(char colour)
  39. {
  40. String color = "";
  41. switch(colour)
  42. {
  43. case '0':
  44. color = Colors.Black;
  45. break;
  46. case '1':
  47. color = Colors.Navy;
  48. break;
  49. case '2':
  50. color = Colors.Green;
  51. break;
  52. case '3':
  53. color = Colors.Blue;
  54. break;
  55. case '4':
  56. color = Colors.Red;
  57. break;
  58. case '5':
  59. color = Colors.Purple;
  60. break;
  61. case '6':
  62. color = Colors.Gold;
  63. break;
  64. case '7':
  65. color = Colors.LightGray;
  66. break;
  67. case '8':
  68. color = Colors.Gray;
  69. break;
  70. case '9':
  71. color = Colors.DarkPurple;
  72. break;
  73. case 'a':
  74. color = Colors.LightGreen;
  75. break;
  76. case 'b':
  77. color = Colors.LightBlue;
  78. break;
  79. case 'c':
  80. color = Colors.Rose;
  81. break;
  82. case 'd':
  83. color = Colors.LightPurple;
  84. break;
  85. case 'e':
  86. color = Colors.Yellow;
  87. break;
  88. case 'f':
  89. color = Colors.White;
  90. break;
  91. case 'A':
  92. color = Colors.LightGreen;
  93. break;
  94. case 'B':
  95. color = Colors.LightBlue;
  96. break;
  97. case 'C':
  98. color = Colors.Rose;
  99. break;
  100. case 'D':
  101. color = Colors.LightPurple;
  102. break;
  103. case 'E':
  104. color = Colors.Yellow;
  105. break;
  106. case 'F':
  107. color = Colors.White;
  108. break;
  109. default:
  110. color = Colors.White;
  111. break;
  112. }
  113. return color;
  114. }
  115. //=====================================================================
  116. //Function: lengthCheck
  117. //Input: String str: The message to make sure isn't too long
  118. //Output: boolean: If the message is too long
  119. //Use: Check if a message is too long
  120. //=====================================================================
  121. public static boolean lengthCheck(String str)
  122. {
  123. int length = 0;
  124. for(int x = 0; x<str.length(); x++)
  125. {
  126. if("i;,.:|!".indexOf(str.charAt(x)) != -1)
  127. {
  128. length+=2;
  129. }
  130. else if("l'".indexOf(str.charAt(x)) != -1)
  131. {
  132. length+=3;
  133. }
  134. else if("tI[]".indexOf(str.charAt(x)) != -1)
  135. {
  136. length+=4;
  137. }
  138. else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
  139. {
  140. length+=5;
  141. }
  142. else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
  143. {
  144. length+=6;
  145. }
  146. else if("@~".indexOf(str.charAt(x)) != -1)
  147. {
  148. length+=7;
  149. }
  150. else if(str.charAt(x)==' ')
  151. {
  152. length+=4;
  153. }
  154. }
  155. if(length<=316)
  156. {
  157. return true;
  158. } else { return false; }
  159. }
  160. //=====================================================================
  161. //Function: adminChat
  162. //Input: Player player: The player talking
  163. // String message: The message to apply the effect to
  164. //Output: boolean: If this feature is enabled
  165. //Use: Sends messages only to admins
  166. //=====================================================================
  167. public static boolean adminChat(Player player, String message){
  168. //Check if the player can use this feature
  169. if(player.isAdmin() || player.canUseCommand("/adminchat"))
  170. {
  171. //Special formatting for adminchat {Username}
  172. String adminchat = Colors.DarkPurple + "{" + player.getColor()
  173. + player.getName() + Colors.DarkPurple +"}" + Colors.White + " ";
  174. //Get the player from the playerlist to send the message to.
  175. for (Player p: etc.getServer().getPlayerList()) {
  176. //If p is not null
  177. if (p != null) {
  178. //And if p is an admin or has access to adminchat
  179. if (p.isAdmin() || (p.canUseCommand("/adminchat"))) {
  180. //Send them the message
  181. p.sendMessage(adminchat
  182. + message.substring(1, message.length()));
  183. }
  184. }
  185. }
  186. //So you can read adminchat from the server console
  187. log.log(Level.INFO, "@" + "<" + nameColor(player)
  188. + Colors.White +"> " + message);
  189. return true;
  190. }
  191. return false;
  192. }
  193. //=====================================================================
  194. //Function: quote
  195. //Input: Player player: The player talking
  196. // String message: The message to apply the effect to
  197. //Output: boolean: If this feature is enabled
  198. //Use: Displays a message as a quote
  199. //=====================================================================
  200. public static boolean quote(Player player, String message)
  201. {
  202. //Format the name
  203. String playerName = "<" + nameColor(player) + Colors.White +"> ";
  204. if(vminecraftSettings.getInstance().greentext()) {
  205. //Log the chat
  206. log.log(Level.INFO, "<"+player.getName()+"> "+message);
  207. //Output the message
  208. gmsg(playerName + Colors.LightGreen + message);
  209. }
  210. return false;
  211. }
  212. //=====================================================================
  213. //Function: rage
  214. //Input: Player player: The player talking
  215. // String message: The message to apply the effect to
  216. //Output: boolean: If this feature is enabled
  217. //Use: Displays a message in red
  218. //=====================================================================
  219. public static boolean rage(Player player, String message)
  220. {
  221. //Format the name
  222. String playerName = "<" + nameColor(player) + Colors.White +"> ";
  223. if (vminecraftSettings.getInstance().FFF()) {
  224. log.log(Level.INFO, "<"+player.getName()+"> "+message);
  225. gmsg(playerName + Colors.Red + message);
  226. return true;
  227. }
  228. return false;
  229. }
  230. //=====================================================================
  231. //Function: quakeColors
  232. //Input: Player player: The player talking
  233. // String message: The message to apply the effect to
  234. //Output: boolean: If this feature is enabled
  235. //Use: Displays a message in red
  236. //=====================================================================
  237. public static boolean quakeColors(Player player, String message)
  238. {
  239. //Format the name
  240. String playerName = "<" + nameColor(player) + Colors.White +"> ";
  241. if(vminecraftSettings.getInstance().quakeColors()&&message.length()>2 && vminecraftChat.lengthCheck(playerName + message)) {
  242. //Loop through the string finding the color codes and inserting them
  243. String temp = "";
  244. for(int x = 0; x< message.length(); x++)
  245. {
  246. if(message.charAt(x)=='^' && x != message.length() - 1)
  247. {
  248. temp += vminecraftChat.colorChange(message.charAt(x+1));
  249. x++;
  250. }
  251. else{
  252. temp+=message.charAt(x);
  253. }
  254. }
  255. //Log the chat
  256. log.log(Level.INFO, "<"+player.getName()+"> "+message);
  257. //Broadcast the message
  258. gmsg(playerName + temp + " ");
  259. return true;
  260. }
  261. return false;
  262. }
  263. }