vMinecraftCommands.java 42 KB

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