vCom.java 86 KB

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