vMinecraftCommands.java 54 KB

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