vCom.java 85 KB

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