vMinecraftCommands.java 75 KB

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