vminecraft.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. //This is where the bulk of the plugin is
  2. import java.util.logging.Logger;
  3. import java.util.logging.Level;
  4. public class vminecraft extends Plugin {
  5. //settings Settings;
  6. @Override
  7. public void disable() {
  8. //throw new UnsupportedOperationException("Not supported yet.");
  9. //I have to include this to compile, not sure why.
  10. }
  11. @Override
  12. public void enable() {
  13. //throw new UnsupportedOperationException("Not supported yet.");
  14. //I have to include this to compile, not sure why.
  15. }
  16. static final Logger log = Logger.getLogger("Minecraft");
  17. @Override
  18. public void onLogin(Player player)
  19. {
  20. settings.getInstance().loadSettings();
  21. }
  22. public boolean onChat(Player player, String message){
  23. //Settings.loadSettings();
  24. settings.getInstance().loadSettings();
  25. String playerb = player.getName(); //Used to get names from players, can't remember why I can't just use 'player'
  26. String temp2 = "<" + player.getColor() + player.getName() + Colors.White +"> "; //Inserts a name before the message
  27. String adminchat = Colors.LightGreen + "{" + player.getColor() + player.getName() + Colors.LightGreen +"}" + Colors.White + " "; //Inserts names admin chat style before the message
  28. String message2 = ""; //Used for greentext and FFF
  29. String check = temp2+message; //Calculates how long your message will be including your name in the equation, this prevents minecraft clients from crashing when a color code is inserted after a linebreak
  30. if (settings.getInstance().adminchat()&&message.startsWith("@") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins"))) {
  31. for (Player p : etc.getServer().getPlayerList()) {
  32. if (p != null) {
  33. if (player.isInGroup("mods") || (player.isInGroup("admins")) || (player.isInGroup("superadmins"))) {
  34. String blaa = "";
  35. for ( int x = 1; x< message.length(); x++) {
  36. blaa+=message.charAt(x);
  37. }
  38. p.sendMessage(adminchat+blaa);
  39. log.log(Level.INFO, "@"+message);
  40. }
  41. }
  42. }
  43. return true;
  44. }
  45. //Greentext
  46. if (settings.getInstance().greentext()&&message.startsWith(">")) {
  47. id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
  48. message = Colors.LightGreen + message;
  49. message2 = temp2 + message;
  50. other.gmsg(message2);
  51. return true;
  52. }
  53. //FFF
  54. if (settings.getInstance().FFF()&&message.startsWith("FFF")) {
  55. id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
  56. message = Colors.Red + message;
  57. message2 = temp2 + message;
  58. other.gmsg(message2);
  59. return true;
  60. }
  61. //QuakeColors
  62. if(settings.getInstance().quakeColors()&&message.length()>2 && lengthCheck(check)) {
  63. String temp = "";
  64. for(int x = 0; x< message.length(); x++)
  65. {
  66. if(message.charAt(x)=='^'&&x!=message.length()-1)
  67. {
  68. temp+=colorChange(message.charAt(x+1));
  69. x+=1;
  70. }
  71. else{
  72. temp+=message.charAt(x);
  73. }
  74. }
  75. log.log(Level.INFO, "<"+player.getName()+"> "+message);
  76. message = temp2 + temp + " ";
  77. for (Player p : etc.getServer().getPlayerList()) {
  78. if (p != null) {
  79. other.gmsg(message);
  80. return true;
  81. }
  82. }
  83. }
  84. return false;
  85. }
  86. public boolean onCommand(Player player, String[] split) {
  87. if (player.canUseCommand(split[0])) {
  88. return false;
  89. }
  90. //Fabulous
  91. if (split[0].equalsIgnoreCase("/fabulous")&&settings.getInstance().cmdFabulous()) {
  92. etc.getInstance().addCommand("/fabulous", "/fabulous <message>");
  93. if (split.length == 1) {return false;}
  94. String temp = "";
  95. String str = "";
  96. //str = paramString.substring(paramString.indexOf(" ")).trim();
  97. str = etc.combineSplit(1, split, " ");
  98. String temp2 = "<" + player.getName() + "> "+str;
  99. String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple};
  100. int counter=0;
  101. if(lengthCheck(temp2))
  102. {
  103. id.a.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  104. for(int x=0; x<str.length(); x++)
  105. {
  106. temp+=rainbow[counter]+str.charAt(x);
  107. counter++;
  108. if(str.charAt(x)==' ') { counter--;}
  109. if(counter==-1){counter = 6; }
  110. if(counter==7){counter = 0; }
  111. }
  112. str = temp+" ";
  113. String message = "<" + player.getColor() + player.getName() + Colors.White + "> " + str;
  114. other.gmsg(message);
  115. } else {
  116. player.sendMessage(Colors.Rose + "Message is too long");
  117. }
  118. }
  119. //Promote
  120. else if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
  121. {
  122. if(split.length != 2)
  123. {
  124. player.sendMessage(Colors.Rose + "Usage is /promote [Player]");
  125. }
  126. Player playerTarget = null;
  127. for( Player p : etc.getServer().getPlayerList())
  128. {
  129. if (p.getName().equalsIgnoreCase(split[1]))
  130. {
  131. playerTarget = p;
  132. }
  133. }
  134. if( playerTarget!=null)
  135. {
  136. if(playerTarget.isInGroup("admins"))
  137. {
  138. player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher.");
  139. }
  140. if(playerTarget.isInGroup("mods") && (player.isInGroup("superadmins")))
  141. {
  142. playerTarget.setGroups(ranks.Admins);
  143. etc.getInstance().getDataSource().modifyPlayer(player);
  144. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin";
  145. other.gmsg(message);
  146. }
  147. else if (playerTarget.isInGroup("trusted") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  148. {
  149. playerTarget.setGroups(ranks.Mods);
  150. etc.getInstance().getDataSource().modifyPlayer(player);
  151. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod";
  152. other.gmsg(message);
  153. }
  154. else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  155. {
  156. player.setGroups(ranks.Trusted);
  157. etc.getInstance().getDataSource().modifyPlayer(player);
  158. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted";
  159. other.gmsg(message);
  160. }
  161. }
  162. else{
  163. player.sendMessage(Colors.Rose + "Player not found");
  164. }
  165. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  166. }
  167. //Demote
  168. else if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
  169. {
  170. if(split.length != 2)
  171. {
  172. player.sendMessage(Colors.Rose + "Usage is /demote [Player]");
  173. }
  174. Player playerTarget = null;
  175. for( Player p : etc.getServer().getPlayerList())
  176. {
  177. if (p.getName().equalsIgnoreCase(split[1]))
  178. {
  179. playerTarget = p;
  180. }
  181. }
  182. if( playerTarget!=null)
  183. {
  184. if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins")))
  185. {
  186. playerTarget.setGroups(ranks.Mods);
  187. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod";
  188. other.gmsg(message);
  189. }
  190. if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  191. {
  192. playerTarget.setGroups(ranks.Trusted);
  193. etc.getInstance().getDataSource().modifyPlayer(player);
  194. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted";
  195. other.gmsg(message);
  196. }
  197. else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins")))
  198. {
  199. playerTarget.setGroups(ranks.Def);
  200. etc.getInstance().getDataSource().modifyPlayer(player);
  201. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default";
  202. other.gmsg(message);
  203. }
  204. else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  205. {
  206. player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower.");
  207. }
  208. }
  209. else{
  210. player.sendMessage(Colors.Rose + "Player not found");
  211. }
  212. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  213. }
  214. //Whois will display info about a player
  215. else if (settings.getInstance().cmdWhoIs()&&split[0].equalsIgnoreCase("/whois")) {
  216. String admin ="";
  217. String group ="";
  218. String ignore ="";
  219. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  220. etc.getInstance().addCommand("/whois", "/whois [user]");
  221. if (split.length < 2) {
  222. player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  223. }
  224. if (player.canIgnoreRestrictions()) {
  225. ignore = "True";
  226. } else {
  227. ignore ="False";
  228. }
  229. if (player.canIgnoreRestrictions()) {
  230. admin = "True";
  231. } else {
  232. admin = "False";
  233. }
  234. if (player.isInGroup("superadmins")){
  235. group = "superadmins";
  236. }else if(player.isInGroup("admins")){
  237. group = "admins";
  238. }else if(player.isInGroup("mods")){
  239. group = "mods";
  240. }else if(player.isInGroup("trusted")){
  241. group = "trusted";
  242. }else{
  243. group = "Default";
  244. }
  245. player.sendMessage(Colors.LightGreen + "Info for "+split[1]+": Admin("+admin+") Ignoresrestrictions("+ignore+") Group("+group+").");
  246. } else {
  247. return false;
  248. }
  249. return true;
  250. }
  251. public void onKick(Player player, String reason)
  252. {
  253. }
  254. //Calculates how long the specified String is to prevent linebreaks when using scripts that insert color codes, designed to be used with playername included
  255. private boolean lengthCheck(String str)
  256. {
  257. int length = 0;
  258. for(int x = 0; x<str.length(); x++)
  259. {
  260. if("i;,.:|!".indexOf(str.charAt(x)) != -1)
  261. {
  262. length+=2;
  263. }
  264. else if("l'".indexOf(str.charAt(x)) != -1)
  265. {
  266. length+=3;
  267. }
  268. else if("tI[]".indexOf(str.charAt(x)) != -1)
  269. {
  270. length+=4;
  271. }
  272. else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
  273. {
  274. length+=5;
  275. }
  276. else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
  277. {
  278. length+=6;
  279. }
  280. else if("@~".indexOf(str.charAt(x)) != -1)
  281. {
  282. length+=7;
  283. }
  284. else if(str.charAt(x)==' ')
  285. {
  286. length+=4;
  287. }
  288. }
  289. if(length<=316)
  290. {
  291. return true;
  292. } else { return false; }
  293. }
  294. //QuakeColors Part 2
  295. private String colorChange(char colour)
  296. {
  297. String color = "";
  298. switch(colour)
  299. {
  300. case '0':
  301. color = Colors.Black;
  302. break;
  303. case '1':
  304. color = Colors.Navy;
  305. break;
  306. case '2':
  307. color = Colors.Green;
  308. break;
  309. case '3':
  310. color = Colors.Blue;
  311. break;
  312. case '4':
  313. color = Colors.Red;
  314. break;
  315. case '5':
  316. color = Colors.Purple;
  317. break;
  318. case '6':
  319. color = Colors.Gold;
  320. break;
  321. case '7':
  322. color = Colors.LightGray;
  323. break;
  324. case '8':
  325. color = Colors.Gray;
  326. break;
  327. case '9':
  328. color = Colors.DarkPurple;
  329. break;
  330. case 'a':
  331. color = Colors.LightGreen;
  332. break;
  333. case 'b':
  334. color = Colors.LightBlue;
  335. break;
  336. case 'c':
  337. color = Colors.Rose;
  338. break;
  339. case 'd':
  340. color = Colors.LightPurple;
  341. break;
  342. case 'e':
  343. color = Colors.Yellow;
  344. break;
  345. case 'f':
  346. color = Colors.White;
  347. break;
  348. case 'A':
  349. color = Colors.LightGreen;
  350. break;
  351. case 'B':
  352. color = Colors.LightBlue;
  353. break;
  354. case 'C':
  355. color = Colors.Rose;
  356. break;
  357. case 'D':
  358. color = Colors.LightPurple;
  359. break;
  360. case 'E':
  361. color = Colors.Yellow;
  362. break;
  363. case 'F':
  364. color = Colors.White;
  365. break;
  366. default:
  367. color = Colors.White;
  368. break;
  369. }
  370. return color;
  371. }
  372. }