vMinecraftCommands.java 56 KB

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