vMinecraftCommands.java 67 KB

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