vMinecraftCommands.java 74 KB

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