vMinecraftCommands.java 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. import java.io.IOException;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.lang.reflect.Method;
  4. import java.util.ArrayList;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. //=====================================================================
  8. //Class: vMinecraftCommands
  9. //Use: Encapsulates all commands added by this mod
  10. //Author: nos, trapalice, cerevisiae
  11. //=====================================================================
  12. public class vMinecraftCommands{
  13. //Log output
  14. protected static final Logger log = Logger.getLogger("Minecraft");
  15. static final int EXIT_FAIL = 0,
  16. EXIT_SUCCESS = 1,
  17. EXIT_CONTINUE = 2;
  18. //The list of commands for vMinecraft
  19. public static commandList cl = new commandList();
  20. //=====================================================================
  21. //Function: loadCommands
  22. //Input: None
  23. //Output: None
  24. //Use: Imports all the commands into the command list
  25. //=====================================================================
  26. public static void loadCommands(){
  27. //If we had commands we would add them here.
  28. //register: Registers a function for use with a command
  29. //String: The command that will be used
  30. //String: The name of the function that will be called when
  31. // the command is used
  32. //String(Optional): The help menu description
  33. //Administrative
  34. cl.register("/prefix", "prefix");
  35. cl.register("/nick", "nickName");
  36. cl.register("/suffix", "suffix");
  37. cl.register("/vminecraft", "vminecrafthelp");
  38. cl.register("/reload", "reload");
  39. cl.register("/whois", "whois", "/whois [user]");
  40. cl.register("/say", "say");
  41. cl.register("/a", "adminChatToggle", "Toggle admin chat for every message");
  42. cl.register("/modify", "modify");
  43. cl.register("/rules", "rules", "Displays the rules");
  44. cl.register("/who", "who");
  45. //Movement
  46. cl.register("/tp", "teleport");
  47. cl.register("/tphere", "tphere");
  48. cl.register("/masstp", "masstp", "Teleports those with lower permissions to you");
  49. //Health
  50. cl.register("/ezmodo", "invuln", "Toggle invulnerability");
  51. cl.register("/ezlist", "ezlist", "List invulnerable players");
  52. cl.register("/heal", "heal", "heal yourself or other players");
  53. cl.register("/suicide", "suicide", "Kill yourself... you loser");
  54. cl.register("/slay", "slay", "Kill target player");
  55. //Social
  56. cl.register("/colors", "colors");
  57. cl.register("/me", "me");
  58. cl.register("/fabulous", "fabulous", "makes text SUUUPER");
  59. cl.register("/msg", "message", "Send a message to a player /msg [Player] [Message]");
  60. cl.register("/reply", "reply", "Reply to a player /reply [Message], Alias: /r");
  61. cl.register("/ignore", "addIgnored", "Adds a user to your ignore list");
  62. cl.register("/unignore", "removeIgnored", "Removes a user from your ignore list");
  63. cl.register("/ignorelist", "ignoreList", "Lists the players you have ignored");
  64. //registerAlias: Runs the second command when the first command is called
  65. //String: The command that this will be called by
  66. //String: The message that will be called when the first is entered
  67. // Can be modified with %# to have it insert a player
  68. // argument into that position.
  69. // EX: Aliased command is
  70. // cl.registerAlias("/test", "/i %0 100")
  71. // Player uses /test wood
  72. // The %0 will be replaced with wood for this instance
  73. // and Player will be given 100 wood.
  74. cl.registerAlias("/playerlist", "/who");
  75. cl.registerAlias("/vhelp", "/vminecraft");
  76. cl.registerAlias("/r", "/reply");
  77. cl.registerAlias("/t", "/msg");
  78. cl.registerAlias("/tell", "/msg");
  79. cl.registerAlias("/wrists", "/suicide");
  80. cl.registerAlias("/kill", "/suicide");
  81. cl.registerAlias("/ci", "/clearinventory");
  82. //registerMessage: Displays a message whenever a command is used
  83. //String: The command it will run on
  84. //String: What will be displayed
  85. // %p is the player calling the command
  86. // %# is the argument number of the command.
  87. // %#p is an argument number that will be required to be
  88. // an online player
  89. //String: The color the message will be
  90. //int: The number of arguments required for the message to appear
  91. //boolean: If the message should only display for admins
  92. cl.registerMessage("/kick", "%p has kicked %0p", Colors.Blue, 1, false);
  93. cl.registerMessage("/ban", "%p has banned %0p", Colors.Blue, 1, false);
  94. cl.registerMessage("/ipban", "%p has IP banned %0p", Colors.Blue, 1, false);
  95. cl.registerMessage("/time", "Time change thanks to %p", Colors.Blue, 1, true);
  96. cl.registerMessage("/tp", "%p has teleported to %0p", Colors.Blue, 1, true);
  97. }
  98. //=====================================================================
  99. //Function: vminecrafthelp (/vhelp or /vminecraft)
  100. //Input: Player player: The player using the command
  101. //Output: int: Exit Code
  102. //Use: Displays the current status of most vMinecraft settings
  103. // and provides some useful tips.
  104. //=====================================================================
  105. public static int vminecrafthelp(Player player, String[] args){
  106. vMinecraftChat.sendMessage(player, player, Colors.Yellow
  107. + "Chat Settings");
  108. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  109. + "Admin Chat: " + vMinecraftSettings.getInstance()
  110. .adminchat());
  111. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  112. + "FFF turns red: " + vMinecraftSettings.getInstance()
  113. .FFF());
  114. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  115. + "Greentext After >: " + vMinecraftSettings.getInstance()
  116. .greentext());
  117. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  118. + "Quake Color Script: " + vMinecraftSettings.getInstance()
  119. .quakeColors());
  120. vMinecraftChat.sendMessage(player, player, Colors.Yellow
  121. + "Enabled Commands are TRUE, disabled are FALSE");
  122. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  123. + "Command /ezmodo: " + vMinecraftSettings.getInstance()
  124. .cmdEzModo());
  125. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  126. + "Command /fabulous: " + vMinecraftSettings.getInstance()
  127. .cmdFabulous());
  128. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  129. + "Command /rules: " + vMinecraftSettings.getInstance()
  130. .cmdRules());
  131. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  132. + "Command /heal: " + vMinecraftSettings.getInstance()
  133. .cmdHeal());
  134. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  135. + "Command /masstp: " + vMinecraftSettings.getInstance()
  136. .cmdMasstp());
  137. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  138. + "Command /say: " + vMinecraftSettings.getInstance()
  139. .cmdSay());
  140. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  141. + "Command /suicide: " + vMinecraftSettings.getInstance()
  142. .cmdSuicide());
  143. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  144. + "Command /whois: " + vMinecraftSettings.getInstance()
  145. .cmdWhoIs());
  146. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  147. + "Command /tp won't work on higher ranked players: "
  148. + vMinecraftSettings.getInstance().cmdTp());
  149. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  150. + "Command /tphere won't work on higher ranked players: "
  151. + vMinecraftSettings.getInstance().cmdTphere());
  152. vMinecraftChat.sendMessage(player, player, Colors.Yellow
  153. + "Other Settings");
  154. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  155. + "Command /who: " + vMinecraftSettings.getInstance()
  156. .cmdWho());
  157. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  158. + "COLORED PLAYER LIST IS DEPENDENT ON /who BEING TRUE!");
  159. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  160. + "Global Messages: " + vMinecraftSettings.getInstance()
  161. .globalmessages());
  162. return EXIT_SUCCESS;
  163. }
  164. //=====================================================================
  165. //Function: prefix (/prefix)
  166. //Input: Player player: The player using the command
  167. // String[] args: The color and the prefix
  168. //Output: int: Exit Code
  169. //Use: Changes your name color and prefix
  170. //=====================================================================
  171. public static int prefix(Player player, String[] args){
  172. //if the player can prefix others
  173. if(player.canUseCommand("/prefixother")){
  174. //Check if there are enough arguments
  175. if(args.length < 2){
  176. vMinecraftChat.sendMessage(player, player, Colors.Rose + "Usage is /prefix [Color Code] <Tag>");
  177. player.sendMessage(Colors.DarkPurple + "Example: /prefix " + player.getName() + " e ^0[^a<3^0]");
  178. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple + "This would produce a name like... " + Colors.Black + "[" + Colors.LightGreen + "<3" + Colors.Black + "]" + Colors.Yellow + player.getName());
  179. return EXIT_SUCCESS;
  180. }
  181. //Check if the prefix is too long
  182. if(args[1].length() > 15)
  183. {
  184. vMinecraftChat.sendMessage(player, player, Colors.Rose
  185. + "The prefix you entered was too long.");
  186. return EXIT_SUCCESS;
  187. }
  188. //Check if the player exists
  189. Player other = etc.getServer().matchPlayer(args[0]);
  190. if(other == null)
  191. {
  192. vMinecraftChat.sendMessage(player, player, Colors.Rose
  193. + "The player you specified could not be found");
  194. return EXIT_SUCCESS;
  195. }
  196. if(args.length >= 2 && args[0] != null){
  197. player.setPrefix(args[1]);
  198. }
  199. if(args.length >= 3 && args[1] != null){
  200. vMinecraftUsers.players.findProfile(player).setTag(args[2]);
  201. }
  202. return EXIT_SUCCESS;
  203. }
  204. //If the player can set their prefix
  205. if(!player.canUseCommand("/prefix")){
  206. return EXIT_FAIL;
  207. }
  208. //Check if there are enough arguments
  209. if(args.length < 1){
  210. vMinecraftChat.sendMessage(player, player, Colors.Rose + "Usage is /prefix [Color Code] <Tag>");
  211. player.sendMessage(Colors.DarkPurple + "Example: /prefix e ^0[^a<3^0]");
  212. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple + "This would produce a name like... " + Colors.Black + "[" + Colors.LightGreen + "<3" + Colors.Black + "]" + Colors.Yellow + player.getName());
  213. return EXIT_SUCCESS;
  214. }
  215. //Name color
  216. if(args.length >= 1 && args[0] != null){
  217. player.setPrefix(args[0]);
  218. player.sendMessage(Colors.Rose + "Name color changed");
  219. }
  220. //Prefix
  221. if(args.length >= 2 && args[1] != null){
  222. //Check if the prefix is too long
  223. if(args[1].length() > 15)
  224. {
  225. vMinecraftChat.sendMessage(player, player, Colors.Rose
  226. + "The prefix you entered was too long.");
  227. return EXIT_SUCCESS;
  228. }
  229. vMinecraftUsers.players.findProfile(player).setTag(args[1]);
  230. player.sendMessage(Colors.LightGreen + "Prefix changed");
  231. }
  232. return EXIT_SUCCESS;
  233. }
  234. //=====================================================================
  235. //Function: nickName (/nick)
  236. //Input: Player player: The player using the command
  237. // String[] args: The color and the prefix
  238. //Output: int: Exit Code
  239. //Use: Changes your name
  240. //=====================================================================
  241. public static int nickName(Player player, String[] args){
  242. //if the player can nickname others
  243. if(player.canUseCommand("/nickother")){
  244. if(args.length < 2){
  245. vMinecraftChat.sendMessage(player, player, Colors.Rose
  246. + "Usage is /nick [Player] [Name]");
  247. return EXIT_SUCCESS;
  248. }
  249. //Check if the nickname is too long
  250. if(args[1].length() > 30)
  251. {
  252. vMinecraftChat.sendMessage(player, player, Colors.Rose
  253. + "The suffix you entered was too long.");
  254. return EXIT_SUCCESS;
  255. }
  256. //Check if the player exists
  257. Player other = etc.getServer().matchPlayer(args[0]);
  258. if(other == null)
  259. {
  260. vMinecraftChat.sendMessage(player, player, Colors.Rose
  261. + "The player you specified could not be found");
  262. return EXIT_SUCCESS;
  263. }
  264. vMinecraftUsers.getProfile(other).setNick(args[1]);
  265. return EXIT_SUCCESS;
  266. }
  267. //Make sure they can nickname themselves
  268. if(!player.canUseCommand("/nick")){
  269. return EXIT_FAIL;
  270. }
  271. //Check if the nickname is too long
  272. if(args[0].length() > 30)
  273. {
  274. vMinecraftChat.sendMessage(player, player, Colors.Rose
  275. + "The suffix you entered was too long.");
  276. return EXIT_SUCCESS;
  277. }
  278. if(args.length < 1){
  279. vMinecraftChat.sendMessage(player, player, Colors.Rose
  280. + "Usage is /nick [Name]");
  281. return EXIT_SUCCESS;
  282. }
  283. vMinecraftUsers.getProfile(player).setNick(args[0]);
  284. return EXIT_SUCCESS;
  285. }
  286. //=====================================================================
  287. //Function: suffix (/suffix)
  288. //Input: Player player: The player using the command
  289. // String[] args: The color and the prefix
  290. //Output: int: Exit Code
  291. //Use: Changes your suffix
  292. //=====================================================================
  293. public static int suffix(Player player, String[] args){
  294. //if the player can suffix others
  295. if(player.canUseCommand("/suffixother")){
  296. if(args.length < 2){
  297. vMinecraftChat.sendMessage(player, player, Colors.Rose
  298. + "Usage is /suffix [Player] [Name]");
  299. return EXIT_SUCCESS;
  300. }
  301. //Check if the suffix is too long
  302. if(args[1].length() > 20)
  303. {
  304. vMinecraftChat.sendMessage(player, player, Colors.Rose
  305. + "The suffix you entered was too long.");
  306. return EXIT_SUCCESS;
  307. }
  308. //Check if the player exists
  309. Player other = etc.getServer().matchPlayer(args[0]);
  310. if(other == null)
  311. {
  312. vMinecraftChat.sendMessage(player, player, Colors.Rose
  313. + "The player you specified could not be found");
  314. return EXIT_SUCCESS;
  315. }
  316. vMinecraftUsers.getProfile(other).setSuffix(args[1]);
  317. return EXIT_SUCCESS;
  318. }
  319. //Check if the player can set their own suffix.
  320. if(!player.canUseCommand("/suffix")){
  321. return EXIT_FAIL;
  322. }
  323. if(args.length < 1){
  324. vMinecraftChat.sendMessage(player, player, Colors.Rose
  325. + "Usage is /suffix [Suffix]");
  326. return EXIT_SUCCESS;
  327. }
  328. //Check if the suffix is too long
  329. if(args[0].length() > 20)
  330. {
  331. vMinecraftChat.sendMessage(player, player, Colors.Rose
  332. + "The suffix you entered was too long.");
  333. return EXIT_SUCCESS;
  334. }
  335. vMinecraftUsers.getProfile(player).setSuffix(args[0]);
  336. return EXIT_SUCCESS;
  337. }
  338. //=====================================================================
  339. //Function: colors (/colors)
  340. //Input: Player player: The player using the command
  341. //Output: int: Exit Code
  342. //Use: Displays a list of all colors and color codes
  343. //=====================================================================
  344. public static int colors(Player player, String[] args){
  345. player.sendMessage(Colors.Rose + "You use these color codes like in quake or MW2, ^4 would make text red, ^a would make it light green.");
  346. vMinecraftChat.sendMessage(player, player,
  347. Colors.Black + "0"
  348. + Colors.Navy + "1"
  349. + Colors.Green + "2"
  350. + Colors.Blue + "3"
  351. + Colors.Red + "4"
  352. + Colors.Purple + "5"
  353. + Colors.Gold + "6"
  354. + Colors.LightGray + "7"
  355. + Colors.Gray + "8"
  356. + Colors.DarkPurple + "9"
  357. + Colors.LightGreen + "a"
  358. + Colors.LightBlue + "b"
  359. + Colors.Rose + "c"
  360. + Colors.LightPurple + "d"
  361. + Colors.White + "f");
  362. return EXIT_SUCCESS;
  363. }
  364. //=====================================================================
  365. //Function: me (/me)
  366. //Input: Player player: The player using the command
  367. // String[] args: Will contain the message the player sends
  368. //Output: int: Exit Code
  369. //Use: The player uses this to emote, but now its colorful.
  370. //=====================================================================
  371. public static int me(Player player, String[] args)
  372. {
  373. String str = etc.combineSplit(0, args, " ");
  374. if (args.length < 1) return EXIT_FAIL;
  375. vMinecraftChat.emote(player, str);
  376. return EXIT_SUCCESS;
  377. }
  378. //=====================================================================
  379. //Function: message (/msg, /w, /whisper)
  380. //Input: Player player: The player using the command
  381. // String[] args: Will contain the target player name and
  382. // message the player sends
  383. //Output: int: Exit Code
  384. //Use: Send a message to a player
  385. //=====================================================================
  386. public static int message(Player player, String[] args)
  387. {
  388. //Make sure a player is specified
  389. if (args.length > 1) {
  390. vMinecraftChat.sendMessage(player, player, Colors.Rose
  391. + "Usage is /msg [player] [message]");
  392. return EXIT_SUCCESS;
  393. }
  394. //Make sure the player exists
  395. Player toPlayer = etc.getServer().matchPlayer(args[0]);
  396. if (toPlayer != null && args.length > 0) {
  397. vMinecraftChat.sendMessage(player, player, Colors.Rose
  398. + "No player by the name of " + args[0] + " could be found.");
  399. return EXIT_SUCCESS;
  400. }
  401. String msg = etc.combineSplit(1, args, " ");
  402. //Send the message to the targeted player and the sender
  403. vMinecraftChat.sendMessage(player, toPlayer,
  404. Colors.LightGreen + "[From:" + vMinecraftChat.getName(player)
  405. + Colors.LightGreen + "] " + msg);
  406. vMinecraftChat.sendMessage(player, player,
  407. Colors.LightGreen + "[To:" + vMinecraftChat.getName(toPlayer)
  408. + Colors.LightGreen + "] " + msg);
  409. //Set the last massager for each player
  410. vMinecraftUsers.getProfile(player).setMessage(toPlayer);
  411. vMinecraftUsers.getProfile(toPlayer).setMessage(player);
  412. //Display the message to the log
  413. log.log(Level.INFO, player.getName() + " whispered to " + toPlayer.getName()
  414. + ": " + msg);
  415. return EXIT_SUCCESS;
  416. }
  417. //=====================================================================
  418. //Function: reply (/r, /reply)
  419. //Input: Player player: The player using the command
  420. // String[] args: Will contain the message the player sends
  421. //Output: int: Exit Code
  422. //Use: Send a message to a player
  423. //=====================================================================
  424. public static int reply(Player player, String[] args)
  425. {
  426. //If the profile exists for the player
  427. if(vMinecraftUsers.getProfile(player) == null ) {
  428. vMinecraftChat.sendMessage(player, player,
  429. Colors.Rose + "The person you last message has logged off");
  430. return EXIT_SUCCESS;
  431. }
  432. //Make sure a message is specified
  433. if (args.length < 1) {
  434. vMinecraftChat.sendMessage(player, player,
  435. Colors.Rose + "Usage is /reply [Message]");
  436. return EXIT_SUCCESS;
  437. }
  438. //Make sure the player they're talking to is online
  439. Player toPlayer = vMinecraftUsers.getProfile(player).getMessage();
  440. if (toPlayer == null) {
  441. vMinecraftChat.sendMessage(player, player,
  442. Colors.Rose + "The person you last message has logged off");
  443. return EXIT_SUCCESS;
  444. }
  445. String msg = etc.combineSplit(0, args, " ");
  446. //Send the message to the targeted player and the sender
  447. vMinecraftChat.sendMessage(player, toPlayer,
  448. Colors.LightGreen + "[From:" + vMinecraftChat.getName(player)
  449. + Colors.LightGreen + "] " + msg);
  450. vMinecraftChat.sendMessage(player, player,
  451. Colors.LightGreen + "[To:" + vMinecraftChat.getName(toPlayer)
  452. + Colors.LightGreen + "] " + msg);
  453. //Set the last messager for each player
  454. vMinecraftUsers.getProfile(player).setMessage(toPlayer);
  455. vMinecraftUsers.getProfile(toPlayer).setMessage(player);
  456. //Display the message to the log
  457. log.log(Level.INFO, player.getName() + " whispered to " + toPlayer.getName()
  458. + ": " + msg);
  459. return EXIT_SUCCESS;
  460. }
  461. //=====================================================================
  462. //Function: addIgnored (/ignore)
  463. //Input: Player player: The player using the command
  464. // String[] args: The name of the player to ignore
  465. //Output: int: Exit Code
  466. //Use: Adds a player to the ignore list
  467. //=====================================================================
  468. public static int addIgnored(Player player, String[] args)
  469. {
  470. //Make sure the player gave you a user to ignore
  471. if(args.length < 1)
  472. {
  473. vMinecraftChat.sendMessage(player, player,
  474. Colors.Rose + "Usage: /ignore [Player]");
  475. return EXIT_SUCCESS;
  476. }
  477. //Find the player and make sure they exist
  478. Player ignore = etc.getServer().matchPlayer(args[0]);
  479. if(ignore == null)
  480. {
  481. vMinecraftChat.sendMessage(player, player, Colors.Rose
  482. + "The person you tried to ignore is not logged in.");
  483. return EXIT_SUCCESS;
  484. }
  485. //Don't let the player ignore themselves
  486. if(!ignore.getName().equalsIgnoreCase(player.getName()))
  487. {
  488. vMinecraftChat.sendMessage(player, player,
  489. Colors.Rose + "You cannot ignore yourself");
  490. return EXIT_SUCCESS;
  491. }
  492. //Attempt to ignore the player and report accordingly
  493. if(vMinecraftUsers.getProfile(player).addIgnore(ignore))
  494. vMinecraftChat.sendMessage(player, player, Colors.Rose
  495. + ignore.getName() + " has been successfuly ignored.");
  496. else
  497. vMinecraftChat.sendMessage(player, player, Colors.Rose
  498. + "You are already ignoring " + ignore.getName());
  499. return EXIT_SUCCESS;
  500. }
  501. //=====================================================================
  502. //Function: removeIgnored (/unignore)
  503. //Input: Player player: The player using the command
  504. // String[] args: The name of the player to stop ignoring
  505. //Output: int: Exit Code
  506. //Use: Removes a player from the ignore list
  507. //=====================================================================
  508. public static int removeIgnored(Player player, String[] args)
  509. {
  510. //Make sure the player gave you a user to ignore
  511. if(args.length < 1)
  512. {
  513. vMinecraftChat.sendMessage(player, player,
  514. Colors.Rose + "Usage: /unignore [Player]");
  515. return EXIT_SUCCESS;
  516. }
  517. //Find the player and make sure they exist
  518. Player ignore = etc.getServer().matchPlayer(args[0]);
  519. if(ignore == null)
  520. {
  521. vMinecraftChat.sendMessage(player, player,
  522. Colors.Rose + "The person you tried to unignore is not logged in.");
  523. return EXIT_SUCCESS;
  524. }
  525. //Attempt to ignore the player and report accordingly
  526. if(vMinecraftUsers.getProfile(player).removeIgnore(ignore))
  527. vMinecraftChat.sendMessage(player, player,
  528. Colors.Rose + ignore.getName()+ " has been successfuly " +
  529. "unignored.");
  530. else
  531. vMinecraftChat.sendMessage(player, player,
  532. Colors.Rose + "You are not currently ignoring " + ignore.getName());
  533. return EXIT_SUCCESS;
  534. }
  535. //=====================================================================
  536. //Function: ignoreList (/ignorelist)
  537. //Input: Player player: The player using the command
  538. // String[] args: Ignored
  539. //Output: int: Exit Code
  540. //Use: Lists the player you have ignored
  541. //=====================================================================
  542. public static int ignoreList(Player player, String[] args)
  543. {
  544. //Get the ignore list
  545. String[] list = vMinecraftUsers.getProfile(player).listIgnore();
  546. //Find the last page number
  547. int lastPage = (int)list.length / 5;
  548. if((int)list.length % 5 > 0)
  549. lastPage++;
  550. //Find the page number the player wants displayed
  551. int page = 0;
  552. if(args.length > 0 && Integer.valueOf(args[0]) > 0
  553. && Integer.valueOf(args[0]) <= lastPage)
  554. page = Integer.valueOf(args[0]) - 1;
  555. //Display the header
  556. vMinecraftChat.sendMessage(player, player,
  557. Colors.Rose + "Ignore List [" + page + "/"
  558. + lastPage + "]");
  559. //Display up to 5 people
  560. for(int i = 0; i < 5 && i + (page * 5) < list.length; i++)
  561. vMinecraftChat.sendMessage(player, player,
  562. Colors.Rose + list[i+ (page * 5)]);
  563. return EXIT_SUCCESS;
  564. }
  565. //=====================================================================
  566. //Function: adminChatToggle (/a)
  567. //Input: Player player: The player using the command
  568. // String[] args: Ignored
  569. //Output: int: Exit Code
  570. //Use: Toggles the player into admin chat. Every message they
  571. // send will be piped to admin chat.
  572. //=====================================================================
  573. public static int adminChatToggle(Player player, String[] args)
  574. {
  575. //Make sure the user has access to the command
  576. if(!player.canUseCommand("/a")) return EXIT_FAIL;
  577. if(!vMinecraftSettings.getInstance().adminChatToggle()) return EXIT_FAIL;
  578. //If the player is already toggled for admin chat, remove them
  579. if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) {
  580. player.sendMessage(Colors.Red + "Admin Chat Toggle = off");
  581. vMinecraftSettings.getInstance().removeAdminToggled(player.getName());
  582. //Otherwise include them
  583. } else {
  584. player.sendMessage(Colors.Blue + "Admin Chat Toggled on");
  585. vMinecraftSettings.getInstance().addAdminToggled(player.getName());
  586. }
  587. return EXIT_SUCCESS;
  588. }
  589. //=====================================================================
  590. //Function: heal (/heal)
  591. //Input: Player player: The player using the command
  592. // String[] args: The arguments for the command. Should be a
  593. // player name or blank
  594. //Output: int: Exit Code
  595. //Use: Heals yourself or a specified player.
  596. //=====================================================================
  597. public static int heal(Player player, String[] args)
  598. {
  599. //Make sure the user has access to the command
  600. if(!player.canUseCommand("/heal")) return EXIT_FAIL;
  601. if(!vMinecraftSettings.getInstance().cmdHeal()) return EXIT_FAIL;
  602. //If a target wasn't specified, heal the user.
  603. if (args.length < 1){
  604. player.setHealth(20);
  605. player.sendMessage("Your health is restored");
  606. return EXIT_SUCCESS;
  607. }
  608. //If a target was specified, try to find them and then heal them
  609. //Otherwise report the error
  610. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  611. if (playerTarget == null){
  612. player.sendMessage(Colors.Rose
  613. + "Couldn't find that player");
  614. return EXIT_SUCCESS;
  615. }
  616. playerTarget.setHealth(20);
  617. player.sendMessage(Colors.Blue + "You have healed "
  618. + vMinecraftChat.getName(playerTarget));
  619. playerTarget.sendMessage(Colors.Blue
  620. + "You have been healed by "
  621. + vMinecraftChat.getName(player));
  622. return EXIT_SUCCESS;
  623. }
  624. //=====================================================================
  625. //Function: suicide (/suicide, /wrists)
  626. //Input: Player player: The player using the command
  627. // String[] args: Ignored
  628. //Output: int: Exit Code
  629. //Use: Kills yourself
  630. //=====================================================================
  631. public static int suicide(Player player, String[] args)
  632. {
  633. //Make sure the user has access to the command
  634. if(!player.canUseCommand("/suicide")) return EXIT_FAIL;
  635. if(vMinecraftSettings.getInstance().cmdSuicide()) return EXIT_FAIL;
  636. //Set your health to 0. Not much to it.
  637. player.setHealth(0);
  638. return EXIT_SUCCESS;
  639. }
  640. //=====================================================================
  641. //Function: teleport (/tp)
  642. //Input: Player player: The player using the command
  643. // String[] args: The arguments for the command. Should be a
  644. // player name
  645. //Output: int: Exit Code
  646. //Use: Teleports the user to another player
  647. //=====================================================================
  648. public static int teleport(Player player, String[] args)
  649. {
  650. //Make sure the user has access to the command
  651. if(!player.canUseCommand("/tp")) return EXIT_FAIL;
  652. //Get if the command is enabled
  653. if(!vMinecraftSettings.getInstance().cmdTp())return EXIT_FAIL;
  654. //Make sure a player has been specified and return an error if not
  655. if (args.length < 1) {
  656. player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]");
  657. return EXIT_SUCCESS;
  658. }
  659. //Find the player by name
  660. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  661. //Target player isn't found
  662. if(playerTarget == null)
  663. player.sendMessage(Colors.Rose + "Can't find user "
  664. + args[0] + ".");
  665. //If it's you, return witty message
  666. else if (player.getName().equalsIgnoreCase(args[0]))
  667. player.sendMessage(Colors.Rose + "You're already here!");
  668. //If the player is higher rank than you, inform the user
  669. else if (!player.hasControlOver(playerTarget))
  670. player.sendMessage(Colors.Red +
  671. "That player has higher permissions than you.");
  672. //If the player exists transport the user to the player
  673. else {
  674. log.log(Level.INFO, player.getName() + " teleported to " +
  675. playerTarget.getName());
  676. player.teleportTo(playerTarget);
  677. }
  678. return EXIT_SUCCESS;
  679. }
  680. //=====================================================================
  681. //Function: masstp (/masstp)
  682. //Input: Player player: The player using the command
  683. // String[] args: Should be empty or is ignored
  684. //Output: int: Exit Code
  685. //Use: Teleports all players to the user
  686. //=====================================================================
  687. public static int masstp(Player player, String[] args)
  688. {
  689. //Make sure the user has access to the command
  690. if(!player.canUseCommand("/masstp")) return EXIT_FAIL;
  691. //If the command is enabled
  692. if(!vMinecraftSettings.getInstance().cmdMasstp())return EXIT_FAIL;
  693. //Go through all players and move them to the user
  694. for (Player p : etc.getServer().getPlayerList()) {
  695. if (!p.hasControlOver(player)) {
  696. p.teleportTo(player);
  697. }
  698. }
  699. //Inform the user that the command has executed successfully
  700. player.sendMessage(Colors.Blue + "Summoning successful.");
  701. return EXIT_SUCCESS;
  702. }
  703. //=====================================================================
  704. //Function: tphere (/tphere)
  705. //Input: Player player: The player using the command
  706. // String[] args: The arguments for the command. Should be a
  707. // player name
  708. //Output: int: Exit Code
  709. //Use: Teleports the user to another player
  710. //=====================================================================
  711. public static int tphere(Player player, String[] args)
  712. {
  713. //Make sure the user has access to the command
  714. if(!player.canUseCommand("/tphere")) return EXIT_FAIL;
  715. //Check if the command is enabled.
  716. if (!vMinecraftSettings.getInstance().cmdTphere())return EXIT_FAIL;
  717. //Make sure a player is specified
  718. if (args.length < 1) {
  719. player.sendMessage(Colors.Rose + "Correct usage" +
  720. " is: /tphere [player]");
  721. return EXIT_SUCCESS;
  722. }
  723. //Get the player by name
  724. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  725. //If the target doesn't exist
  726. if(playerTarget == null)
  727. player.sendMessage(Colors.Rose + "Can't find user "
  728. + args[0] + ".");
  729. //If the player has a higher rank than the user, return error
  730. else if (!player.hasControlOver(playerTarget))
  731. player.sendMessage(Colors.Red + "That player has higher" +
  732. " permissions than you.");
  733. //If the user teleports themselves, mock them
  734. else if (player.getName().equalsIgnoreCase(args[0]))
  735. player.sendMessage(Colors.Rose + "Wow look at that! You" +
  736. " teleported yourself to yourself!");
  737. //If the target exists, teleport them to the user
  738. else {
  739. log.log(Level.INFO, player.getName() + " teleported "
  740. + player.getName() + " to their self.");
  741. playerTarget.teleportTo(player);
  742. }
  743. return EXIT_SUCCESS;
  744. }
  745. //=====================================================================
  746. //Function: reload (/reload)
  747. //Input: Player player: The player using the command
  748. // String[] args: Ignored
  749. //Output: int: Exit Code
  750. //Use: Reloads the settings for vMinecraft
  751. //=====================================================================
  752. public static int reload(Player player, String[] args)
  753. {
  754. //Make sure the user has access to the command
  755. if(!player.canUseCommand("/reload")) return EXIT_FAIL;
  756. vMinecraftSettings.getInstance().loadSettings();
  757. return EXIT_SUCCESS;
  758. }
  759. //=====================================================================
  760. //Function: rules (/rules)
  761. //Input: Player player: The player using the command
  762. // String[] args: Ignored
  763. //Output: int: Exit Code
  764. //Use: Lists the rules
  765. //=====================================================================
  766. public static int rules(Player player, String[] args)
  767. {
  768. //If the rules exist
  769. if(!vMinecraftSettings.getInstance().cmdRules()
  770. && vMinecraftSettings.getInstance().getRules().length > 0
  771. && !vMinecraftSettings.getInstance().getRules()[0].isEmpty()) {
  772. return EXIT_FAIL;
  773. }
  774. //Apply QuakeCode Colors to the rules
  775. String[] rules = vMinecraftChat.applyColors(
  776. vMinecraftSettings.getInstance().getRules());
  777. //Display them
  778. for (String str : rules ) {
  779. if(!str.isEmpty())
  780. player.sendMessage(Colors.Blue + str);
  781. else
  782. player.sendMessage(Colors.Blue
  783. + "!!!The Rules Have Not Been Set!!!");
  784. }
  785. return EXIT_SUCCESS;
  786. }
  787. //=====================================================================
  788. //Function: fabulous (/fabulous)
  789. //Input: Player player: The player using the command
  790. // String[] args: The message to apply the effect to
  791. //Output: int: Exit Code
  792. //Use: Makes the text rainbow colored
  793. //=====================================================================
  794. public static int fabulous(Player player, String[] args)
  795. {
  796. //If the command is enabled
  797. if(!vMinecraftSettings.getInstance().cmdFabulous()) return EXIT_FAIL;
  798. //Make sure a message has been specified
  799. if (args.length < 1) {
  800. player.sendMessage(Colors.Rose + "Usage /fabulous [Message]");
  801. return EXIT_SUCCESS;
  802. }
  803. //Format the name
  804. String playerName = Colors.White + "<"
  805. + vMinecraftChat.getName(player) + Colors.White +"> ";
  806. //Merge the message again
  807. String str = etc.combineSplit(0, args, " ");
  808. //Output for server
  809. log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  810. //Prepend the player name and cut into lines.
  811. vMinecraftChat.gmsg(player, playerName + vMinecraftChat.rainbow(str));
  812. return EXIT_SUCCESS;
  813. }
  814. //=====================================================================
  815. //Function: whois (/whois)
  816. //Input: Player player: The player using the command
  817. // String[] args: The player to find info on
  818. //Output: int: Exit Code
  819. //Use: Displays information about the player specified
  820. //=====================================================================
  821. public static int whois(Player player, String[] args)
  822. {
  823. //Make sure the user has access to the command
  824. if(!player.canUseCommand("/whois")) return EXIT_FAIL;
  825. //If the command is enabled
  826. if (!vMinecraftSettings.getInstance().cmdWhoIs()) return EXIT_FAIL;
  827. //If a player is specified
  828. if (args.length < 1)
  829. {
  830. player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  831. return EXIT_SUCCESS;
  832. }
  833. //Get the player by name
  834. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  835. //If the player exists
  836. if (playerTarget == null){
  837. player.sendMessage(Colors.Rose+"Player not found.");
  838. return EXIT_SUCCESS;
  839. }
  840. //Displaying the information
  841. player.sendMessage(Colors.Blue + "Whois results for " +
  842. vMinecraftChat.getName(playerTarget));
  843. //Group
  844. for(String group: playerTarget.getGroups())
  845. player.sendMessage(Colors.Blue + "Groups: " + group);
  846. //Only let admins see this info
  847. if(player.isAdmin())
  848. {
  849. //Admin
  850. player.sendMessage(Colors.Blue+"Admin: " +
  851. String.valueOf(playerTarget.isAdmin()));
  852. //IP
  853. player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP());
  854. //Restrictions
  855. player.sendMessage(Colors.Blue+"Can ignore restrictions: " +
  856. String.valueOf(playerTarget.canIgnoreRestrictions()));
  857. }
  858. return EXIT_SUCCESS;
  859. }
  860. //=====================================================================
  861. //Function: who (/who)
  862. //Input: Player player: The player using the command
  863. // String[] args: Ignored
  864. //Output: int: Exit Code
  865. //Use: Displays the connected players
  866. //=====================================================================
  867. public static int who(Player player, String[] args)
  868. {
  869. //If the command is enabled
  870. if (!vMinecraftSettings.getInstance().cmdWho()) return EXIT_FAIL;
  871. //Loop through all players counting them and adding to the list
  872. int count=0;
  873. String tempList = "";
  874. for( Player p : etc.getServer().getPlayerList())
  875. {
  876. if(p != null){
  877. if(count == 0)
  878. tempList += vMinecraftChat.getName(p);
  879. else
  880. tempList += Colors.White + ", " + vMinecraftChat.getName(p);
  881. count++;
  882. }
  883. }
  884. //Get the max players from the config
  885. PropertiesFile server = new PropertiesFile("server.properties");
  886. try {
  887. server.load();
  888. } catch (IOException e) {
  889. e.printStackTrace();
  890. }
  891. int maxPlayers = server.getInt("max-players");
  892. //Output the player list
  893. vMinecraftChat.sendMessage(player, player, Colors.Rose + "Player List ("
  894. + count + "/" + maxPlayers +"): " + tempList);
  895. return EXIT_SUCCESS;
  896. }
  897. //=====================================================================
  898. //Function: say (/say)
  899. //Input: Player player: The player using the command
  900. // String[] args: The message to apply the effect to
  901. //Output: int: Exit Code
  902. //Use: Announces the message to all players
  903. //=====================================================================
  904. public static int say(Player player, String[] args)
  905. {
  906. //Make sure the user has access to the command
  907. if(!player.canUseCommand("/say")) return EXIT_FAIL;
  908. //Check if the command is enabled
  909. if (!vMinecraftSettings.getInstance().cmdSay()) return EXIT_FAIL;
  910. //Make sure a message is supplied or output an error
  911. if (args.length < 1) {
  912. player.sendMessage(Colors.Rose + "Usage is /say [message]");
  913. }
  914. //Display the message globally
  915. vMinecraftChat.gmsg(player, Colors.Yellow
  916. + etc.combineSplit(0, args, " "));
  917. return EXIT_SUCCESS;
  918. }
  919. //=====================================================================
  920. //Function: slay (/slay)
  921. //Input: Player player: The player using the command
  922. // String[] args: The target for the command
  923. //Output: int: Exit Code
  924. //Use: Kill the target player
  925. //=====================================================================
  926. public static int slay(Player player, String[] args)
  927. {
  928. //Make sure the user has access to the command
  929. if(!player.canUseCommand("/slay")) return EXIT_FAIL;
  930. //Check if the command is enabled
  931. if(!vMinecraftSettings.getInstance().cmdEzModo()) return EXIT_FAIL;
  932. //Get the player by name
  933. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  934. //If the player doesn't exist don't run
  935. if(playerTarget == null)
  936. {
  937. player.sendMessage(Colors.Rose + "Usage is /slay [Player]");
  938. return EXIT_SUCCESS;
  939. }
  940. //If the player isn't invulnerable kill them
  941. if (vMinecraftSettings.getInstance()
  942. .isEzModo(playerTarget.getName())) {
  943. player.sendMessage(Colors.Rose + "That player is currently in" +
  944. " ezmodo! Hahahaha");
  945. }
  946. playerTarget.setHealth(0);
  947. vMinecraftChat.gmsg(player, vMinecraftChat.getName(player)
  948. + Colors.LightBlue + " has slain "
  949. + vMinecraftChat.getName(playerTarget));
  950. //Otherwise output error to the user
  951. return EXIT_SUCCESS;
  952. }
  953. //=====================================================================
  954. //Function: invuln (/ezmodo)
  955. //Input: Player player: The player using the command
  956. // String[] args: The target for the command
  957. //Output: int: Exit Code
  958. //Use: Kill the target player
  959. //=====================================================================
  960. public static int invuln(Player player, String[] args)
  961. {
  962. //Make sure the user has access to the command
  963. if(!player.canUseCommand("/ezmodo")) return EXIT_FAIL;
  964. //If the command is enabled
  965. if (!vMinecraftSettings.getInstance().cmdEzModo()) return EXIT_FAIL;
  966. //If the player is already invulnerable, turn ezmodo off.
  967. if (vMinecraftSettings.getInstance().isEzModo(player.getName())) {
  968. player.sendMessage(Colors.Red + "ezmodo = off");
  969. vMinecraftSettings.getInstance().removeEzModo(player.getName());
  970. //Otherwise make them invulnerable
  971. } else {
  972. player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?");
  973. player.sendMessage(Colors.Rose + "kimo-i");
  974. player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru" +
  975. " no wa shougakusei made dayo ne");
  976. player.sendMessage(Colors.Red + "**Laughter**");
  977. vMinecraftSettings.getInstance().addEzModo(player.getName());
  978. }
  979. return EXIT_SUCCESS;
  980. }
  981. //=====================================================================
  982. //Function: ezlist (/ezlist)
  983. //Input: Player player: The player using the command
  984. // String[] args: Ignored
  985. //Output: int: Exit Code
  986. //Use: List all invulnerable players
  987. //=====================================================================
  988. public static int ezlist(Player player, String[] args)
  989. {
  990. //Make sure the user has access to the command
  991. if(!player.canUseCommand("/ezmodo")) return EXIT_FAIL;
  992. //If the feature is enabled list the players
  993. if(!vMinecraftSettings.getInstance().cmdEzModo()) return EXIT_FAIL;
  994. player.sendMessage("Ezmodo: " + vMinecraftSettings.getInstance().ezModoList());
  995. return EXIT_SUCCESS;
  996. }
  997. //=====================================================================
  998. //Function: modify (/modify)
  999. //Input: Player player: The player using the command
  1000. // String[] args: Player, Command, Arguments
  1001. //Output: int: Exit Code
  1002. //Use: List all invulnerable players
  1003. //=====================================================================
  1004. public static int modify(Player player, String[] args)
  1005. {
  1006. if(player.canUseCommand("/prefix"))
  1007. vMinecraftChat.sendMessage(player, player, "/prefix [Color]" +
  1008. " (Tag) - Set your prefix and tag.");
  1009. return EXIT_SUCCESS;
  1010. }
  1011. //=====================================================================
  1012. //Function: Time Reverse
  1013. //Input: long time: The time to reverse to.
  1014. //Output: int: Exit Code
  1015. //Use: List all invulnerable players
  1016. //=====================================================================
  1017. public static int timeReverse(long tarTime)
  1018. {
  1019. long curTime = etc.getServer().getRelativeTime();
  1020. //if(cur)
  1021. return EXIT_SUCCESS;
  1022. }
  1023. }
  1024. //=====================================================================
  1025. //Class: commandList
  1026. //Use: The list of commands that will be checked for
  1027. //Author: cerevisiae
  1028. //=====================================================================
  1029. class commandList {
  1030. ArrayList<command> commands;
  1031. protected static final Logger log = Logger.getLogger("Minecraft");
  1032. static final int EXIT_FAIL = 0,
  1033. EXIT_SUCCESS = 1,
  1034. EXIT_CONTINUE = 2;
  1035. //=====================================================================
  1036. //Function: commandList
  1037. //Input: None
  1038. //Output: None
  1039. //Use: Initialize the array of commands
  1040. //=====================================================================
  1041. public commandList(){
  1042. commands = new ArrayList<command>();
  1043. }
  1044. //=====================================================================
  1045. //Function: register
  1046. //Input: String name: The name of the command
  1047. // String func: The function to be called
  1048. //Output: boolean: Whether the command was input successfully or not
  1049. //Use: Registers a command to the command list for checking later
  1050. //=====================================================================
  1051. public boolean register(String name, String func)
  1052. {
  1053. //Check to make sure the command doesn't already exist
  1054. for(command temp : commands)
  1055. if(temp.getName().equalsIgnoreCase(name))
  1056. return false;
  1057. //Add the new function to the list
  1058. commands.add(new command(name, func));
  1059. //exit successfully
  1060. return true;
  1061. }
  1062. //=====================================================================
  1063. //Function: register
  1064. //Input: String name: The name of the command
  1065. // String func: The function to be called
  1066. // String info: The information for the command to put in help
  1067. //Output: boolean: Whether the command was input successfully or not
  1068. //Use: Registers a command to the command list for checking later
  1069. //=====================================================================
  1070. public boolean register(String name, String func, String info){
  1071. //Add to the /help list
  1072. etc.getInstance().addCommand(name, info);
  1073. //Finish registering
  1074. return register(name, func);
  1075. }
  1076. //=====================================================================
  1077. //Function: register
  1078. //Input: String name: The name of the command
  1079. // String func: The function to be called
  1080. //Output: boolean: Whether the command was input successfully or not
  1081. //Use: Registers a command to the command list for checking later
  1082. //=====================================================================
  1083. public boolean registerAlias(String name, String com)
  1084. {
  1085. //Check to make sure the command doesn't already exist
  1086. for(command temp : commands)
  1087. if(temp.getName().equalsIgnoreCase(name))
  1088. return false;
  1089. //Add the new function to the list
  1090. commands.add(new commandRef(name, com));
  1091. //exit successfully
  1092. return true;
  1093. }
  1094. //=====================================================================
  1095. //Function: registerMessage
  1096. //Input: String name: The name of the command
  1097. // String msg: The message to be displayed
  1098. // boolean admin: If the message is displayed to admins only
  1099. //Output: boolean: Whether the command was input successfully or not
  1100. //Use: Registers a command to the command list for checking later
  1101. //=====================================================================
  1102. public boolean registerMessage(String name, String msg, String clr, int args, boolean admin)
  1103. {
  1104. //Check to make sure the command doesn't already exist
  1105. for(command temp : commands)
  1106. if(temp.getName().equalsIgnoreCase(name))
  1107. return false;
  1108. //Add the new function to the list
  1109. commands.add(new commandAnnounce(name, msg, clr, args, admin));
  1110. //exit successfully
  1111. return true;
  1112. }
  1113. //=====================================================================
  1114. //Function: call
  1115. //Input: String name: The name of the command to be run
  1116. //Output: boolean: If the command was called successfully
  1117. //Use: Attempts to call a command
  1118. //=====================================================================
  1119. public int call(String name, Player player, String[] arg){
  1120. //Search for the command
  1121. for(command cmd : commands)
  1122. {
  1123. //When found
  1124. if(cmd.getName().equalsIgnoreCase(name))
  1125. {
  1126. try {
  1127. //Call the command and return results
  1128. return cmd.call(player, arg);
  1129. } catch (SecurityException e) {
  1130. log.log(Level.SEVERE, "Exception while running command", e);
  1131. } catch (IllegalArgumentException e) {
  1132. log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e);
  1133. return EXIT_FAIL;
  1134. }
  1135. }
  1136. }
  1137. //Something went wrong
  1138. return EXIT_FAIL;
  1139. }
  1140. //=====================================================================
  1141. //Class: command
  1142. //Use: The specific command
  1143. //Author: cerevisiae
  1144. //=====================================================================
  1145. private class command
  1146. {
  1147. private String commandName;
  1148. private String function;
  1149. //=====================================================================
  1150. //Function: command
  1151. //Input: None
  1152. //Output: None
  1153. //Use: Initialize the command
  1154. //=====================================================================
  1155. public command(String name, String func){
  1156. commandName = name;
  1157. function = func;
  1158. }
  1159. //=====================================================================
  1160. //Function: getName
  1161. //Input: None
  1162. //Output: String: The command name
  1163. //Use: Returns the command name
  1164. //=====================================================================
  1165. public String getName(){return commandName;}
  1166. //=====================================================================
  1167. //Function: call
  1168. //Input: String[] arg: The arguments for the command
  1169. //Output: boolean: If the command was called successfully
  1170. //Use: Attempts to call the command
  1171. //=====================================================================
  1172. int call(Player player, String[] arg)
  1173. {
  1174. Method m;
  1175. try {
  1176. m = vMinecraftCommands.class.getMethod(function, Player.class, String[].class);
  1177. m.setAccessible(true);
  1178. return (Integer) m.invoke(null, player, arg);
  1179. } catch (SecurityException e) {
  1180. e.printStackTrace();
  1181. } catch (NoSuchMethodException e) {
  1182. e.printStackTrace();
  1183. } catch (IllegalArgumentException e) {
  1184. e.printStackTrace();
  1185. } catch (IllegalAccessException e) {
  1186. e.printStackTrace();
  1187. } catch (InvocationTargetException e) {
  1188. e.printStackTrace();
  1189. }
  1190. return 1;
  1191. }
  1192. }
  1193. //=====================================================================
  1194. //Class: commandRef
  1195. //Use: A command referencing another command
  1196. //Author: cerevisiae
  1197. //=====================================================================
  1198. private class commandRef extends command
  1199. {
  1200. private String reference;
  1201. private String[] args;
  1202. //=====================================================================
  1203. //Function: command
  1204. //Input: String name: The command name
  1205. // String com: The command to run
  1206. //Output: None
  1207. //Use: Initialize the command
  1208. //=====================================================================
  1209. public commandRef(String name, String com){
  1210. super(name, "");
  1211. //Get the reference name
  1212. String[]temp = com.split(" ");
  1213. reference = temp[0];
  1214. //Get the arguments
  1215. args = new String[temp.length - 1];
  1216. System.arraycopy(temp, 1, args, 0, temp.length - 1);
  1217. }
  1218. //=====================================================================
  1219. //Function: call
  1220. //Input: String[] arg: The arguments for the command
  1221. //Output: boolean: If the command was called successfully
  1222. //Use: Attempts to call the command
  1223. //=====================================================================
  1224. int call(Player player, String[] arg)
  1225. {
  1226. String[] temp = new String[0];
  1227. int lastSet = 0,
  1228. argCount = 0;
  1229. //If there are args set with the function
  1230. if(args != null && args.length > 0) {
  1231. temp = new String[args.length];
  1232. System.arraycopy(args, 0, temp, 0, args.length);
  1233. //Insert the arguments into the pre-set arguments
  1234. for(String argument : temp)
  1235. {
  1236. if(argument.startsWith("%") && argument.length() > 1)
  1237. {
  1238. int argNum = Integer.parseInt(argument.substring(1));
  1239. if( argNum < arg.length )
  1240. {
  1241. temp[lastSet] = arg[argNum];
  1242. argCount++;
  1243. }
  1244. }
  1245. lastSet++;
  1246. }
  1247. }
  1248. //If there are args being input
  1249. if(arg.length > 0) {
  1250. //Append the rest of the arguments to the argument array
  1251. if(lastSet < temp.length + arg.length - argCount)
  1252. {
  1253. String[] temp2 = new String[temp.length + arg.length - argCount];
  1254. System.arraycopy(temp, 0, temp2, 0, temp.length);
  1255. System.arraycopy(arg, argCount, temp2,
  1256. temp.length, arg.length - argCount);
  1257. temp = temp2;
  1258. }
  1259. log.log(Level.INFO, reference + " " + etc.combineSplit(0, temp, " "));
  1260. //Call the referenced command
  1261. player.command(reference + " " + etc.combineSplit(0, temp, " "));
  1262. } else
  1263. player.command(reference);
  1264. return EXIT_SUCCESS;
  1265. }
  1266. }
  1267. //=====================================================================
  1268. //Class: commandAnnounce
  1269. //Use: Announces when a command is used
  1270. //Author: cerevisiae
  1271. //=====================================================================
  1272. private class commandAnnounce extends command
  1273. {
  1274. private String message;
  1275. private boolean admin;
  1276. private int minArgs;
  1277. private String color;
  1278. //=====================================================================
  1279. //Function: commandAnnounce
  1280. //Input: String name: The command name
  1281. // String msg: The message to announce
  1282. //Output: None
  1283. //Use: Initialize the command
  1284. //=====================================================================
  1285. public commandAnnounce(String name, String msg, String clr, int args, boolean admn){
  1286. super(name, "");
  1287. message = msg;
  1288. admin = admn;
  1289. minArgs = args;
  1290. color = clr;
  1291. }
  1292. //=====================================================================
  1293. //Function: call
  1294. //Input: String[] arg: The arguments for the command
  1295. //Output: boolean: If the command was called successfully
  1296. //Use: Attempts to call the command
  1297. //=====================================================================
  1298. int call(Player player, String[] arg)
  1299. {
  1300. //Make sure the player can use the command first
  1301. if(!player.canUseCommand(super.commandName)) return EXIT_FAIL;
  1302. //Make sure the command is long enough to fire
  1303. if(minArgs < arg.length)
  1304. return EXIT_FAIL;
  1305. if(vMinecraftSettings.getInstance().globalmessages())
  1306. {
  1307. //Split up the message
  1308. String[] temp = message.split(" ");
  1309. //Insert the arguments into the message
  1310. int i = 0;
  1311. for(String argument : temp)
  1312. {
  1313. if(argument.startsWith("%") && argument.length() > 1)
  1314. {
  1315. char position = argument.charAt(1);
  1316. //Replace %p with the player name
  1317. if(position == 'p')
  1318. temp[i] = vMinecraftChat.getName(player) + color;
  1319. else if( Character.isDigit(position) && Character.getNumericValue(position) < arg.length )
  1320. {
  1321. //If the argument is specified to be a player insert it if the
  1322. //player is found or exit if they aren't
  1323. if(argument.length() > 2 && argument.charAt(2) == 'p')
  1324. {
  1325. Player targetName = etc.getServer().matchPlayer(arg[Character.getNumericValue(position)]);
  1326. if(targetName != null)
  1327. temp[i] = vMinecraftChat.getName(targetName) + color;
  1328. else
  1329. return EXIT_FAIL;
  1330. }
  1331. //Replace %# with the argument at position #
  1332. else
  1333. temp[i] = arg[Character.getNumericValue(position)];
  1334. }
  1335. }
  1336. i++;
  1337. }
  1338. message = etc.combineSplit(0, temp, " ");
  1339. //If it's an admin message only
  1340. if(admin)
  1341. {
  1342. for (Player p: etc.getServer().getPlayerList()) {
  1343. //If p is not null
  1344. if (p != null) {
  1345. //And if p is an admin or has access to adminchat send message
  1346. if (p.isAdmin()) {
  1347. vMinecraftChat.sendMessage(player, p, color + message);
  1348. }
  1349. }
  1350. }
  1351. } else
  1352. vMinecraftChat.gmsg(player, message);
  1353. }
  1354. return EXIT_FAIL;
  1355. }
  1356. }
  1357. }