vMinecraftCommands.java 56 KB

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