vCom.java 86 KB

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