vMinecraftCommands.java 54 KB

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