vMinecraftCommands.java 84 KB

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