vminecraft.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. //This is where the bulk of the plugin is
  2. import java.util.Locale;
  3. import java.util.logging.Logger;
  4. import java.util.logging.Level;
  5. public class vminecraft extends Plugin {
  6. @Override
  7. public void disable() {
  8. //I have to include this to compile, not sure why.
  9. }
  10. @Override
  11. public void enable() {
  12. //I have to include this to compile, not sure why.
  13. }
  14. static final Logger log = Logger.getLogger("Minecraft");
  15. @Override
  16. public void onLogin(Player player)
  17. {
  18. settings.getInstance().rules();
  19. settings.getInstance().loadSettings();
  20. }
  21. private String rules[];
  22. public boolean onChat(Player player, String message){
  23. settings.getInstance().rules();
  24. settings.getInstance().loadSettings(); //So you can disable/enable things in the txt files without having to reload the server
  25. String temp2 = "<" + player.getColor() + player.getName() + Colors.White +"> "; //Copies the formatting of id.java
  26. String adminchat = Colors.DarkPurple + "{" + player.getColor() + player.getName() + Colors.DarkPurple +"}" + Colors.White + " "; //Special formatting for adminchat
  27. String message2 = ""; //Used for greentext and FFF
  28. 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
  29. if (settings.getInstance().adminchat()&&message.startsWith("@") && (player.isAdmin())) {
  30. for (Player p : etc.getServer().getPlayerList()) {
  31. String blaa = "";
  32. if (p != null) {
  33. if (player.isAdmin()) {
  34. for ( int x = 1; x< message.length(); x++) {
  35. blaa+=message.charAt(x);
  36. }
  37. if (p.isAdmin()){
  38. if (p != null) {
  39. p.sendMessage(adminchat+blaa);
  40. }
  41. }
  42. }
  43. }
  44. }
  45. log.log(Level.INFO, "@"+temp2+message); //So you can read adminchat from the server console
  46. return true;
  47. }
  48. //Greentext
  49. if (settings.getInstance().greentext()&&message.startsWith(">")) {
  50. id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
  51. message = Colors.LightGreen + message;
  52. message2 = temp2 + message;
  53. other.gmsg(message2);
  54. return true;
  55. }
  56. //FFF
  57. if (settings.getInstance().FFF()&&message.startsWith("FFF")) {
  58. id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
  59. message = Colors.Red + message;
  60. message2 = temp2 + message;
  61. other.gmsg(message2);
  62. return true;
  63. }
  64. //QuakeColors
  65. if(settings.getInstance().quakeColors()&&message.length()>2 && lengthCheck(check)) {
  66. String temp = "";
  67. for(int x = 0; x< message.length(); x++)
  68. {
  69. if(message.charAt(x)=='^'&&x!=message.length()-1)
  70. {
  71. temp+=colorChange(message.charAt(x+1));
  72. x+=1;
  73. }
  74. else{
  75. temp+=message.charAt(x);
  76. }
  77. }
  78. log.log(Level.INFO, "<"+player.getName()+"> "+message);
  79. message = temp2 + temp + " ";
  80. for (Player p : etc.getServer().getPlayerList()) {
  81. if (p != null) {
  82. other.gmsg(message);
  83. return true;
  84. }
  85. }
  86. }
  87. return false;
  88. }
  89. public boolean onCommand(Player player, String[] split) {
  90. if(!player.canUseCommand(split[0])) {
  91. return false;
  92. }
  93. //Replacement for /tp
  94. if(settings.getInstance().cmdTp() && split[0].equalsIgnoreCase("/tp")) {
  95. {
  96. if (split.length < 2) {
  97. player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]");
  98. return true;
  99. }
  100. Player playerTarget = etc.getServer().matchPlayer(split[1]);
  101. if (player.getName().equalsIgnoreCase(split[1])) {
  102. player.sendMessage(Colors.Rose + "You're already here!");
  103. return true;
  104. }
  105. if (!player.hasControlOver(playerTarget)) {
  106. player.sendMessage(Colors.Red + "That player has higher permissions than you.");
  107. return true;
  108. }
  109. if (playerTarget != null) {
  110. log.log(Level.INFO, player.getName() + " teleported to " + playerTarget.getName());
  111. player.teleportTo(playerTarget);
  112. return true;
  113. } else {
  114. player.sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
  115. return true;
  116. }
  117. }
  118. }
  119. //Replacement for /tphere
  120. if (settings.getInstance().cmdTphere() && (split[0].equalsIgnoreCase("/tphere") || split[0].equalsIgnoreCase("/s"))) {
  121. if (split.length < 2) {
  122. player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]");
  123. return true;
  124. }
  125. Player playerTarget = etc.getServer().matchPlayer(split[1]);
  126. if (!player.hasControlOver(playerTarget)) {
  127. player.sendMessage(Colors.Red + "That player has higher permissions than you.");
  128. return true;
  129. }
  130. if (player.getName().equalsIgnoreCase(split[1])) {
  131. player.sendMessage(Colors.Rose + "Wow look at that! You teleported yourself to yourself!");
  132. return true;
  133. }
  134. if (playerTarget != null) {
  135. log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self.");
  136. playerTarget.teleportTo(player);
  137. } else {
  138. player.sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
  139. }
  140. }
  141. //Global messages that should only parse when a command can be successful
  142. if(settings.getInstance().globalmessages() && split[0].equalsIgnoreCase("/kick")) {
  143. Player playerTarget = etc.getServer().matchPlayer(split[1]);
  144. if (playerTarget != null && !playerTarget.hasControlOver(player)) {
  145. other.gmsg(player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName());
  146. }
  147. }
  148. if(settings.getInstance().globalmessages() && split[0].equalsIgnoreCase("/ban")) {
  149. Player playerTarget = etc.getServer().matchPlayer(split[1]);
  150. if (playerTarget != null && !playerTarget.hasControlOver(player)) {
  151. other.gmsg(player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName());
  152. }
  153. }
  154. if(settings.getInstance().globalmessages() && split[0].equalsIgnoreCase("/ipban")) {
  155. Player playerTarget = etc.getServer().matchPlayer(split[1]);
  156. if (playerTarget != null && !playerTarget.hasControlOver(player)) {
  157. other.gmsg(player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName());
  158. }
  159. }
  160. if(settings.getInstance().globalmessages() && split[0].equalsIgnoreCase("/time")) {
  161. if (split.length <= 2) {
  162. other.gmsg(Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName());
  163. return false;
  164. }
  165. }
  166. //Rules
  167. if(settings.getInstance().cmdRules() && split[0].equalsIgnoreCase("/rules")) {
  168. etc.getInstance().addCommand("/rules", "Displays the rules");
  169. for (String str : settings.getInstance().getRules()) {
  170. player.sendMessage(Colors.Blue+str);
  171. }
  172. return true;
  173. }
  174. //Fabulous
  175. if(split[0].equalsIgnoreCase("/fabulous") && settings.getInstance().cmdFabulous()) {
  176. etc.getInstance().addCommand("/fabulous", "makes text SUUUPER");
  177. if (split.length == 1) {return false;}
  178. String temp = "";
  179. String str = "";
  180. str = etc.combineSplit(1, split, " ");
  181. String temp2 = "<" + player.getName() + "> "+str;
  182. String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple};
  183. int counter=0;
  184. if(lengthCheck(temp2))
  185. {
  186. id.a.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  187. for(int x=0; x<str.length(); x++)
  188. {
  189. temp+=rainbow[counter]+str.charAt(x);
  190. counter++;
  191. if(str.charAt(x)==' ') { counter--;}
  192. if(counter==-1){counter = 6; }
  193. if(counter==7){counter = 0; }
  194. }
  195. str = temp+" ";
  196. String message = "<" + player.getColor() + player.getName() + Colors.White + "> " + str;
  197. other.gmsg(message);
  198. } else {
  199. player.sendMessage(Colors.Rose + "Message is too long");
  200. }
  201. return true;
  202. }
  203. //Promote
  204. if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) {
  205. if(split.length != 2)
  206. {
  207. player.sendMessage(Colors.Rose + "Usage is /promote [Player]");
  208. }
  209. Player playerTarget = null;
  210. for( Player p : etc.getServer().getPlayerList())
  211. {
  212. if (p.getName().equalsIgnoreCase(split[1]))
  213. {
  214. playerTarget = p;
  215. }
  216. }
  217. if( playerTarget!=null)
  218. {
  219. if(playerTarget.isInGroup("admins"))
  220. {
  221. player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher.");
  222. }
  223. if(playerTarget.isInGroup("mods") && (player.isInGroup("superadmins")))
  224. {
  225. playerTarget.setGroups(ranks.Admins);
  226. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  227. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin";
  228. other.gmsg(message);
  229. }
  230. else if (playerTarget.isInGroup("trusted") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  231. {
  232. playerTarget.setGroups(ranks.Mods);
  233. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  234. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod";
  235. other.gmsg(message);
  236. }
  237. else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  238. {
  239. playerTarget.setGroups(ranks.Trusted);
  240. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  241. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted";
  242. other.gmsg(message);
  243. }
  244. return true;
  245. }
  246. else{
  247. player.sendMessage(Colors.Rose + "Player not found");
  248. }
  249. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  250. }
  251. //Demote
  252. if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
  253. {
  254. if(split.length != 2)
  255. {
  256. player.sendMessage(Colors.Rose + "Usage is /demote [Player]");
  257. }
  258. Player playerTarget = null;
  259. for( Player p : etc.getServer().getPlayerList())
  260. {
  261. if (p.getName().equalsIgnoreCase(split[1]))
  262. {
  263. playerTarget = p;
  264. }
  265. }
  266. if( playerTarget!=null)
  267. {
  268. if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins")))
  269. {
  270. playerTarget.setGroups(ranks.Mods);
  271. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  272. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod";
  273. other.gmsg(message);
  274. }
  275. if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  276. {
  277. playerTarget.setGroups(ranks.Trusted);
  278. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  279. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted";
  280. other.gmsg(message);
  281. }
  282. else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins")))
  283. {
  284. playerTarget.setGroups(ranks.Def);
  285. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  286. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default";
  287. other.gmsg(message);
  288. }
  289. else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  290. {
  291. player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower.");
  292. }
  293. }
  294. else{
  295. player.sendMessage(Colors.Rose + "Player not found");
  296. }
  297. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  298. return true;
  299. }
  300. //Whois will display info about a player
  301. if (settings.getInstance().cmdWhoIs() && split[0].equalsIgnoreCase("/whois")) {
  302. etc.getInstance().addCommand("/whois", "/whois [user]");
  303. if (split.length < 2) {
  304. player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  305. }
  306. String admin ="";
  307. String ignore ="";
  308. String IP = "";
  309. Player playerTarget = null;
  310. for( Player p : etc.getServer().getPlayerList())
  311. {
  312. if (p.getName().equalsIgnoreCase(split[1]))
  313. {
  314. playerTarget = p;
  315. }
  316. }
  317. if (playerTarget != null){
  318. IP = playerTarget.getIP();
  319. if (playerTarget.canIgnoreRestrictions()) {
  320. ignore = "True";
  321. } else {
  322. ignore ="False";
  323. }
  324. if (playerTarget.canIgnoreRestrictions()) {
  325. admin = "True";
  326. } else {
  327. admin = "False";
  328. }
  329. //Displaying the information
  330. player.sendMessage(Colors.Blue + "Whois results for "+split[1]+".");
  331. //Group
  332. for (String group : playerTarget.getGroups()) {
  333. player.sendMessage(Colors.Blue + "Groups: "+group);
  334. }
  335. //Admin
  336. player.sendMessage(Colors.Blue+"Admin: "+admin);
  337. //IP
  338. player.sendMessage(Colors.Blue+"IP: "+IP);
  339. //Restrictions
  340. player.sendMessage(Colors.Blue+"Can ignore restrictions: "+ignore);
  341. } else {
  342. player.sendMessage(Colors.Rose+"Player not found.");
  343. }
  344. return true;
  345. }
  346. //Say
  347. if (settings.getInstance().cmdSay() && (split[0].equalsIgnoreCase("/say"))) {
  348. String sayan;
  349. sayan = etc.combineSplit(1, split, " ");
  350. other.gmsg(Colors.Yellow+sayan);
  351. }
  352. //Should this be included?
  353. else {
  354. return false;
  355. }
  356. //Needs to be included
  357. return true;
  358. }
  359. //Calculates how long the specified String is to prevent linebreaks when using scripts that insert color codes, designed to be used with playername included
  360. private boolean lengthCheck(String str)
  361. {
  362. int length = 0;
  363. for(int x = 0; x<str.length(); x++)
  364. {
  365. if("i;,.:|!".indexOf(str.charAt(x)) != -1)
  366. {
  367. length+=2;
  368. }
  369. else if("l'".indexOf(str.charAt(x)) != -1)
  370. {
  371. length+=3;
  372. }
  373. else if("tI[]".indexOf(str.charAt(x)) != -1)
  374. {
  375. length+=4;
  376. }
  377. else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
  378. {
  379. length+=5;
  380. }
  381. else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
  382. {
  383. length+=6;
  384. }
  385. else if("@~".indexOf(str.charAt(x)) != -1)
  386. {
  387. length+=7;
  388. }
  389. else if(str.charAt(x)==' ')
  390. {
  391. length+=4;
  392. }
  393. }
  394. if(length<=316)
  395. {
  396. return true;
  397. } else { return false; }
  398. }
  399. //QuakeColors Part 2
  400. private String colorChange(char colour)
  401. {
  402. String color = "";
  403. switch(colour)
  404. {
  405. case '0':
  406. color = Colors.Black;
  407. break;
  408. case '1':
  409. color = Colors.Navy;
  410. break;
  411. case '2':
  412. color = Colors.Green;
  413. break;
  414. case '3':
  415. color = Colors.Blue;
  416. break;
  417. case '4':
  418. color = Colors.Red;
  419. break;
  420. case '5':
  421. color = Colors.Purple;
  422. break;
  423. case '6':
  424. color = Colors.Gold;
  425. break;
  426. case '7':
  427. color = Colors.LightGray;
  428. break;
  429. case '8':
  430. color = Colors.Gray;
  431. break;
  432. case '9':
  433. color = Colors.DarkPurple;
  434. break;
  435. case 'a':
  436. color = Colors.LightGreen;
  437. break;
  438. case 'b':
  439. color = Colors.LightBlue;
  440. break;
  441. case 'c':
  442. color = Colors.Rose;
  443. break;
  444. case 'd':
  445. color = Colors.LightPurple;
  446. break;
  447. case 'e':
  448. color = Colors.Yellow;
  449. break;
  450. case 'f':
  451. color = Colors.White;
  452. break;
  453. case 'A':
  454. color = Colors.LightGreen;
  455. break;
  456. case 'B':
  457. color = Colors.LightBlue;
  458. break;
  459. case 'C':
  460. color = Colors.Rose;
  461. break;
  462. case 'D':
  463. color = Colors.LightPurple;
  464. break;
  465. case 'E':
  466. color = Colors.Yellow;
  467. break;
  468. case 'F':
  469. color = Colors.White;
  470. break;
  471. default:
  472. color = Colors.White;
  473. break;
  474. }
  475. return color;
  476. }
  477. }