vMinecraftCommands.java 76 KB

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