vMinecraftCommands.java 37 KB

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