vMinecraftCommands.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. import java.io.IOException;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.lang.reflect.Method;
  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;
  6. //=====================================================================
  7. //Class: vMinecraftCommands
  8. //Use: Encapsulates all commands added by this mod
  9. //Author: nos, trapalice, cerevisiae
  10. //=====================================================================
  11. public class vMinecraftCommands{
  12. //Log output
  13. protected static final Logger log = Logger.getLogger("Minecraft");
  14. static final int EXIT_FAIL = 0,
  15. EXIT_SUCCESS = 1,
  16. EXIT_CONTINUE = 2;
  17. //The list of commands for vMinecraft
  18. public static commandList cl = new commandList();
  19. //=====================================================================
  20. //Function: loadCommands
  21. //Input: None
  22. //Output: None
  23. //Use: Imports all the commands into the command list
  24. //=====================================================================
  25. public static void loadCommands(){
  26. //If we had commands we would add them here.
  27. cl.register("/tp", "teleport");
  28. cl.register("/masstp", "masstp", "Teleports those with lower permissions to you");
  29. cl.register("/reload", "reload");
  30. cl.register("/rules", "rules", "Displays the rules");
  31. cl.register("/fabulous", "fabulous", "makes text SUUUPER");
  32. cl.register("/whois", "whois", "/whois [user]");
  33. cl.register("/who", "who");
  34. cl.register("/say", "say");
  35. cl.register("/slay", "slay", "Kill target player");
  36. cl.register("/ezmodo", "invuln", "Toggle invulnerability");
  37. cl.register("/ezlist", "ezlist", "List invulnerable players");
  38. cl.register("/heal", "heal", "heal yourself or other players");
  39. cl.register("/suicide", "suicide", "kill yourself... you loser");
  40. cl.register("/a", "adminChatToggle", "toggle admin chat for every message");
  41. cl.register("/modify", "modifySplit");
  42. cl.register("/me", "me");
  43. cl.register("/msg", "message");
  44. cl.register("/reply", "reply");
  45. cl.registerAlias("/playerlist", "/who");
  46. cl.registerAlias("/r", "/reply");
  47. cl.registerAlias("/w", "/msg");
  48. cl.registerAlias("/wrists", "/suicide");
  49. cl.registerAlias("/ci", "/clearinventory");
  50. }
  51. //=====================================================================
  52. //Function: me (/me)
  53. //Input: Player player: The player using the command
  54. //Output: int: Exit Code
  55. //Use: The player uses this to emote, but now its colorful.
  56. //=====================================================================
  57. public static int me(Player player, String[] args)
  58. {
  59. String str = etc.combineSplit(0, args, " ");
  60. if (args.length < 1) {return EXIT_FAIL;}
  61. vMinecraftChat.emote(player, str);
  62. return EXIT_SUCCESS;
  63. }
  64. //=====================================================================
  65. //Function: message (/msg, /w, /whisper)
  66. //Input: Player player: The player using the command
  67. //Output: int: Exit Code
  68. //Use: Send a message to a player
  69. //=====================================================================
  70. public static int message(Player player, String[] args)
  71. {
  72. String msg = etc.combineSplit(1, args, " ");
  73. Player toPlayer = etc.getServer().matchPlayer(args[0]);
  74. if (args.length < 1) {
  75. return EXIT_FAIL;
  76. } else if (toPlayer != null) {
  77. //Send the message to the targeted player and the sender
  78. vMinecraftChat.sendMessage(player, toPlayer,
  79. Colors.LightGreen + "[" + Colors.White + "From:"
  80. + vMinecraftChat.getName(player) + Colors.LightGreen + "] "
  81. + Colors.White + msg);
  82. vMinecraftChat.sendMessage(player, player,
  83. Colors.LightGreen + "[" + Colors.White + "To:"
  84. + vMinecraftChat.getName(toPlayer) + Colors.LightGreen + "] "
  85. + Colors.White + msg);
  86. //Set the last massager for each player
  87. vMinecraftUsers.players.findProfile(player).setMessage(toPlayer);
  88. vMinecraftUsers.players.findProfile(toPlayer).setMessage(player);
  89. } else {
  90. vMinecraftChat.sendMessage(player, player, Colors.Red
  91. + "No player by the name of " + args[0] + " could be found.");
  92. }
  93. return EXIT_SUCCESS;
  94. }
  95. //=====================================================================
  96. //Function: reply (/r, /reply)
  97. //Input: Player player: The player using the command
  98. //Output: int: Exit Code
  99. //Use: Send a message to a player
  100. //=====================================================================
  101. public static int reply(Player player, String[] args)
  102. {
  103. Player toPlayer = vMinecraftUsers.players.findProfile(player).getMessage();
  104. if (toPlayer != null) {
  105. String msg = etc.combineSplit(1, args, " ");
  106. //Send the message to the targeted player and the sender
  107. vMinecraftChat.sendMessage(player, toPlayer,
  108. Colors.LightGreen + "[" + Colors.White + "From:"
  109. + vMinecraftChat.getName(player) + Colors.LightGreen + "] " + msg);
  110. vMinecraftChat.sendMessage(player, player,
  111. Colors.LightGreen + "[" + Colors.White + "To:"
  112. + vMinecraftChat.getName(toPlayer) + Colors.LightGreen + "] " + msg);
  113. //Set the last messager for each player
  114. vMinecraftUsers.players.findProfile(player).setMessage(toPlayer);
  115. vMinecraftUsers.players.findProfile(toPlayer).setMessage(player);
  116. } else {
  117. vMinecraftChat.sendMessage(player, player,
  118. Colors.Red + "That person is no longer logged in.");
  119. }
  120. return EXIT_SUCCESS;
  121. }
  122. //=====================================================================
  123. //Function: adminChatToggle (/a)
  124. //Input: Player player: The player using the command
  125. //Output: int: Exit Code
  126. //Use: Toggles the player into admin chat. Every message they
  127. // send will be piped to admin chat.
  128. //=====================================================================
  129. public static int adminChatToggle(Player player, String[] args)
  130. {
  131. if(vMinecraftSettings.getInstance().adminChatToggle())
  132. {
  133. //If the player is already toggled for admin chat, remove them
  134. if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) {
  135. player.sendMessage(Colors.Red + "Admin Chat Toggle = off");
  136. vMinecraftSettings.getInstance().removeAdminToggled(player.getName());
  137. //Otherwise include them
  138. } else {
  139. player.sendMessage(Colors.Blue + "Admin Chat Toggled on");
  140. vMinecraftSettings.getInstance().addAdminToggled(player.getName());
  141. }
  142. return EXIT_SUCCESS;
  143. }
  144. return EXIT_FAIL;
  145. }
  146. //=====================================================================
  147. //Function: heal (/heal)
  148. //Input: Player player: The player using the command
  149. // String[] args: The arguments for the command. Should be a
  150. // player name or blank
  151. //Output: int: Exit Code
  152. //Use: Heals yourself or a specified player.
  153. //=====================================================================
  154. public static int heal(Player player, String[] args)
  155. {
  156. if(vMinecraftSettings.getInstance().cmdHeal())
  157. {
  158. //If a target wasn't specified, heal the user.
  159. if (args.length < 1){
  160. player.setHealth(20);
  161. player.sendMessage("Your health is restored");
  162. //If a target was specified, try to find them and then heal them
  163. //Otherwise report the error
  164. } else if (args.length > 0){
  165. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  166. if (playerTarget != null){
  167. playerTarget.setHealth(20);
  168. player.sendMessage(Colors.Blue + "You have healed " + vMinecraftChat.getName(playerTarget));
  169. playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vMinecraftChat.getName(player));
  170. }
  171. else if (playerTarget == null){
  172. player.sendMessage(Colors.Rose + "Couldn't find that player");
  173. }
  174. }
  175. return EXIT_SUCCESS;
  176. }
  177. return EXIT_FAIL;
  178. }
  179. //=====================================================================
  180. //Function: suicide (/suicide, /wrists)
  181. //Input: Player player: The player using the command
  182. // String[] args: Ignored
  183. //Output: int: Exit Code
  184. //Use: Kills yourself
  185. //=====================================================================
  186. public static int suicide(Player player, String[] args)
  187. {
  188. if(vMinecraftSettings.getInstance().cmdSuicide())
  189. {
  190. //Set your health to 0. Not much to it.
  191. player.setHealth(0);
  192. return EXIT_SUCCESS;
  193. }
  194. return EXIT_FAIL;
  195. }
  196. //=====================================================================
  197. //Function: teleport (/tp)
  198. //Input: Player player: The player using the command
  199. // String[] args: The arguments for the command. Should be a
  200. // player name
  201. //Output: int: Exit Code
  202. //Use: Teleports the user to another player
  203. //=====================================================================
  204. public static int teleport(Player player, String[] args)
  205. {
  206. //Get if the command is enabled
  207. if(vMinecraftSettings.getInstance().cmdTp())
  208. {
  209. //Make sure a player has been specified and return an error if not
  210. if (args.length < 1) {
  211. player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]");
  212. } else {
  213. //Find the player by name
  214. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  215. //Target player isn't found
  216. if(playerTarget == null)
  217. player.sendMessage(Colors.Rose + "Can't find user "
  218. + args[0] + ".");
  219. //If it's you, return witty message
  220. else if (player.getName().equalsIgnoreCase(args[0]))
  221. player.sendMessage(Colors.Rose + "You're already here!");
  222. //If the player is higher rank than you, inform the user
  223. else if (!player.hasControlOver(playerTarget))
  224. player.sendMessage(Colors.Red +
  225. "That player has higher permissions than you.");
  226. //If the player exists transport the user to the player
  227. else {
  228. log.log(Level.INFO, player.getName() + " teleported to " +
  229. playerTarget.getName());
  230. player.teleportTo(playerTarget);
  231. //Otherwise inform the user that the player doesn't exist
  232. }
  233. }
  234. return EXIT_SUCCESS;
  235. }
  236. return EXIT_FAIL;
  237. }
  238. //=====================================================================
  239. //Function: masstp (/masstp)
  240. //Input: Player player: The player using the command
  241. // String[] args: Should be empty or is ignored
  242. //Output: int: Exit Code
  243. //Use: Teleports all players to the user
  244. //=====================================================================
  245. public static int masstp(Player player, String[] args)
  246. {
  247. //If the command is enabled
  248. if(vMinecraftSettings.getInstance().cmdMasstp()) {
  249. //Go through all players and move them to the user
  250. for (Player p : etc.getServer().getPlayerList()) {
  251. if (!p.hasControlOver(player)) {
  252. p.teleportTo(player);
  253. }
  254. }
  255. //Inform the user that the command has executed successfully
  256. player.sendMessage(Colors.Blue+"Summoning successful.");
  257. return EXIT_SUCCESS;
  258. }
  259. return EXIT_FAIL;
  260. }
  261. //=====================================================================
  262. //Function: tphere (/tphere)
  263. //Input: Player player: The player using the command
  264. // String[] args: The arguments for the command. Should be a
  265. // player name
  266. //Output: int: Exit Code
  267. //Use: Teleports the user to another player
  268. //=====================================================================
  269. public static int tphere(Player player, String[] args)
  270. {
  271. //Check if the command is enabled.
  272. if (vMinecraftSettings.getInstance().cmdTphere()) {
  273. //Make sure a player is specified
  274. if (args.length < 1) {
  275. player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]");
  276. } else {
  277. //Get the player by name
  278. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  279. //If the target doesn't exist
  280. if(playerTarget == null)
  281. player.sendMessage(Colors.Rose + "Can't find user " + args[0] + ".");
  282. //If the player has a higher rank than the user, return error
  283. else if (!player.hasControlOver(playerTarget))
  284. player.sendMessage(Colors.Red + "That player has higher permissions than you.");
  285. //If the user teleports themselves, mock them
  286. else if (player.getName().equalsIgnoreCase(args[0]))
  287. player.sendMessage(Colors.Rose + "Wow look at that! You teleported yourself to yourself!");
  288. //If the target exists, teleport them to the user
  289. else {
  290. log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self.");
  291. playerTarget.teleportTo(player);
  292. }
  293. }
  294. return EXIT_SUCCESS;
  295. }
  296. return EXIT_FAIL;
  297. }
  298. //=====================================================================
  299. //Function: reload (/reload)
  300. //Input: Player player: The player using the command
  301. // String[] args: Ignored
  302. //Output: int: Exit Code
  303. //Use: Reloads the settings for vMinecraft
  304. //=====================================================================
  305. public static int reload(Player player, String[] args)
  306. {
  307. vMinecraftSettings.getInstance().loadSettings();
  308. return EXIT_FAIL;
  309. }
  310. //=====================================================================
  311. //Function: rules (/rules)
  312. //Input: Player player: The player using the command
  313. // String[] args: Ignored
  314. //Output: int: Exit Code
  315. //Use: Lists the rules
  316. //=====================================================================
  317. public static int rules(Player player, String[] args)
  318. {
  319. //If the rules exist
  320. if(vMinecraftSettings.getInstance().cmdRules()
  321. && vMinecraftSettings.getInstance().getRules().length > 0) {
  322. //Apply QuakeCode Colors to the rules
  323. String[] rules = vMinecraftChat.applyColors(
  324. vMinecraftSettings.getInstance().getRules());
  325. //Display them
  326. for (String str : rules ) {
  327. if(!str.isEmpty())
  328. player.sendMessage(Colors.Blue + str);
  329. else
  330. player.sendMessage(Colors.Blue + "!!!The Rules Have Not Been Set!!!");
  331. }
  332. return EXIT_SUCCESS;
  333. }
  334. return EXIT_FAIL;
  335. }
  336. //=====================================================================
  337. //Function: fabulous (/fabulous)
  338. //Input: Player player: The player using the command
  339. // String[] args: The message to apply the effect to
  340. //Output: int: Exit Code
  341. //Use: Makes the text rainbow colored
  342. //=====================================================================
  343. public static int fabulous(Player player, String[] args)
  344. {
  345. //If the command is enabled
  346. if(vMinecraftSettings.getInstance().cmdFabulous()) {
  347. //Format the name
  348. String playerName = Colors.White + "<"
  349. + vMinecraftChat.getName(player) + Colors.White +"> ";
  350. //Make sure a message has been specified
  351. if (args.length < 1) {return EXIT_FAIL;}
  352. String str = " ";
  353. //Merge the message again
  354. str = etc.combineSplit(0, args, " ");
  355. //Output for server
  356. log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  357. //Prepend the player name and cut into lines.
  358. vMinecraftChat.gmsg(player, playerName + vMinecraftChat.rainbow(str));
  359. return EXIT_SUCCESS;
  360. }
  361. return EXIT_FAIL;
  362. }
  363. //=====================================================================
  364. //Function: whois (/whois)
  365. //Input: Player player: The player using the command
  366. // String[] args: The player to find info on
  367. //Output: int: Exit Code
  368. //Use: Displays information about the player specified
  369. //=====================================================================
  370. public static int whois(Player player, String[] args)
  371. {
  372. //If the command is enabled
  373. if (vMinecraftSettings.getInstance().cmdWhoIs()) {
  374. //If a player is specified
  375. if (args.length < 1)
  376. player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  377. else {
  378. //Get the player by name
  379. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  380. //If the player exists
  381. if (playerTarget != null){
  382. //Displaying the information
  383. player.sendMessage(Colors.Blue + "Whois results for " +
  384. vMinecraftChat.getName(playerTarget));
  385. //Group
  386. for(String group: playerTarget.getGroups())
  387. player.sendMessage(Colors.Blue + "Groups: " + group);
  388. //Admin
  389. player.sendMessage(Colors.Blue+"Admin: " +
  390. String.valueOf(playerTarget.isAdmin()));
  391. //IP
  392. player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP());
  393. //Restrictions
  394. player.sendMessage(Colors.Blue+"Can ignore restrictions: " +
  395. String.valueOf(playerTarget.canIgnoreRestrictions()));
  396. //Give the user an error if the player doesn't exist
  397. } else {
  398. player.sendMessage(Colors.Rose+"Player not found.");
  399. }
  400. }
  401. return EXIT_SUCCESS;
  402. }
  403. return EXIT_SUCCESS;
  404. }
  405. //=====================================================================
  406. //Function: who (/who)
  407. //Input: Player player: The player using the command
  408. // String[] args: Ignored
  409. //Output: int: Exit Code
  410. //Use: Displays the connected players
  411. //=====================================================================
  412. public static int who(Player player, String[] args)
  413. {
  414. //If the command is enabled
  415. if (vMinecraftSettings.getInstance().cmdWho()) {
  416. //Loop through all players counting them and adding to the list
  417. int count=0;
  418. String tempList = "";
  419. for( Player p : etc.getServer().getPlayerList())
  420. {
  421. if(p != null){
  422. if(count == 0)
  423. tempList += vMinecraftChat.getName(p);
  424. else
  425. tempList += Colors.White + ", " + vMinecraftChat.getName(p);
  426. count++;
  427. }
  428. }
  429. //Get the max players from the config
  430. PropertiesFile server = new PropertiesFile("server.properties");
  431. try {
  432. server.load();
  433. } catch (IOException e) {
  434. e.printStackTrace();
  435. }
  436. int maxPlayers = server.getInt("max-players");
  437. //Output the player list
  438. vMinecraftChat.sendMessage(player, player, Colors.Rose + "Player List ("
  439. + count + "/" + maxPlayers +"): " + tempList);
  440. return EXIT_SUCCESS;
  441. }
  442. return EXIT_FAIL;
  443. }
  444. //=====================================================================
  445. //Function: say (/say)
  446. //Input: Player player: The player using the command
  447. // String[] args: The message to apply the effect to
  448. //Output: int: Exit Code
  449. //Use: Announces the message to all players
  450. //=====================================================================
  451. public static int say(Player player, String[] args)
  452. {
  453. //If the command is enabled
  454. if (vMinecraftSettings.getInstance().cmdSay()) {
  455. //Make sure a message is supplied or output an error
  456. if (args.length < 1) {
  457. player.sendMessage(Colors.Rose + "Usage is /say [message]");
  458. }
  459. //Display the message globally
  460. vMinecraftChat.gmsg(player, Colors.Yellow + etc.combineSplit(0, args, " "));
  461. return EXIT_SUCCESS;
  462. }
  463. return EXIT_FAIL;
  464. }
  465. //=====================================================================
  466. //Function: slay (/slay)
  467. //Input: Player player: The player using the command
  468. // String[] args: The target for the command
  469. //Output: int: Exit Code
  470. //Use: Kill the target player
  471. //=====================================================================
  472. public static int slay(Player player, String[] args)
  473. {
  474. //Check if the command is enabled
  475. if(vMinecraftSettings.getInstance().cmdEzModo()) {
  476. //Get the player by name
  477. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  478. //If the player doesn't exist don't run
  479. if(playerTarget == null)
  480. return EXIT_FAIL;
  481. //If the player isn't invulnerable kill them
  482. if (!vMinecraftSettings.getInstance().isEzModo(playerTarget.getName())) {
  483. playerTarget.setHealth(0);
  484. vMinecraftChat.gmsg(player, vMinecraftChat.getName(player)
  485. + Colors.LightBlue + " has slain "
  486. + vMinecraftChat.getName(playerTarget));
  487. //Otherwise output error to the user
  488. } else {
  489. player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha");
  490. }
  491. return EXIT_SUCCESS;
  492. }
  493. return EXIT_FAIL;
  494. }
  495. //=====================================================================
  496. //Function: invuln (/ezmodo)
  497. //Input: Player player: The player using the command
  498. // String[] args: The target for the command
  499. //Output: int: Exit Code
  500. //Use: Kill the target player
  501. //=====================================================================
  502. public static int invuln(Player player, String[] args)
  503. {
  504. //If the command is enabled
  505. if (vMinecraftSettings.getInstance().cmdEzModo()) {
  506. //If the player is already invulnerable, turn ezmodo off.
  507. if (vMinecraftSettings.getInstance().isEzModo(player.getName())) {
  508. player.sendMessage(Colors.Red + "ezmodo = off");
  509. vMinecraftSettings.getInstance().removeEzModo(player.getName());
  510. //Otherwise make them invulnerable
  511. } else {
  512. player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?");
  513. player.sendMessage(Colors.Rose + "kimo-i");
  514. player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru no wa shougakusei made dayo ne");
  515. player.sendMessage(Colors.Red + "**Laughter**");
  516. vMinecraftSettings.getInstance().addEzModo(player.getName());
  517. }
  518. return EXIT_SUCCESS;
  519. }
  520. return EXIT_FAIL;
  521. }
  522. //=====================================================================
  523. //Function: ezlist (/ezlist)
  524. //Input: Player player: The player using the command
  525. // String[] args: Ignored
  526. //Output: int: Exit Code
  527. //Use: List all invulnerable players
  528. //=====================================================================
  529. public static int ezlist(Player player, String[] args)
  530. {
  531. //If the feature is enabled list the players
  532. if(vMinecraftSettings.getInstance().cmdEzModo()) {
  533. player.sendMessage("Ezmodo: " + vMinecraftSettings.getInstance().ezModoList());
  534. return EXIT_SUCCESS;
  535. }
  536. return EXIT_FAIL;
  537. }
  538. //=====================================================================
  539. //Function: modifySplit (/modify)
  540. //Input: Player player: The player using the command
  541. // String[] args: Player, Command, Arguments
  542. //Output: int: Exit Code
  543. //Use: List all invulnerable players
  544. //=====================================================================
  545. public static int modifySplit(Player player, String[] args)
  546. {
  547. //Exploit fix for people giving themselves commands
  548. if(args[2].equals("commands")){
  549. return EXIT_FAIL;
  550. }
  551. return EXIT_CONTINUE;
  552. }
  553. //=====================================================================
  554. //Function: Time Reverse
  555. //Input: long time: The time to reverse to.
  556. //Output: int: Exit Code
  557. //Use: List all invulnerable players
  558. //=====================================================================
  559. public static int timeReverse(long tarTime)
  560. {
  561. long curTime = etc.getServer().getRelativeTime();
  562. //if(cur)
  563. return EXIT_SUCCESS;
  564. }
  565. //=====================================================================
  566. //Function: privateMessage(/msg)
  567. //Input: long time: The time to reverse to.
  568. //Output: int: Exit Code
  569. //Use: List all invulnerable players
  570. //=====================================================================
  571. public static int privateMessage(Player player, String[] message)
  572. {
  573. long curTime = etc.getServer().getRelativeTime();
  574. //if(cur)
  575. return EXIT_SUCCESS;
  576. }
  577. }
  578. //=====================================================================
  579. //Class: commandList
  580. //Use: The list of commands that will be checked for
  581. //Author: cerevisiae
  582. //=====================================================================
  583. class commandList {
  584. command[] commands;
  585. protected static final Logger log = Logger.getLogger("Minecraft");
  586. static final int EXIT_FAIL = 0,
  587. EXIT_SUCCESS = 1,
  588. EXIT_CONTINUE = 2;
  589. //=====================================================================
  590. //Function: commandList
  591. //Input: None
  592. //Output: None
  593. //Use: Initialize the array of commands
  594. //=====================================================================
  595. public commandList(){
  596. commands = new command[0];
  597. }
  598. //=====================================================================
  599. //Function: register
  600. //Input: String name: The name of the command
  601. // String func: The function to be called
  602. //Output: boolean: Whether the command was input successfully or not
  603. //Use: Registers a command to the command list for checking later
  604. //=====================================================================
  605. public boolean register(String name, String func){
  606. //If the command list isn't empty
  607. if(commands.length > 0)
  608. {
  609. //Check to make sure the command doesn't already exist
  610. for(int i = 0; i < commands.length; i++)
  611. if(commands[i].getName().equalsIgnoreCase(name))
  612. return false;
  613. //Create a new temp array
  614. command[] temp = new command[commands.length + 1];
  615. //Copy the old command list over
  616. System.arraycopy(commands, 0, temp, 0, commands.length);
  617. //Set commands to equal the new array
  618. commands = temp;
  619. } else {
  620. commands = new command[1];
  621. }
  622. //Add the new function to the list
  623. commands[commands.length - 1] = new command(name, func);
  624. //exit successfully
  625. return true;
  626. }
  627. //=====================================================================
  628. //Function: register
  629. //Input: String name: The name of the command
  630. // String func: The function to be called
  631. // String info: The information for the command to put in help
  632. //Output: boolean: Whether the command was input successfully or not
  633. //Use: Registers a command to the command list for checking later
  634. //=====================================================================
  635. public boolean register(String name, String func, String info){
  636. //Add to the /help list
  637. etc.getInstance().addCommand(name, info);
  638. //Finish registering
  639. return register(name, func);
  640. }
  641. //=====================================================================
  642. //Function: register
  643. //Input: String name: The name of the command
  644. // String func: The function to be called
  645. //Output: boolean: Whether the command was input successfully or not
  646. //Use: Registers a command to the command list for checking later
  647. //=====================================================================
  648. public boolean registerAlias(String name, String com, String[] args){
  649. //If the command list isn't empty
  650. if(commands.length > 0)
  651. {
  652. //Check to make sure the command doesn't already exist
  653. for(int i = 0; i < commands.length; i++)
  654. if(commands[i].getName().equalsIgnoreCase(name))
  655. return false;
  656. //Create a new temp array
  657. command[] temp = new command[commands.length + 1];
  658. //Copy the old command list over
  659. System.arraycopy(commands, 0, temp, 0, commands.length);
  660. //Set commands to equal the new array
  661. commands = temp;
  662. } else {
  663. commands = new command[1];
  664. }
  665. //Add the new function to the list
  666. commands[commands.length - 1] = new commandRef(name, com, args);
  667. //exit successfully
  668. return true;
  669. }
  670. //=====================================================================
  671. //Function: register
  672. //Input: String name: The name of the command
  673. // String func: The function to be called
  674. //Output: boolean: Whether the command was input successfully or not
  675. //Use: Registers a command to the command list for checking later
  676. //=====================================================================
  677. public boolean registerAlias(String name, String com){
  678. //If the command list isn't empty
  679. if(commands.length > 0)
  680. {
  681. //Check to make sure the command doesn't already exist
  682. for(int i = 0; i < commands.length; i++)
  683. if(commands[i].getName().equalsIgnoreCase(name))
  684. return false;
  685. //Create a new temp array
  686. command[] temp = new command[commands.length + 1];
  687. //Copy the old command list over
  688. System.arraycopy(commands, 0, temp, 0, commands.length);
  689. //Set commands to equal the new array
  690. commands = temp;
  691. } else {
  692. commands = new command[1];
  693. }
  694. //Add the new function to the list
  695. commands[commands.length - 1] = new commandRef(name, com);
  696. //exit successfully
  697. return true;
  698. }
  699. //=====================================================================
  700. //Function: call
  701. //Input: String name: The name of the command to be run
  702. //Output: boolean: If the command was called successfully
  703. //Use: Attempts to call a command
  704. //=====================================================================
  705. public int call(String name, Player player, String[] arg){
  706. //Make sure the user has access to the command
  707. if(!player.canUseCommand(name)) {
  708. return EXIT_FAIL;
  709. }
  710. //Search for the command
  711. for(command cmd : commands)
  712. {
  713. //When found
  714. if(cmd.getName().equalsIgnoreCase(name))
  715. {
  716. try {
  717. //Call the command and return results
  718. return cmd.call(player, arg);
  719. } catch (SecurityException e) {
  720. log.log(Level.SEVERE, "Exception while running command", e);
  721. } catch (IllegalArgumentException e) {
  722. log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e);
  723. return EXIT_FAIL;
  724. }
  725. }
  726. }
  727. //Something went wrong
  728. return EXIT_FAIL;
  729. }
  730. //=====================================================================
  731. //Class: command
  732. //Use: The specific command
  733. //Author: cerevisiae
  734. //=====================================================================
  735. private class command
  736. {
  737. private String commandName;
  738. private String function;
  739. //=====================================================================
  740. //Function: command
  741. //Input: None
  742. //Output: None
  743. //Use: Initialize the command
  744. //=====================================================================
  745. public command(String name, String func){
  746. commandName = name;
  747. function = func;
  748. }
  749. //=====================================================================
  750. //Function: getName
  751. //Input: None
  752. //Output: String: The command name
  753. //Use: Returns the command name
  754. //=====================================================================
  755. public String getName(){return commandName;}
  756. //=====================================================================
  757. //Function: call
  758. //Input: String[] arg: The arguments for the command
  759. //Output: boolean: If the command was called successfully
  760. //Use: Attempts to call the command
  761. //=====================================================================
  762. int call(Player player, String[] arg)
  763. {
  764. Method m;
  765. try {
  766. m = vMinecraftCommands.class.getMethod(function, Player.class, String[].class);
  767. m.setAccessible(true);
  768. return (Integer) m.invoke(null, player, arg);
  769. } catch (SecurityException e) {
  770. e.printStackTrace();
  771. } catch (NoSuchMethodException e) {
  772. e.printStackTrace();
  773. } catch (IllegalArgumentException e) {
  774. e.printStackTrace();
  775. } catch (IllegalAccessException e) {
  776. e.printStackTrace();
  777. } catch (InvocationTargetException e) {
  778. e.printStackTrace();
  779. }
  780. return 1;
  781. }
  782. }
  783. //=====================================================================
  784. //Class: commandRef
  785. //Use: A command referencing another command
  786. //Author: cerevisiae
  787. //=====================================================================
  788. private class commandRef extends command
  789. {
  790. private String reference;
  791. private String[] args;
  792. //=====================================================================
  793. //Function: command
  794. //Input: String name: The command name
  795. // String com: The command to run
  796. // String[] arg: the arguments to apply
  797. //Output: None
  798. //Use: Initialize the command
  799. //=====================================================================
  800. public commandRef(String name, String com, String[] arg){
  801. super(name, "");
  802. reference = com;
  803. args = arg;
  804. }
  805. //=====================================================================
  806. //Function: command
  807. //Input: String name: The command name
  808. // String com: The command to run
  809. //Output: None
  810. //Use: Initialize the command
  811. //=====================================================================
  812. public commandRef(String name, String com){
  813. super(name, "");
  814. reference = com;
  815. args = null;
  816. }
  817. //=====================================================================
  818. //Function: call
  819. //Input: String[] arg: The arguments for the command
  820. //Output: boolean: If the command was called successfully
  821. //Use: Attempts to call the command
  822. //=====================================================================
  823. int call(Player player, String[] arg)
  824. {
  825. if(args != null) {
  826. String[] temp = new String[args.length];
  827. System.arraycopy(args, 0, temp, 0, args.length);
  828. //Insert the arguments into the pre-set arguments
  829. int lastSet = 0,
  830. argCount = 0;
  831. for(String argument : temp)
  832. {
  833. if(argument.startsWith("%"))
  834. {
  835. int argNum = Integer.parseInt(argument.substring(1));
  836. if( argNum < arg.length )
  837. {
  838. temp[lastSet] = arg[argNum];
  839. argCount++;
  840. }
  841. }
  842. lastSet++;
  843. }
  844. //Append the rest of the arguments to the argument array
  845. if(lastSet < temp.length + arg.length - argCount)
  846. {
  847. String[] temp2 = new String[temp.length + arg.length - argCount];
  848. System.arraycopy(temp, 0, temp2, 0, temp.length);
  849. System.arraycopy(arg, argCount, temp2,
  850. temp.length, arg.length - argCount);
  851. temp = temp2;
  852. }
  853. //Call the referenced command
  854. player.command(reference + " " + etc.combineSplit(0, temp, " "));
  855. } else
  856. player.command(reference);
  857. return EXIT_SUCCESS;
  858. }
  859. }
  860. }