vMinecraftCommands.java 45 KB

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