vMinecraftCommands.java 55 KB

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