vMinecraftCommands.java 81 KB

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