vMinecraftCommands.java 78 KB

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