2
0

vMinecraftCommands.java 34 KB

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