vMinecraftCommands.java 56 KB

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