vMinecraftCommands.java 84 KB

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