vMinecraftCommands.java 49 KB

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