vminecraft.java 19 KB

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