vMinecraftCommands.java 81 KB

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