vMinecraftCommands.java 65 KB

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