vMinecraftCommands.java 33 KB

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