vMinecraftCommands.java 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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
  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. cl.register("/tp", "teleport");
  34. cl.register("/masstp", "masstp", "Teleports those with lower permissions to you");
  35. cl.register("/reload", "reload");
  36. cl.register("/rules", "rules", "Displays the rules");
  37. cl.register("/fabulous", "fabulous", "makes text SUUUPER");
  38. cl.register("/whois", "whois", "/whois [user]");
  39. cl.register("/who", "who");
  40. cl.register("/say", "say");
  41. cl.register("/slay", "slay", "Kill target player");
  42. cl.register("/ezmodo", "invuln", "Toggle invulnerability");
  43. cl.register("/ezlist", "ezlist", "List invulnerable players");
  44. cl.register("/heal", "heal", "heal yourself or other players");
  45. cl.register("/suicide", "suicide", "Kill yourself... you loser");
  46. cl.register("/a", "adminChatToggle", "Toggle admin chat for every message");
  47. cl.register("/modify", "modifySplit");
  48. cl.register("/me", "me");
  49. cl.register("/msg", "message", "Send a message to a player /msg [Player] [Message]");
  50. cl.register("/reply", "reply", "Reply to a player /reply [Message], Alias: /r");
  51. //registerAlias
  52. //String: The command that this will be called by
  53. //String: The message that will be called when the first is entered
  54. // Can be modified with %# to have it insert a player
  55. // argument into that position.
  56. // EX: Aliased command is
  57. // cl.registerAlias("/test", "/i %0 100")
  58. // Player uses /test wood
  59. // The %0 will be replaced with wood for this instance
  60. // and Player will be given 100 wood.
  61. cl.registerAlias("/playerlist", "/who");
  62. cl.registerAlias("/r", "/reply");
  63. cl.registerAlias("/w", "/msg");
  64. cl.registerAlias("/wrists", "/suicide");
  65. cl.registerAlias("/ci", "/clearinventory");
  66. //registerMessage
  67. //String: The command it will run on
  68. //String: What will be displayed
  69. // %p is the player calling the command
  70. // %# is the argument number of the command.
  71. // %#p is an argument number that will be required to be
  72. // an online player
  73. //String: The color the message will be
  74. //int: The number of arguments required for the message to appear
  75. //boolean: If the message should only display for admins
  76. cl.registerMessage("/kick", "%p has kicked %0p", Colors.Blue, 1, false);
  77. cl.registerMessage("/ban", "%p has banned %0p", Colors.Blue, 1, false);
  78. cl.registerMessage("/ipban", "%p has IP banned %0p", Colors.Blue, 1, false);
  79. cl.registerMessage("/time", "Time change thanks to %p", Colors.Blue, 1, true);
  80. cl.registerMessage("/tp", "%p has teleported to %0p", Colors.Blue, 1, true);
  81. }
  82. //=====================================================================
  83. //Function: me (/me)
  84. //Input: Player player: The player using the command
  85. // String[] args: Will contain the message the player sends
  86. //Output: int: Exit Code
  87. //Use: The player uses this to emote, but now its colorful.
  88. //=====================================================================
  89. public static int me(Player player, String[] args)
  90. {
  91. String str = etc.combineSplit(0, args, " ");
  92. if (args.length < 1) {return EXIT_FAIL;}
  93. vMinecraftChat.emote(player, str);
  94. return EXIT_SUCCESS;
  95. }
  96. //=====================================================================
  97. //Function: message (/msg, /w, /whisper)
  98. //Input: Player player: The player using the command
  99. // String[] args: Will contain the target player name and
  100. // message the player sends
  101. //Output: int: Exit Code
  102. //Use: Send a message to a player
  103. //=====================================================================
  104. public static int message(Player player, String[] args)
  105. {
  106. if (args.length > 1) {
  107. String msg = etc.combineSplit(1, args, " ");
  108. Player toPlayer = etc.getServer().matchPlayer(args[0]);
  109. if (toPlayer != null && args.length > 0) {
  110. //Send the message to the targeted player and the sender
  111. vMinecraftChat.sendMessage(player, toPlayer,
  112. Colors.LightGreen + "[From:" + vMinecraftChat.getName(player)
  113. + Colors.LightGreen + "] " + msg);
  114. vMinecraftChat.sendMessage(player, player,
  115. Colors.LightGreen + "[To:" + vMinecraftChat.getName(toPlayer)
  116. + Colors.LightGreen + "] " + msg);
  117. //Set the last massager for each player
  118. vMinecraftUsers.players.findProfile(player).setMessage(toPlayer);
  119. vMinecraftUsers.players.findProfile(toPlayer).setMessage(player);
  120. //Display the message to the log
  121. log.log(Level.INFO, player.getName() + " whispered to " + toPlayer.getName()
  122. + ": " + msg);
  123. } else {
  124. vMinecraftChat.sendMessage(player, player, Colors.Rose
  125. + "No player by the name of " + args[0] + " could be found.");
  126. }
  127. } else {
  128. vMinecraftChat.sendMessage(player, player, Colors.Rose
  129. + "Usage is /msg [player] [message]");
  130. }
  131. return EXIT_SUCCESS;
  132. }
  133. //=====================================================================
  134. //Function: reply (/r, /reply)
  135. //Input: Player player: The player using the command
  136. // String[] args: Will contain the message the player sends
  137. //Output: int: Exit Code
  138. //Use: Send a message to a player
  139. //=====================================================================
  140. public static int reply(Player player, String[] args)
  141. {
  142. //If the profile exists for the player
  143. if(vMinecraftUsers.players.findProfile(player) != null )
  144. {
  145. Player toPlayer = vMinecraftUsers.players.findProfile(player).getMessage();
  146. if (toPlayer != null && args.length > 0) {
  147. String msg = etc.combineSplit(0, args, " ");
  148. //Send the message to the targeted player and the sender
  149. vMinecraftChat.sendMessage(player, toPlayer,
  150. Colors.LightGreen + "[From:" + vMinecraftChat.getName(player)
  151. + Colors.LightGreen + "] " + msg);
  152. vMinecraftChat.sendMessage(player, player,
  153. Colors.LightGreen + "[To:" + vMinecraftChat.getName(toPlayer)
  154. + Colors.LightGreen + "] " + msg);
  155. //Set the last messager for each player
  156. vMinecraftUsers.players.findProfile(player).setMessage(toPlayer);
  157. vMinecraftUsers.players.findProfile(toPlayer).setMessage(player);
  158. //Display the message to the log
  159. log.log(Level.INFO, player.getName() + " whispered to " + toPlayer.getName()
  160. + ": " + msg);
  161. } else {
  162. vMinecraftChat.sendMessage(player, player,
  163. Colors.Rose + "The person you last message has logged off");
  164. }
  165. }
  166. return EXIT_SUCCESS;
  167. }
  168. public static int addIgnored(Player player, String[] args)
  169. {
  170. return EXIT_SUCCESS;
  171. }
  172. //=====================================================================
  173. //Function: adminChatToggle (/a)
  174. //Input: Player player: The player using the command
  175. // String[] args: Ignored
  176. //Output: int: Exit Code
  177. //Use: Toggles the player into admin chat. Every message they
  178. // send will be piped to admin chat.
  179. //=====================================================================
  180. public static int adminChatToggle(Player player, String[] args)
  181. {
  182. if(vMinecraftSettings.getInstance().adminChatToggle())
  183. {
  184. //If the player is already toggled for admin chat, remove them
  185. if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) {
  186. player.sendMessage(Colors.Red + "Admin Chat Toggle = off");
  187. vMinecraftSettings.getInstance().removeAdminToggled(player.getName());
  188. //Otherwise include them
  189. } else {
  190. player.sendMessage(Colors.Blue + "Admin Chat Toggled on");
  191. vMinecraftSettings.getInstance().addAdminToggled(player.getName());
  192. }
  193. return EXIT_SUCCESS;
  194. }
  195. return EXIT_FAIL;
  196. }
  197. //=====================================================================
  198. //Function: heal (/heal)
  199. //Input: Player player: The player using the command
  200. // String[] args: The arguments for the command. Should be a
  201. // player name or blank
  202. //Output: int: Exit Code
  203. //Use: Heals yourself or a specified player.
  204. //=====================================================================
  205. public static int heal(Player player, String[] args)
  206. {
  207. if(vMinecraftSettings.getInstance().cmdHeal())
  208. {
  209. //If a target wasn't specified, heal the user.
  210. if (args.length < 1){
  211. player.setHealth(20);
  212. player.sendMessage("Your health is restored");
  213. //If a target was specified, try to find them and then heal them
  214. //Otherwise report the error
  215. } else if (args.length > 0){
  216. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  217. if (playerTarget != null){
  218. playerTarget.setHealth(20);
  219. player.sendMessage(Colors.Blue + "You have healed " + vMinecraftChat.getName(playerTarget));
  220. playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vMinecraftChat.getName(player));
  221. }
  222. else if (playerTarget == null){
  223. player.sendMessage(Colors.Rose + "Couldn't find that player");
  224. }
  225. }
  226. return EXIT_SUCCESS;
  227. }
  228. return EXIT_FAIL;
  229. }
  230. //=====================================================================
  231. //Function: suicide (/suicide, /wrists)
  232. //Input: Player player: The player using the command
  233. // String[] args: Ignored
  234. //Output: int: Exit Code
  235. //Use: Kills yourself
  236. //=====================================================================
  237. public static int suicide(Player player, String[] args)
  238. {
  239. if(vMinecraftSettings.getInstance().cmdSuicide())
  240. {
  241. //Set your health to 0. Not much to it.
  242. player.setHealth(0);
  243. return EXIT_SUCCESS;
  244. }
  245. return EXIT_FAIL;
  246. }
  247. //=====================================================================
  248. //Function: teleport (/tp)
  249. //Input: Player player: The player using the command
  250. // String[] args: The arguments for the command. Should be a
  251. // player name
  252. //Output: int: Exit Code
  253. //Use: Teleports the user to another player
  254. //=====================================================================
  255. public static int teleport(Player player, String[] args)
  256. {
  257. //Get if the command is enabled
  258. if(vMinecraftSettings.getInstance().cmdTp())
  259. {
  260. //Make sure a player has been specified and return an error if not
  261. if (args.length < 1) {
  262. player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]");
  263. } else {
  264. //Find the player by name
  265. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  266. //Target player isn't found
  267. if(playerTarget == null)
  268. player.sendMessage(Colors.Rose + "Can't find user "
  269. + args[0] + ".");
  270. //If it's you, return witty message
  271. else if (player.getName().equalsIgnoreCase(args[0]))
  272. player.sendMessage(Colors.Rose + "You're already here!");
  273. //If the player is higher rank than you, inform the user
  274. else if (!player.hasControlOver(playerTarget))
  275. player.sendMessage(Colors.Red +
  276. "That player has higher permissions than you.");
  277. //If the player exists transport the user to the player
  278. else {
  279. log.log(Level.INFO, player.getName() + " teleported to " +
  280. playerTarget.getName());
  281. player.teleportTo(playerTarget);
  282. //Otherwise inform the user that the player doesn't exist
  283. }
  284. }
  285. return EXIT_SUCCESS;
  286. }
  287. return EXIT_FAIL;
  288. }
  289. //=====================================================================
  290. //Function: masstp (/masstp)
  291. //Input: Player player: The player using the command
  292. // String[] args: Should be empty or is ignored
  293. //Output: int: Exit Code
  294. //Use: Teleports all players to the user
  295. //=====================================================================
  296. public static int masstp(Player player, String[] args)
  297. {
  298. //If the command is enabled
  299. if(vMinecraftSettings.getInstance().cmdMasstp()) {
  300. //Go through all players and move them to the user
  301. for (Player p : etc.getServer().getPlayerList()) {
  302. if (!p.hasControlOver(player)) {
  303. p.teleportTo(player);
  304. }
  305. }
  306. //Inform the user that the command has executed successfully
  307. player.sendMessage(Colors.Blue+"Summoning successful.");
  308. return EXIT_SUCCESS;
  309. }
  310. return EXIT_FAIL;
  311. }
  312. //=====================================================================
  313. //Function: tphere (/tphere)
  314. //Input: Player player: The player using the command
  315. // String[] args: The arguments for the command. Should be a
  316. // player name
  317. //Output: int: Exit Code
  318. //Use: Teleports the user to another player
  319. //=====================================================================
  320. public static int tphere(Player player, String[] args)
  321. {
  322. //Check if the command is enabled.
  323. if (vMinecraftSettings.getInstance().cmdTphere()) {
  324. //Make sure a player is specified
  325. if (args.length < 1) {
  326. player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]");
  327. } else {
  328. //Get the player by name
  329. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  330. //If the target doesn't exist
  331. if(playerTarget == null)
  332. player.sendMessage(Colors.Rose + "Can't find user " + args[0] + ".");
  333. //If the player has a higher rank than the user, return error
  334. else if (!player.hasControlOver(playerTarget))
  335. player.sendMessage(Colors.Red + "That player has higher permissions than you.");
  336. //If the user teleports themselves, mock them
  337. else if (player.getName().equalsIgnoreCase(args[0]))
  338. player.sendMessage(Colors.Rose + "Wow look at that! You teleported yourself to yourself!");
  339. //If the target exists, teleport them to the user
  340. else {
  341. log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self.");
  342. playerTarget.teleportTo(player);
  343. }
  344. }
  345. return EXIT_SUCCESS;
  346. }
  347. return EXIT_FAIL;
  348. }
  349. //=====================================================================
  350. //Function: reload (/reload)
  351. //Input: Player player: The player using the command
  352. // String[] args: Ignored
  353. //Output: int: Exit Code
  354. //Use: Reloads the settings for vMinecraft
  355. //=====================================================================
  356. public static int reload(Player player, String[] args)
  357. {
  358. vMinecraftSettings.getInstance().loadSettings();
  359. return EXIT_FAIL;
  360. }
  361. //=====================================================================
  362. //Function: rules (/rules)
  363. //Input: Player player: The player using the command
  364. // String[] args: Ignored
  365. //Output: int: Exit Code
  366. //Use: Lists the rules
  367. //=====================================================================
  368. public static int rules(Player player, String[] args)
  369. {
  370. //If the rules exist
  371. if(vMinecraftSettings.getInstance().cmdRules()
  372. && vMinecraftSettings.getInstance().getRules().length > 0) {
  373. //Apply QuakeCode Colors to the rules
  374. String[] rules = vMinecraftChat.applyColors(
  375. vMinecraftSettings.getInstance().getRules());
  376. //Display them
  377. for (String str : rules ) {
  378. if(!str.isEmpty())
  379. player.sendMessage(Colors.Blue + str);
  380. else
  381. player.sendMessage(Colors.Blue + "!!!The Rules Have Not Been Set!!!");
  382. }
  383. return EXIT_SUCCESS;
  384. }
  385. return EXIT_FAIL;
  386. }
  387. //=====================================================================
  388. //Function: fabulous (/fabulous)
  389. //Input: Player player: The player using the command
  390. // String[] args: The message to apply the effect to
  391. //Output: int: Exit Code
  392. //Use: Makes the text rainbow colored
  393. //=====================================================================
  394. public static int fabulous(Player player, String[] args)
  395. {
  396. //If the command is enabled
  397. if(vMinecraftSettings.getInstance().cmdFabulous()) {
  398. //Format the name
  399. String playerName = Colors.White + "<"
  400. + vMinecraftChat.getName(player) + Colors.White +"> ";
  401. //Make sure a message has been specified
  402. if (args.length < 1) {return EXIT_FAIL;}
  403. String str = " ";
  404. //Merge the message again
  405. str = etc.combineSplit(0, args, " ");
  406. //Output for server
  407. log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  408. //Prepend the player name and cut into lines.
  409. vMinecraftChat.gmsg(player, playerName + vMinecraftChat.rainbow(str));
  410. return EXIT_SUCCESS;
  411. }
  412. return EXIT_FAIL;
  413. }
  414. //=====================================================================
  415. //Function: whois (/whois)
  416. //Input: Player player: The player using the command
  417. // String[] args: The player to find info on
  418. //Output: int: Exit Code
  419. //Use: Displays information about the player specified
  420. //=====================================================================
  421. public static int whois(Player player, String[] args)
  422. {
  423. //If the command is enabled
  424. if (vMinecraftSettings.getInstance().cmdWhoIs()) {
  425. //If a player is specified
  426. if (args.length < 1)
  427. player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  428. else {
  429. //Get the player by name
  430. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  431. //If the player exists
  432. if (playerTarget != null){
  433. //Displaying the information
  434. player.sendMessage(Colors.Blue + "Whois results for " +
  435. vMinecraftChat.getName(playerTarget));
  436. //Group
  437. for(String group: playerTarget.getGroups())
  438. player.sendMessage(Colors.Blue + "Groups: " + group);
  439. //Admin
  440. player.sendMessage(Colors.Blue+"Admin: " +
  441. String.valueOf(playerTarget.isAdmin()));
  442. //IP
  443. player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP());
  444. //Restrictions
  445. player.sendMessage(Colors.Blue+"Can ignore restrictions: " +
  446. String.valueOf(playerTarget.canIgnoreRestrictions()));
  447. //Give the user an error if the player doesn't exist
  448. } else {
  449. player.sendMessage(Colors.Rose+"Player not found.");
  450. }
  451. }
  452. return EXIT_SUCCESS;
  453. }
  454. return EXIT_SUCCESS;
  455. }
  456. //=====================================================================
  457. //Function: who (/who)
  458. //Input: Player player: The player using the command
  459. // String[] args: Ignored
  460. //Output: int: Exit Code
  461. //Use: Displays the connected players
  462. //=====================================================================
  463. public static int who(Player player, String[] args)
  464. {
  465. //If the command is enabled
  466. if (vMinecraftSettings.getInstance().cmdWho()) {
  467. //Loop through all players counting them and adding to the list
  468. int count=0;
  469. String tempList = "";
  470. for( Player p : etc.getServer().getPlayerList())
  471. {
  472. if(p != null){
  473. if(count == 0)
  474. tempList += vMinecraftChat.getName(p);
  475. else
  476. tempList += Colors.White + ", " + vMinecraftChat.getName(p);
  477. count++;
  478. }
  479. }
  480. //Get the max players from the config
  481. PropertiesFile server = new PropertiesFile("server.properties");
  482. try {
  483. server.load();
  484. } catch (IOException e) {
  485. e.printStackTrace();
  486. }
  487. int maxPlayers = server.getInt("max-players");
  488. //Output the player list
  489. vMinecraftChat.sendMessage(player, player, Colors.Rose + "Player List ("
  490. + count + "/" + maxPlayers +"): " + tempList);
  491. return EXIT_SUCCESS;
  492. }
  493. return EXIT_FAIL;
  494. }
  495. //=====================================================================
  496. //Function: say (/say)
  497. //Input: Player player: The player using the command
  498. // String[] args: The message to apply the effect to
  499. //Output: int: Exit Code
  500. //Use: Announces the message to all players
  501. //=====================================================================
  502. public static int say(Player player, String[] args)
  503. {
  504. //If the command is enabled
  505. if (vMinecraftSettings.getInstance().cmdSay()) {
  506. //Make sure a message is supplied or output an error
  507. if (args.length < 1) {
  508. player.sendMessage(Colors.Rose + "Usage is /say [message]");
  509. }
  510. //Display the message globally
  511. vMinecraftChat.gmsg(player, Colors.Yellow + etc.combineSplit(0, args, " "));
  512. return EXIT_SUCCESS;
  513. }
  514. return EXIT_FAIL;
  515. }
  516. //=====================================================================
  517. //Function: slay (/slay)
  518. //Input: Player player: The player using the command
  519. // String[] args: The target for the command
  520. //Output: int: Exit Code
  521. //Use: Kill the target player
  522. //=====================================================================
  523. public static int slay(Player player, String[] args)
  524. {
  525. //Check if the command is enabled
  526. if(vMinecraftSettings.getInstance().cmdEzModo()) {
  527. //Get the player by name
  528. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  529. //If the player doesn't exist don't run
  530. if(playerTarget == null)
  531. return EXIT_FAIL;
  532. //If the player isn't invulnerable kill them
  533. if (!vMinecraftSettings.getInstance().isEzModo(playerTarget.getName())) {
  534. playerTarget.setHealth(0);
  535. vMinecraftChat.gmsg(player, vMinecraftChat.getName(player)
  536. + Colors.LightBlue + " has slain "
  537. + vMinecraftChat.getName(playerTarget));
  538. //Otherwise output error to the user
  539. } else {
  540. player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha");
  541. }
  542. return EXIT_SUCCESS;
  543. }
  544. return EXIT_FAIL;
  545. }
  546. //=====================================================================
  547. //Function: invuln (/ezmodo)
  548. //Input: Player player: The player using the command
  549. // String[] args: The target for the command
  550. //Output: int: Exit Code
  551. //Use: Kill the target player
  552. //=====================================================================
  553. public static int invuln(Player player, String[] args)
  554. {
  555. //If the command is enabled
  556. if (vMinecraftSettings.getInstance().cmdEzModo()) {
  557. //If the player is already invulnerable, turn ezmodo off.
  558. if (vMinecraftSettings.getInstance().isEzModo(player.getName())) {
  559. player.sendMessage(Colors.Red + "ezmodo = off");
  560. vMinecraftSettings.getInstance().removeEzModo(player.getName());
  561. //Otherwise make them invulnerable
  562. } else {
  563. player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?");
  564. player.sendMessage(Colors.Rose + "kimo-i");
  565. player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru no wa shougakusei made dayo ne");
  566. player.sendMessage(Colors.Red + "**Laughter**");
  567. vMinecraftSettings.getInstance().addEzModo(player.getName());
  568. }
  569. return EXIT_SUCCESS;
  570. }
  571. return EXIT_FAIL;
  572. }
  573. //=====================================================================
  574. //Function: ezlist (/ezlist)
  575. //Input: Player player: The player using the command
  576. // String[] args: Ignored
  577. //Output: int: Exit Code
  578. //Use: List all invulnerable players
  579. //=====================================================================
  580. public static int ezlist(Player player, String[] args)
  581. {
  582. //If the feature is enabled list the players
  583. if(vMinecraftSettings.getInstance().cmdEzModo()) {
  584. player.sendMessage("Ezmodo: " + vMinecraftSettings.getInstance().ezModoList());
  585. return EXIT_SUCCESS;
  586. }
  587. return EXIT_FAIL;
  588. }
  589. //=====================================================================
  590. //Function: modifySplit (/modify)
  591. //Input: Player player: The player using the command
  592. // String[] args: Player, Command, Arguments
  593. //Output: int: Exit Code
  594. //Use: List all invulnerable players
  595. //=====================================================================
  596. public static int modifySplit(Player player, String[] args)
  597. {
  598. //Exploit fix for people giving themselves commands
  599. if(args[2].equals("commands")){
  600. return EXIT_FAIL;
  601. }
  602. return EXIT_CONTINUE;
  603. }
  604. //=====================================================================
  605. //Function: Time Reverse
  606. //Input: long time: The time to reverse to.
  607. //Output: int: Exit Code
  608. //Use: List all invulnerable players
  609. //=====================================================================
  610. public static int timeReverse(long tarTime)
  611. {
  612. long curTime = etc.getServer().getRelativeTime();
  613. //if(cur)
  614. return EXIT_SUCCESS;
  615. }
  616. }
  617. //=====================================================================
  618. //Class: commandList
  619. //Use: The list of commands that will be checked for
  620. //Author: cerevisiae
  621. //=====================================================================
  622. class commandList {
  623. ArrayList<command> commands;
  624. protected static final Logger log = Logger.getLogger("Minecraft");
  625. static final int EXIT_FAIL = 0,
  626. EXIT_SUCCESS = 1,
  627. EXIT_CONTINUE = 2;
  628. //=====================================================================
  629. //Function: commandList
  630. //Input: None
  631. //Output: None
  632. //Use: Initialize the array of commands
  633. //=====================================================================
  634. public commandList(){
  635. commands = new ArrayList<command>();
  636. }
  637. //=====================================================================
  638. //Function: register
  639. //Input: String name: The name of the command
  640. // String func: The function to be called
  641. //Output: boolean: Whether the command was input successfully or not
  642. //Use: Registers a command to the command list for checking later
  643. //=====================================================================
  644. public boolean register(String name, String func)
  645. {
  646. //Check to make sure the command doesn't already exist
  647. for(command temp : commands)
  648. if(temp.getName().equalsIgnoreCase(name))
  649. return false;
  650. //Add the new function to the list
  651. commands.add(new command(name, func));
  652. //exit successfully
  653. return true;
  654. }
  655. //=====================================================================
  656. //Function: register
  657. //Input: String name: The name of the command
  658. // String func: The function to be called
  659. // String info: The information for the command to put in help
  660. //Output: boolean: Whether the command was input successfully or not
  661. //Use: Registers a command to the command list for checking later
  662. //=====================================================================
  663. public boolean register(String name, String func, String info){
  664. //Add to the /help list
  665. etc.getInstance().addCommand(name, info);
  666. //Finish registering
  667. return register(name, func);
  668. }
  669. //=====================================================================
  670. //Function: register
  671. //Input: String name: The name of the command
  672. // String func: The function to be called
  673. //Output: boolean: Whether the command was input successfully or not
  674. //Use: Registers a command to the command list for checking later
  675. //=====================================================================
  676. public boolean registerAlias(String name, String com)
  677. {
  678. //Check to make sure the command doesn't already exist
  679. for(command temp : commands)
  680. if(temp.getName().equalsIgnoreCase(name))
  681. return false;
  682. //Add the new function to the list
  683. commands.add(new commandRef(name, com));
  684. //exit successfully
  685. return true;
  686. }
  687. //=====================================================================
  688. //Function: registerMessage
  689. //Input: String name: The name of the command
  690. // String msg: The message to be displayed
  691. // boolean admin: If the message is displayed to admins only
  692. //Output: boolean: Whether the command was input successfully or not
  693. //Use: Registers a command to the command list for checking later
  694. //=====================================================================
  695. public boolean registerMessage(String name, String msg, String clr, int args, boolean admin)
  696. {
  697. //Check to make sure the command doesn't already exist
  698. for(command temp : commands)
  699. if(temp.getName().equalsIgnoreCase(name))
  700. return false;
  701. //Add the new function to the list
  702. commands.add(new commandAnnounce(name, msg, clr, args, admin));
  703. //exit successfully
  704. return true;
  705. }
  706. //=====================================================================
  707. //Function: call
  708. //Input: String name: The name of the command to be run
  709. //Output: boolean: If the command was called successfully
  710. //Use: Attempts to call a command
  711. //=====================================================================
  712. public int call(String name, Player player, String[] arg){
  713. //Make sure the user has access to the command
  714. if(!player.canUseCommand(name)) {
  715. return EXIT_FAIL;
  716. }
  717. //Search for the command
  718. for(command cmd : commands)
  719. {
  720. //When found
  721. if(cmd.getName().equalsIgnoreCase(name))
  722. {
  723. try {
  724. //Call the command and return results
  725. return cmd.call(player, arg);
  726. } catch (SecurityException e) {
  727. log.log(Level.SEVERE, "Exception while running command", e);
  728. } catch (IllegalArgumentException e) {
  729. log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e);
  730. return EXIT_FAIL;
  731. }
  732. }
  733. }
  734. //Something went wrong
  735. return EXIT_FAIL;
  736. }
  737. //=====================================================================
  738. //Class: command
  739. //Use: The specific command
  740. //Author: cerevisiae
  741. //=====================================================================
  742. private class command
  743. {
  744. private String commandName;
  745. private String function;
  746. //=====================================================================
  747. //Function: command
  748. //Input: None
  749. //Output: None
  750. //Use: Initialize the command
  751. //=====================================================================
  752. public command(String name, String func){
  753. commandName = name;
  754. function = func;
  755. }
  756. //=====================================================================
  757. //Function: getName
  758. //Input: None
  759. //Output: String: The command name
  760. //Use: Returns the command name
  761. //=====================================================================
  762. public String getName(){return commandName;}
  763. //=====================================================================
  764. //Function: call
  765. //Input: String[] arg: The arguments for the command
  766. //Output: boolean: If the command was called successfully
  767. //Use: Attempts to call the command
  768. //=====================================================================
  769. int call(Player player, String[] arg)
  770. {
  771. Method m;
  772. try {
  773. m = vMinecraftCommands.class.getMethod(function, Player.class, String[].class);
  774. m.setAccessible(true);
  775. return (Integer) m.invoke(null, player, arg);
  776. } catch (SecurityException e) {
  777. e.printStackTrace();
  778. } catch (NoSuchMethodException e) {
  779. e.printStackTrace();
  780. } catch (IllegalArgumentException e) {
  781. e.printStackTrace();
  782. } catch (IllegalAccessException e) {
  783. e.printStackTrace();
  784. } catch (InvocationTargetException e) {
  785. e.printStackTrace();
  786. }
  787. return 1;
  788. }
  789. }
  790. //=====================================================================
  791. //Class: commandRef
  792. //Use: A command referencing another command
  793. //Author: cerevisiae
  794. //=====================================================================
  795. private class commandRef extends command
  796. {
  797. private String reference;
  798. private String[] args;
  799. //=====================================================================
  800. //Function: command
  801. //Input: String name: The command name
  802. // String com: The command to run
  803. //Output: None
  804. //Use: Initialize the command
  805. //=====================================================================
  806. public commandRef(String name, String com){
  807. super(name, "");
  808. //Get the reference name
  809. String[]temp = com.split(" ");
  810. reference = temp[0];
  811. //Get the arguments
  812. args = new String[temp.length - 1];
  813. System.arraycopy(temp, 1, args, 0, temp.length - 1);
  814. }
  815. //=====================================================================
  816. //Function: call
  817. //Input: String[] arg: The arguments for the command
  818. //Output: boolean: If the command was called successfully
  819. //Use: Attempts to call the command
  820. //=====================================================================
  821. int call(Player player, String[] arg)
  822. {
  823. String[] temp = new String[0];
  824. int lastSet = 0,
  825. argCount = 0;
  826. //If there are args set with the function
  827. if(args != null && args.length > 0) {
  828. temp = new String[args.length];
  829. System.arraycopy(args, 0, temp, 0, args.length);
  830. //Insert the arguments into the pre-set arguments
  831. for(String argument : temp)
  832. {
  833. if(argument.startsWith("%") && argument.length() > 1)
  834. {
  835. int argNum = Integer.parseInt(argument.substring(1));
  836. if( argNum < arg.length )
  837. {
  838. temp[lastSet] = arg[argNum];
  839. argCount++;
  840. }
  841. }
  842. lastSet++;
  843. }
  844. }
  845. //If there are args being input
  846. if(arg.length > 0) {
  847. //Append the rest of the arguments to the argument array
  848. if(lastSet < temp.length + arg.length - argCount)
  849. {
  850. String[] temp2 = new String[temp.length + arg.length - argCount];
  851. System.arraycopy(temp, 0, temp2, 0, temp.length);
  852. System.arraycopy(arg, argCount, temp2,
  853. temp.length, arg.length - argCount);
  854. temp = temp2;
  855. }
  856. log.log(Level.INFO, reference + " " + etc.combineSplit(0, temp, " "));
  857. //Call the referenced command
  858. player.command(reference + " " + etc.combineSplit(0, temp, " "));
  859. } else
  860. player.command(reference);
  861. return EXIT_SUCCESS;
  862. }
  863. }
  864. //=====================================================================
  865. //Class: commandAnnounce
  866. //Use: Announces when a command is used
  867. //Author: cerevisiae
  868. //=====================================================================
  869. private class commandAnnounce extends command
  870. {
  871. private String message;
  872. private boolean admin;
  873. private int minArgs;
  874. private String color;
  875. //=====================================================================
  876. //Function: commandAnnounce
  877. //Input: String name: The command name
  878. // String msg: The message to announce
  879. //Output: None
  880. //Use: Initialize the command
  881. //=====================================================================
  882. public commandAnnounce(String name, String msg, String clr, int args, boolean admn){
  883. super(name, "");
  884. message = msg;
  885. admin = admn;
  886. minArgs = args;
  887. color = clr;
  888. }
  889. //=====================================================================
  890. //Function: call
  891. //Input: String[] arg: The arguments for the command
  892. //Output: boolean: If the command was called successfully
  893. //Use: Attempts to call the command
  894. //=====================================================================
  895. int call(Player player, String[] arg)
  896. {
  897. //Make sure the player can use the command first
  898. if(!player.canUseCommand(super.commandName))
  899. return EXIT_FAIL;
  900. //Make sure the command is long enough to fire
  901. if(minArgs < arg.length)
  902. return EXIT_FAIL;
  903. if(vMinecraftSettings.getInstance().globalmessages())
  904. {
  905. //Split up the message
  906. String[] temp = message.split(" ");
  907. //Insert the arguments into the message
  908. int i = 0;
  909. for(String argument : temp)
  910. {
  911. if(argument.startsWith("%") && argument.length() > 1)
  912. {
  913. char position = argument.charAt(1);
  914. //Replace %p with the player name
  915. if(position == 'p')
  916. temp[i] = vMinecraftChat.getName(player) + color;
  917. else if( Character.isDigit(position) && Character.getNumericValue(position) < arg.length )
  918. {
  919. //If the argument is specified to be a player insert it if the
  920. //player is found or exit if they aren't
  921. if(argument.length() > 2 && argument.charAt(2) == 'p')
  922. {
  923. Player targetName = etc.getServer().matchPlayer(arg[Character.getNumericValue(position)]);
  924. if(targetName != null)
  925. temp[i] = vMinecraftChat.getName(targetName) + color;
  926. else
  927. return EXIT_FAIL;
  928. }
  929. //Replace %# with the argument at position #
  930. else
  931. temp[i] = arg[Character.getNumericValue(position)];
  932. }
  933. }
  934. i++;
  935. }
  936. message = etc.combineSplit(0, temp, " ");
  937. //If it's an admin message only
  938. if(admin)
  939. {
  940. for (Player p: etc.getServer().getPlayerList()) {
  941. //If p is not null
  942. if (p != null) {
  943. //And if p is an admin or has access to adminchat send message
  944. if (p.isAdmin()) {
  945. vMinecraftChat.sendMessage(player, p, color + message);
  946. }
  947. }
  948. }
  949. } else
  950. vMinecraftChat.gmsg(player, message);
  951. }
  952. return EXIT_FAIL;
  953. }
  954. }
  955. }