vminecraft.java 16 KB

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