vCom.java 86 KB

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