vminecraftCommands.java 33 KB

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