vMinecraftCommands.java 46 KB

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