vMinecraftCommands.java 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076
  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_SUCCESS;
  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. {
  1317. myRank = 0;
  1318. }
  1319. log.log(Level.INFO, myRank + " / " + tarRank);
  1320. //Make sure they're not promoting to their rank or higher
  1321. if(myRank <= tarRank + 1)
  1322. {
  1323. vMinecraftChat.sendMessage(player, Colors.Rose + "You cannot promote someone to" +
  1324. " your rank or higher.");
  1325. return EXIT_SUCCESS;
  1326. }
  1327. tarGroups[tarPos] = ranks[tarRank + 1];
  1328. target.setGroups(tarGroups);
  1329. //Make sure the player is in the files
  1330. FlatFileSource ffs = new FlatFileSource();
  1331. if(!ffs.doesPlayerExist(target.getName()))
  1332. {
  1333. vMinecraftChat.sendMessage(player, Colors.Rose + "Adding player.");
  1334. ffs.addPlayer(target);
  1335. }
  1336. else
  1337. {
  1338. ffs.modifyPlayer(target);
  1339. }
  1340. vMinecraftChat.sendMessage(player, Colors.Rose + target.getName()
  1341. + " has been promoted to " + ranks[tarRank + 1] + ".");
  1342. vMinecraftChat.sendMessage(target, Colors.Rose + "You have been promoted to "
  1343. + ranks[tarRank + 1] + ".");
  1344. return EXIT_SUCCESS;
  1345. }
  1346. //=====================================================================
  1347. //Function: demote (/demote)
  1348. //Input: Player player: The player using the command
  1349. // String[] args: Player to promote
  1350. //Output: int: Exit Code
  1351. //Use: Attempt to promote a player one rank
  1352. //=====================================================================
  1353. public static int demote(Player player, String[] args)
  1354. {
  1355. //Check if they can demote
  1356. if(!player.canUseCommand("/demote")) return EXIT_FAIL;
  1357. //Check if they specified a player
  1358. if(args.length < 1)
  1359. {
  1360. vMinecraftChat.sendMessage(player, Colors.Rose + "Usage: /demote [Player] (Rank)");
  1361. return EXIT_SUCCESS;
  1362. }
  1363. //Try to find the player
  1364. Player target = etc.getServer().matchPlayer(args[0]);
  1365. if(target == null)
  1366. {
  1367. vMinecraftChat.sendMessage(player, Colors.Rose + "The player specified could not be found");
  1368. return EXIT_SUCCESS;
  1369. }
  1370. //Get the list of ranks
  1371. String[] ranks = vMinecraftSettings.getInstance().getRanks();
  1372. //Find the targets current rank number
  1373. String[] tarGroups = target.getGroups();
  1374. int tarRank = 0,
  1375. tarPos = 0;
  1376. boolean leave = false;
  1377. for(String rank : ranks)
  1378. {
  1379. for(String group : tarGroups)
  1380. {
  1381. if(rank.equalsIgnoreCase(group))
  1382. {
  1383. leave = true;
  1384. break;
  1385. }
  1386. else
  1387. tarPos++;
  1388. }
  1389. if(leave)
  1390. break;
  1391. tarRank++;
  1392. tarPos = 0;
  1393. }
  1394. if(!leave)
  1395. {
  1396. tarRank = 0;
  1397. tarPos = 0;
  1398. if(tarGroups != null)
  1399. {
  1400. String[] tempGroups = new String[tarGroups.length + 1];
  1401. System.arraycopy(tarGroups, 0, tempGroups, 1, tarGroups.length);
  1402. tarGroups = tempGroups;
  1403. } else
  1404. tarGroups = new String[1];
  1405. }
  1406. leave = false;
  1407. //Get the player's rank
  1408. String[] myGroups = player.getGroups();
  1409. int myRank = 0;
  1410. for(String rank : ranks)
  1411. {
  1412. for(String group : myGroups)
  1413. if(rank.equalsIgnoreCase(group))
  1414. {
  1415. leave = true;
  1416. break;
  1417. }
  1418. if(leave)
  1419. break;
  1420. myRank++;
  1421. }
  1422. if(!leave)
  1423. {
  1424. myRank = 0;
  1425. }
  1426. //Make sure they're not demoting to their rank or higher
  1427. if(myRank <= tarRank)
  1428. {
  1429. vMinecraftChat.sendMessage(player, Colors.Rose + "You cannot demote someone who is" +
  1430. " your rank or higher.");
  1431. return EXIT_SUCCESS;
  1432. }
  1433. if(tarRank - 1 < 0)
  1434. {
  1435. vMinecraftChat.sendMessage(player, Colors.Rose + target.getName() + " is already the" +
  1436. " lowest rank.");
  1437. return EXIT_SUCCESS;
  1438. }
  1439. tarGroups[tarPos] = ranks[tarRank - 1];
  1440. target.setGroups(tarGroups);
  1441. //Make sure the player is in the files
  1442. FlatFileSource ffs = new FlatFileSource();
  1443. if(!ffs.doesPlayerExist(target.getName()))
  1444. {
  1445. vMinecraftChat.sendMessage(player, Colors.Rose + "Adding player.");
  1446. ffs.addPlayer(target);
  1447. }
  1448. else
  1449. {
  1450. ffs.modifyPlayer(target);
  1451. }
  1452. vMinecraftChat.sendMessage(player, Colors.Rose + target.getName()
  1453. + " has been demoted to " + ranks[tarRank - 1] + ".");
  1454. vMinecraftChat.sendMessage(target, Colors.Rose + "You have been demoted to "
  1455. + ranks[tarRank - 1] + ".");
  1456. return EXIT_SUCCESS;
  1457. }
  1458. }
  1459. //=====================================================================
  1460. //Class: commandList
  1461. //Use: The list of commands that will be checked for
  1462. //Author: cerevisiae
  1463. //=====================================================================
  1464. class commandList {
  1465. ArrayList<command> commands;
  1466. protected static final Logger log = Logger.getLogger("Minecraft");
  1467. static final int EXIT_FAIL = 0,
  1468. EXIT_SUCCESS = 1,
  1469. EXIT_CONTINUE = 2;
  1470. //=====================================================================
  1471. //Function: commandList
  1472. //Input: None
  1473. //Output: None
  1474. //Use: Initialize the array of commands
  1475. //=====================================================================
  1476. public commandList(){
  1477. commands = new ArrayList<command>();
  1478. }
  1479. //=====================================================================
  1480. //Function: register
  1481. //Input: String name: The name of the command
  1482. // String func: The function to be called
  1483. //Output: boolean: Whether the command was input successfully or not
  1484. //Use: Registers a command to the command list for checking later
  1485. //=====================================================================
  1486. public boolean register(String name, String func)
  1487. {
  1488. //Check to make sure the command doesn't already exist
  1489. for(command temp : commands)
  1490. if(temp.getName().equalsIgnoreCase(name))
  1491. return false;
  1492. //Add the new function to the list
  1493. commands.add(new command(name, func));
  1494. //exit successfully
  1495. return true;
  1496. }
  1497. //=====================================================================
  1498. //Function: register
  1499. //Input: String name: The name of the command
  1500. // String func: The function to be called
  1501. // String info: The information for the command to put in help
  1502. //Output: boolean: Whether the command was input successfully or not
  1503. //Use: Registers a command to the command list for checking later
  1504. //=====================================================================
  1505. public boolean register(String name, String func, String info){
  1506. //Add to the /help list
  1507. etc.getInstance().addCommand(name, info);
  1508. //Finish registering
  1509. return register(name, func);
  1510. }
  1511. //=====================================================================
  1512. //Function: register
  1513. //Input: String name: The name of the command
  1514. // String func: The function to be called
  1515. //Output: boolean: Whether the command was input successfully or not
  1516. //Use: Registers a command to the command list for checking later
  1517. //=====================================================================
  1518. public boolean registerAlias(String name, String com)
  1519. {
  1520. //Check to make sure the command doesn't already exist
  1521. for(command temp : commands)
  1522. if(temp.getName().equalsIgnoreCase(name))
  1523. return false;
  1524. //Add the new function to the list
  1525. commands.add(new commandRef(name, com));
  1526. //exit successfully
  1527. return true;
  1528. }
  1529. //=====================================================================
  1530. //Function: registerMessage
  1531. //Input: String name: The name of the command
  1532. // String msg: The message to be displayed
  1533. // boolean admin: If the message is displayed to admins only
  1534. //Output: boolean: Whether the command was input successfully or not
  1535. //Use: Registers a command to the command list for checking later
  1536. //=====================================================================
  1537. public boolean registerMessage(String name, String msg, String clr, int args, boolean admin)
  1538. {
  1539. //Check to make sure the command doesn't already exist
  1540. for(command temp : commands)
  1541. if(temp.getName().equalsIgnoreCase(name))
  1542. return false;
  1543. //Add the new function to the list
  1544. commands.add(new commandAnnounce(name, msg, clr, args, admin));
  1545. //exit successfully
  1546. return true;
  1547. }
  1548. //=====================================================================
  1549. //Function: call
  1550. //Input: String name: The name of the command to be run
  1551. // Player player: The player calling the command
  1552. // String[] arg: The arguments being input for the command
  1553. //Output: boolean: If the command was called successfully
  1554. //Use: Attempts to call a command
  1555. //=====================================================================
  1556. public int call(String name, Player player, String[] arg){
  1557. //Search for the command
  1558. for(command cmd : commands)
  1559. {
  1560. //When found
  1561. if(cmd.getName().equalsIgnoreCase(name))
  1562. {
  1563. try {
  1564. //Call the command and return results
  1565. return cmd.call(player, arg);
  1566. } catch (SecurityException e) {
  1567. log.log(Level.SEVERE, "Exception while running command", e);
  1568. } catch (IllegalArgumentException e) {
  1569. log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e);
  1570. return EXIT_FAIL;
  1571. }
  1572. }
  1573. }
  1574. //Something went wrong
  1575. return EXIT_FAIL;
  1576. }
  1577. //=====================================================================
  1578. //Function: toString
  1579. //Input: None
  1580. //Output: String: A string representation of the aliases in the list
  1581. //Use: Displays all the aliases in thel ist
  1582. //=====================================================================
  1583. public String toString()
  1584. {
  1585. String temp = "";
  1586. int i = 0;
  1587. for(command comm : commands)
  1588. {
  1589. temp += comm.toString();
  1590. if(i < commands.size() - 1)
  1591. temp +=",";
  1592. }
  1593. return temp;
  1594. }
  1595. //=====================================================================
  1596. //Class: command
  1597. //Use: The specific command
  1598. //Author: cerevisiae
  1599. //=====================================================================
  1600. private class command
  1601. {
  1602. private String commandName;
  1603. private String function;
  1604. //=====================================================================
  1605. //Function: command
  1606. //Input: None
  1607. //Output: None
  1608. //Use: Initialize the command
  1609. //=====================================================================
  1610. public command(String name, String func){
  1611. commandName = name;
  1612. function = func;
  1613. }
  1614. //=====================================================================
  1615. //Function: getName
  1616. //Input: None
  1617. //Output: String: The command name
  1618. //Use: Returns the command name
  1619. //=====================================================================
  1620. public String getName(){return commandName;}
  1621. //=====================================================================
  1622. //Function: call
  1623. //Input: String[] arg: The arguments for the command
  1624. //Output: boolean: If the command was called successfully
  1625. //Use: Attempts to call the command
  1626. //=====================================================================
  1627. int call(Player player, String[] arg)
  1628. {
  1629. Method m;
  1630. try {
  1631. m = vMinecraftCommands.class.getMethod(function, Player.class, String[].class);
  1632. m.setAccessible(true);
  1633. return (Integer) m.invoke(null, player, arg);
  1634. } catch (SecurityException e) {
  1635. e.printStackTrace();
  1636. } catch (NoSuchMethodException e) {
  1637. e.printStackTrace();
  1638. } catch (IllegalArgumentException e) {
  1639. e.printStackTrace();
  1640. } catch (IllegalAccessException e) {
  1641. e.printStackTrace();
  1642. } catch (InvocationTargetException e) {
  1643. e.printStackTrace();
  1644. }
  1645. return 1;
  1646. }
  1647. //=====================================================================
  1648. //Function: toString
  1649. //Input: None
  1650. //Output: String: null
  1651. //Use: Returns null
  1652. //=====================================================================
  1653. public String toString() { return null; }
  1654. }
  1655. //=====================================================================
  1656. //Class: commandRef
  1657. //Use: A command referencing another command
  1658. //Author: cerevisiae
  1659. //=====================================================================
  1660. private class commandRef extends command
  1661. {
  1662. private String reference;
  1663. private String[] args;
  1664. //=====================================================================
  1665. //Function: command
  1666. //Input: String name: The command name
  1667. // String com: The command to run
  1668. //Output: None
  1669. //Use: Initialize the command
  1670. //=====================================================================
  1671. public commandRef(String name, String com){
  1672. super(name, "");
  1673. //Get the reference name
  1674. String[]temp = com.split(" ");
  1675. reference = temp[0];
  1676. //Get the arguments
  1677. args = new String[temp.length - 1];
  1678. System.arraycopy(temp, 1, args, 0, temp.length - 1);
  1679. }
  1680. //=====================================================================
  1681. //Function: call
  1682. //Input: String[] arg: The arguments for the command
  1683. //Output: boolean: If the command was called successfully
  1684. //Use: Attempts to call the command
  1685. //=====================================================================
  1686. int call(Player player, String[] arg)
  1687. {
  1688. String[] temp = new String[0];
  1689. int lastSet = 0,
  1690. argCount = 0;
  1691. //If there are args set with the function
  1692. if(args != null && args.length > 0) {
  1693. temp = new String[args.length];
  1694. System.arraycopy(args, 0, temp, 0, args.length);
  1695. //Insert the arguments into the pre-set arguments
  1696. for(String argument : temp)
  1697. {
  1698. if(argument.startsWith("%") && argument.length() > 1)
  1699. {
  1700. int argNum = Integer.parseInt(argument.substring(1));
  1701. if( argNum < arg.length )
  1702. {
  1703. temp[lastSet] = arg[argNum];
  1704. argCount++;
  1705. }
  1706. }
  1707. lastSet++;
  1708. }
  1709. }
  1710. //If there are args being input
  1711. if(arg.length > 0) {
  1712. //Append the rest of the arguments to the argument array
  1713. if(lastSet < temp.length + arg.length - argCount)
  1714. {
  1715. String[] temp2 = new String[temp.length + arg.length - argCount];
  1716. System.arraycopy(temp, 0, temp2, 0, temp.length);
  1717. System.arraycopy(arg, argCount, temp2,
  1718. temp.length, arg.length - argCount);
  1719. temp = temp2;
  1720. }
  1721. log.log(Level.INFO, reference + " " + etc.combineSplit(0, temp, " "));
  1722. //Call the referenced command
  1723. player.command(reference + " " + etc.combineSplit(0, temp, " "));
  1724. } else
  1725. player.command(reference);
  1726. return EXIT_SUCCESS;
  1727. }
  1728. //=====================================================================
  1729. //Function: toString
  1730. //Input: None
  1731. //Output: String: A string representation of this command.
  1732. // command@referencedcommand arg1 arg2 argn
  1733. //Use: Returns the string representation of the alias
  1734. //=====================================================================
  1735. public String toString()
  1736. {
  1737. String temp = getName();
  1738. temp += '@';
  1739. temp += reference;
  1740. temp += etc.combineSplit(0, args, " ");
  1741. return temp;
  1742. }
  1743. }
  1744. //=====================================================================
  1745. //Class: commandAnnounce
  1746. //Use: Announces when a command is used
  1747. //Author: cerevisiae
  1748. //=====================================================================
  1749. private class commandAnnounce extends command
  1750. {
  1751. private String message;
  1752. private boolean admin;
  1753. private int minArgs;
  1754. private String color;
  1755. //=====================================================================
  1756. //Function: commandAnnounce
  1757. //Input: String name: The command name
  1758. // String msg: The message to announce
  1759. //Output: None
  1760. //Use: Initialize the command
  1761. //=====================================================================
  1762. public commandAnnounce(String name, String msg, String clr, int args, boolean admn){
  1763. super(name, "");
  1764. message = msg;
  1765. admin = admn;
  1766. minArgs = args;
  1767. color = clr;
  1768. }
  1769. //=====================================================================
  1770. //Function: call
  1771. //Input: String[] arg: The arguments for the command
  1772. //Output: boolean: If the command was called successfully
  1773. //Use: Attempts to call the command
  1774. //=====================================================================
  1775. int call(Player player, String[] arg)
  1776. {
  1777. //Make sure the player can use the command first
  1778. if(!player.canUseCommand(super.commandName)) return EXIT_FAIL;
  1779. //Make sure the command is long enough to fire
  1780. if(minArgs < arg.length)
  1781. return EXIT_FAIL;
  1782. if(vMinecraftSettings.getInstance().globalmessages())
  1783. {
  1784. //Split up the message
  1785. String[] temp = message.split(" ");
  1786. //Insert the arguments into the message
  1787. int i = 0;
  1788. for(String argument : temp)
  1789. {
  1790. if(argument.startsWith("%") && argument.length() > 1)
  1791. {
  1792. char position = argument.charAt(1);
  1793. //Replace %p with the player name
  1794. if(position == 'p')
  1795. temp[i] = vMinecraftChat.getName(player) + color;
  1796. else if( Character.isDigit(position) && Character.getNumericValue(position) < arg.length )
  1797. {
  1798. //If the argument is specified to be a player insert it if the
  1799. //player is found or exit if they aren't
  1800. if(argument.length() > 2 && argument.charAt(2) == 'p')
  1801. {
  1802. Player targetName = etc.getServer().matchPlayer(arg[Character.getNumericValue(position)]);
  1803. if(targetName != null)
  1804. temp[i] = vMinecraftChat.getName(targetName) + color;
  1805. else
  1806. return EXIT_FAIL;
  1807. }
  1808. //Replace %# with the argument at position #
  1809. else
  1810. temp[i] = arg[Character.getNumericValue(position)];
  1811. }
  1812. }
  1813. i++;
  1814. }
  1815. message = etc.combineSplit(0, temp, " ");
  1816. //If it's an admin message only
  1817. if(admin)
  1818. {
  1819. for (Player p: etc.getServer().getPlayerList()) {
  1820. //If p is not null
  1821. if (p != null) {
  1822. //And if p is an admin or has access to adminchat send message
  1823. if (p.isAdmin()) {
  1824. vMinecraftChat.sendMessage(player, p, color + message);
  1825. }
  1826. }
  1827. }
  1828. } else
  1829. vMinecraftChat.gmsg(player, message);
  1830. }
  1831. return EXIT_FAIL;
  1832. }
  1833. //=====================================================================
  1834. //Function: toString
  1835. //Input: None
  1836. //Output: String: null
  1837. //Use: Returns null
  1838. //=====================================================================
  1839. public String toString() { return null; }
  1840. }
  1841. }