vCom.java 85 KB

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