2
0

vMinecraftCommands.java 61 KB

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