vCom.java 85 KB

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