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