vminecraft.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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(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 ((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(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(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(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(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(split[0].equalsIgnoreCase("/rules")) {
  168. for (String str : settings.getInstance().getRules()) {
  169. player.sendMessage(Colors.Blue+str);
  170. }
  171. return true;
  172. }
  173. //Fabulous
  174. if(split[0].equalsIgnoreCase("/fabulous") && settings.getInstance().cmdFabulous()) {
  175. if (split.length == 1) {return false;}
  176. String temp = "";
  177. String str = "";
  178. str = etc.combineSplit(1, split, " ");
  179. String temp2 = "<" + player.getName() + "> "+str;
  180. String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple};
  181. int counter=0;
  182. if(lengthCheck(temp2))
  183. {
  184. id.a.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  185. for(int x=0; x<str.length(); x++)
  186. {
  187. temp+=rainbow[counter]+str.charAt(x);
  188. counter++;
  189. if(str.charAt(x)==' ') { counter--;}
  190. if(counter==-1){counter = 6; }
  191. if(counter==7){counter = 0; }
  192. }
  193. str = temp+" ";
  194. String message = "<" + player.getColor() + player.getName() + Colors.White + "> " + str;
  195. other.gmsg(message);
  196. } else {
  197. player.sendMessage(Colors.Rose + "Message is too long");
  198. }
  199. return true;
  200. }
  201. //Promote
  202. if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) {
  203. if(split.length != 2)
  204. {
  205. player.sendMessage(Colors.Rose + "Usage is /promote [Player]");
  206. }
  207. Player playerTarget = null;
  208. for( Player p : etc.getServer().getPlayerList())
  209. {
  210. if (p.getName().equalsIgnoreCase(split[1]))
  211. {
  212. playerTarget = p;
  213. }
  214. }
  215. if( playerTarget!=null)
  216. {
  217. if(playerTarget.isInGroup("admins"))
  218. {
  219. player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher.");
  220. }
  221. if(playerTarget.isInGroup("mods") && (player.isInGroup("superadmins")))
  222. {
  223. playerTarget.setGroups(ranks.Admins);
  224. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  225. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin";
  226. other.gmsg(message);
  227. }
  228. else if (playerTarget.isInGroup("trusted") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  229. {
  230. playerTarget.setGroups(ranks.Mods);
  231. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  232. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod";
  233. other.gmsg(message);
  234. }
  235. else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  236. {
  237. playerTarget.setGroups(ranks.Trusted);
  238. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  239. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted";
  240. other.gmsg(message);
  241. }
  242. return true;
  243. }
  244. else{
  245. player.sendMessage(Colors.Rose + "Player not found");
  246. }
  247. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  248. }
  249. //Demote
  250. if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
  251. {
  252. if(split.length != 2)
  253. {
  254. player.sendMessage(Colors.Rose + "Usage is /demote [Player]");
  255. }
  256. Player playerTarget = null;
  257. for( Player p : etc.getServer().getPlayerList())
  258. {
  259. if (p.getName().equalsIgnoreCase(split[1]))
  260. {
  261. playerTarget = p;
  262. }
  263. }
  264. if( playerTarget!=null)
  265. {
  266. if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins")))
  267. {
  268. playerTarget.setGroups(ranks.Mods);
  269. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  270. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod";
  271. other.gmsg(message);
  272. }
  273. if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  274. {
  275. playerTarget.setGroups(ranks.Trusted);
  276. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  277. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted";
  278. other.gmsg(message);
  279. }
  280. else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins")))
  281. {
  282. playerTarget.setGroups(ranks.Def);
  283. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  284. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default";
  285. other.gmsg(message);
  286. }
  287. else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  288. {
  289. player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower.");
  290. }
  291. }
  292. else{
  293. player.sendMessage(Colors.Rose + "Player not found");
  294. }
  295. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  296. return true;
  297. }
  298. //Whois will display info about a player
  299. if (settings.getInstance().cmdWhoIs()&&split[0].equalsIgnoreCase("/whois")) {
  300. if (split.length < 2) {
  301. player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  302. }
  303. String admin ="";
  304. String group ="";
  305. String ignore ="";
  306. String IP = "";
  307. Player playerTarget = null;
  308. for( Player p : etc.getServer().getPlayerList())
  309. {
  310. if (p.getName().equalsIgnoreCase(split[1]))
  311. {
  312. playerTarget = p;
  313. }
  314. }
  315. if (playerTarget != null){
  316. etc.getInstance().addCommand("/whois", "/whois [user]");
  317. IP = playerTarget.getIP();
  318. if (playerTarget.canIgnoreRestrictions()) {
  319. ignore = "True";
  320. } else {
  321. ignore ="False";
  322. }
  323. if (playerTarget.canIgnoreRestrictions()) {
  324. admin = "True";
  325. } else {
  326. admin = "False";
  327. }
  328. if (playerTarget.isInGroup("superadmins")){
  329. group = "superadmins";
  330. }else if(playerTarget.isInGroup("admins")){
  331. group = "admins";
  332. }else if(player.isInGroup("mods")){
  333. group = "mods";
  334. }else if(player.isInGroup("trusted")){
  335. group = "trusted";
  336. }else{
  337. group = "Default";
  338. }
  339. //Displaying the information
  340. player.sendMessage(Colors.Blue + "Whois results for "+split[1]+".");
  341. //Group
  342. player.sendMessage(Colors.Blue + "Group: "+group);
  343. //Admin
  344. player.sendMessage(Colors.Blue+"Admin: "+admin);
  345. //IP
  346. player.sendMessage(Colors.Blue+"IP: "+IP);
  347. //Restrictions
  348. player.sendMessage(Colors.Blue+"Can ignore restrictions: "+ignore);
  349. return true;
  350. } else {
  351. player.sendMessage(Colors.Rose+"Player not found.");
  352. }
  353. }
  354. //Say
  355. if (split[0].equalsIgnoreCase("/say")) {
  356. String sayan;
  357. sayan = etc.combineSplit(1, split, " ");
  358. other.gmsg(Colors.Yellow+sayan);
  359. }
  360. //Should this be included?
  361. else {
  362. return false;
  363. }
  364. //Needs to be included
  365. return true;
  366. }
  367. //Calculates how long the specified String is to prevent linebreaks when using scripts that insert color codes, designed to be used with playername included
  368. private boolean lengthCheck(String str)
  369. {
  370. int length = 0;
  371. for(int x = 0; x<str.length(); x++)
  372. {
  373. if("i;,.:|!".indexOf(str.charAt(x)) != -1)
  374. {
  375. length+=2;
  376. }
  377. else if("l'".indexOf(str.charAt(x)) != -1)
  378. {
  379. length+=3;
  380. }
  381. else if("tI[]".indexOf(str.charAt(x)) != -1)
  382. {
  383. length+=4;
  384. }
  385. else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
  386. {
  387. length+=5;
  388. }
  389. else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
  390. {
  391. length+=6;
  392. }
  393. else if("@~".indexOf(str.charAt(x)) != -1)
  394. {
  395. length+=7;
  396. }
  397. else if(str.charAt(x)==' ')
  398. {
  399. length+=4;
  400. }
  401. }
  402. if(length<=316)
  403. {
  404. return true;
  405. } else { return false; }
  406. }
  407. //QuakeColors Part 2
  408. private String colorChange(char colour)
  409. {
  410. String color = "";
  411. switch(colour)
  412. {
  413. case '0':
  414. color = Colors.Black;
  415. break;
  416. case '1':
  417. color = Colors.Navy;
  418. break;
  419. case '2':
  420. color = Colors.Green;
  421. break;
  422. case '3':
  423. color = Colors.Blue;
  424. break;
  425. case '4':
  426. color = Colors.Red;
  427. break;
  428. case '5':
  429. color = Colors.Purple;
  430. break;
  431. case '6':
  432. color = Colors.Gold;
  433. break;
  434. case '7':
  435. color = Colors.LightGray;
  436. break;
  437. case '8':
  438. color = Colors.Gray;
  439. break;
  440. case '9':
  441. color = Colors.DarkPurple;
  442. break;
  443. case 'a':
  444. color = Colors.LightGreen;
  445. break;
  446. case 'b':
  447. color = Colors.LightBlue;
  448. break;
  449. case 'c':
  450. color = Colors.Rose;
  451. break;
  452. case 'd':
  453. color = Colors.LightPurple;
  454. break;
  455. case 'e':
  456. color = Colors.Yellow;
  457. break;
  458. case 'f':
  459. color = Colors.White;
  460. break;
  461. case 'A':
  462. color = Colors.LightGreen;
  463. break;
  464. case 'B':
  465. color = Colors.LightBlue;
  466. break;
  467. case 'C':
  468. color = Colors.Rose;
  469. break;
  470. case 'D':
  471. color = Colors.LightPurple;
  472. break;
  473. case 'E':
  474. color = Colors.Yellow;
  475. break;
  476. case 'F':
  477. color = Colors.White;
  478. break;
  479. default:
  480. color = Colors.White;
  481. break;
  482. }
  483. return color;
  484. }
  485. }