vMinecraftCommands.java 62 KB

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