vMinecraftCommands.java 61 KB

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