vMinecraftCommands.java 56 KB

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