vMinecraftCommands.java 49 KB

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