vMinecraftCommands.java 62 KB

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