vCom.java 82 KB

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