vCom.java 84 KB

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