vMinecraftCommands.java 78 KB

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