vminecraftCommands.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  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. //Display them
  221. for (String str : vminecraftSettings.getInstance().getRules()) {
  222. if(str.isEmpty())
  223. player.sendMessage(Colors.Blue+str);
  224. }
  225. return EXIT_SUCCESS;
  226. }
  227. return EXIT_FAIL;
  228. }
  229. //=====================================================================
  230. //Function: fabulous (/fabulous)
  231. //Input: Player player: The player using the command
  232. // String[] args: The message to apply the effect to
  233. //Output: int: Exit Code
  234. //Use: Makes the text rainbow colored
  235. //=====================================================================
  236. public static int fabulous(Player player, String[] args)
  237. {
  238. //If the command is enabled
  239. if(vminecraftSettings.getInstance().cmdFabulous()) {
  240. //Format the name
  241. String playerName = Colors.White + "<"
  242. + vminecraftChat.getName(player) + Colors.White +"> ";
  243. //Make sure a message has been specified
  244. if (args.length < 1) {return EXIT_FAIL;}
  245. String str = " ";
  246. //Merge the message again
  247. str = etc.combineSplit(0, args, " ");
  248. //Output for server
  249. log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  250. //Prepend the player name and cut into lines.
  251. String[] message = vminecraftChat.wordWrap(playerName + str);
  252. //Output the message
  253. for(String msg: message)
  254. {
  255. if (msg.contains(playerName))
  256. vminecraftChat.gmsg( playerName
  257. + vminecraftChat.rainbow(
  258. msg.substring(playerName.length())));
  259. else
  260. vminecraftChat.gmsg(vminecraftChat.rainbow(msg));
  261. }
  262. return EXIT_SUCCESS;
  263. }
  264. return EXIT_FAIL;
  265. }
  266. //=====================================================================
  267. //Function: whois (/whois)
  268. //Input: Player player: The player using the command
  269. // String[] args: The player to find info on
  270. //Output: int: Exit Code
  271. //Use: Displays information about the player specified
  272. //=====================================================================
  273. public static int whois(Player player, String[] args)
  274. {
  275. //If the command is enabled
  276. if (vminecraftSettings.getInstance().cmdWhoIs()) {
  277. //If a player is specified
  278. if (args.length < 1)
  279. player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  280. else {
  281. //Get the player by name
  282. Player playerTarget = null;
  283. for( Player p : etc.getServer().getPlayerList())
  284. {
  285. if (p.getName().equalsIgnoreCase(args[0]))
  286. {
  287. playerTarget = p;
  288. }
  289. }
  290. //If the player exists
  291. if (playerTarget != null){
  292. //Displaying the information
  293. player.sendMessage(Colors.Blue + "Whois results for " +
  294. vminecraftChat.getName(playerTarget));
  295. //Group
  296. for(String group: playerTarget.getGroups())
  297. player.sendMessage(Colors.Blue + "Groups: " + group);
  298. //Admin
  299. player.sendMessage(Colors.Blue+"Admin: " +
  300. String.valueOf(playerTarget.isAdmin()));
  301. //IP
  302. player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP());
  303. //Restrictions
  304. player.sendMessage(Colors.Blue+"Can ignore restrictions: " +
  305. String.valueOf(playerTarget.canIgnoreRestrictions()));
  306. //Give the user an error if the player doesn't exist
  307. } else {
  308. player.sendMessage(Colors.Rose+"Player not found.");
  309. }
  310. }
  311. return EXIT_SUCCESS;
  312. }
  313. return EXIT_SUCCESS;
  314. }
  315. //=====================================================================
  316. //Function: who (/who)
  317. //Input: Player player: The player using the command
  318. // String[] args: Ignored
  319. //Output: int: Exit Code
  320. //Use: Displays the connected players
  321. //=====================================================================
  322. public static int who(Player player, String[] args)
  323. {
  324. //If the command is enabled
  325. if (vminecraftSettings.getInstance().cmdWho()) {
  326. //Loop through all players counting them and adding to the list
  327. int count=0;
  328. String tempList = "";
  329. for( Player p : etc.getServer().getPlayerList())
  330. {
  331. if(p != null){
  332. if(count == 0)
  333. tempList += vminecraftChat.getName(p);
  334. else
  335. tempList += Colors.White + ", " + vminecraftChat.getName(p);
  336. count++;
  337. }
  338. }
  339. //Get the max players from the config
  340. PropertiesFile server = new PropertiesFile("server.properties");
  341. try {
  342. server.load();
  343. } catch (IOException e) {
  344. e.printStackTrace();
  345. }
  346. int maxPlayers = server.getInt("max-players");
  347. //Output the player list
  348. String[] tempOut = vminecraftChat.wordWrap(Colors.Rose + "Player List ("
  349. + count + "/" + maxPlayers +"): " + tempList);
  350. for(String msg: tempOut)
  351. player.sendMessage( msg );
  352. return EXIT_SUCCESS;
  353. }
  354. return EXIT_FAIL;
  355. }
  356. //=====================================================================
  357. //Function: say (/say)
  358. //Input: Player player: The player using the command
  359. // String[] args: The message to apply the effect to
  360. //Output: int: Exit Code
  361. //Use: Announces the message to all players
  362. //=====================================================================
  363. public static int say(Player player, String[] args)
  364. {
  365. //If the command is enabled
  366. if (vminecraftSettings.getInstance().cmdSay()) {
  367. //Make sure a message is supplied or output an error
  368. if (args.length < 1) {
  369. player.sendMessage(Colors.Rose + "Usage is /say [message]");
  370. }
  371. //Display the message globally
  372. vminecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " "));
  373. return EXIT_SUCCESS;
  374. }
  375. return EXIT_FAIL;
  376. }
  377. //=====================================================================
  378. //Function: slay (/slay)
  379. //Input: Player player: The player using the command
  380. // String[] args: The target for the command
  381. //Output: int: Exit Code
  382. //Use: Kill the target player
  383. //=====================================================================
  384. public static int slay(Player player, String[] args)
  385. {
  386. //Check if the command is enabled
  387. if(vminecraftSettings.getInstance().cmdEzModo()) {
  388. //Get the player by name
  389. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  390. //If the player doesn't exist don't run
  391. if(playerTarget == null)
  392. return EXIT_FAIL;
  393. //If the player isn't invulnerable kill them
  394. if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) {
  395. playerTarget.setHealth(0);
  396. vminecraftChat.gmsg(vminecraftChat.getName(player)
  397. + Colors.LightBlue + " has slain "
  398. + vminecraftChat.getName(playerTarget));
  399. //Otherwise output error to the user
  400. } else {
  401. player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha");
  402. }
  403. return EXIT_SUCCESS;
  404. }
  405. return EXIT_FAIL;
  406. }
  407. //=====================================================================
  408. //Function: invuln (/ezmodo)
  409. //Input: Player player: The player using the command
  410. // String[] args: The target for the command
  411. //Output: int: Exit Code
  412. //Use: Kill the target player
  413. //=====================================================================
  414. public static int invuln(Player player, String[] args)
  415. {
  416. //If the command is enabled
  417. if (vminecraftSettings.getInstance().cmdEzModo()) {
  418. //If the player is already invulnerable, turn ezmodo off.
  419. if (vminecraftSettings.getInstance().isEzModo(player.getName())) {
  420. player.sendMessage(Colors.Red + "ezmodo = off");
  421. vminecraftSettings.getInstance().removeEzModo(player.getName());
  422. //Otherwise make them invulnerable
  423. } else {
  424. player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?");
  425. player.sendMessage(Colors.Rose + "kimo-i");
  426. player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru no wa shougakusei made dayo ne");
  427. player.sendMessage(Colors.Red + "**Laughter**");
  428. vminecraftSettings.getInstance().addEzModo(player.getName());
  429. player.setHealth(vminecraftSettings.getInstance().ezModoHealth());
  430. }
  431. return EXIT_SUCCESS;
  432. }
  433. return EXIT_FAIL;
  434. }
  435. //=====================================================================
  436. //Function: ezlist (/ezlist)
  437. //Input: Player player: The player using the command
  438. // String[] args: Ignored
  439. //Output: int: Exit Code
  440. //Use: List all invulnerable players
  441. //=====================================================================
  442. public static int ezlist(Player player, String[] args)
  443. {
  444. //If the feature is enabled list the players
  445. if(vminecraftSettings.getInstance().cmdEzModo()) {
  446. player.sendMessage("Ezmodo: " + vminecraftSettings.getInstance().ezModoList());
  447. return EXIT_SUCCESS;
  448. }
  449. return EXIT_FAIL;
  450. }
  451. //=====================================================================
  452. //Function: modifySplit (/modify)
  453. //Input: Player player: The player using the command
  454. // String[] args: Player, Command, Arguments
  455. //Output: int: Exit Code
  456. //Use: List all invulnerable players
  457. //=====================================================================
  458. public static int modifySplit(Player player, String[] args)
  459. {
  460. //Exploit fix for people giving themselves commands
  461. if(args[1].equals("commands"))
  462. return EXIT_FAIL;
  463. else if (args[1].equals("tag"))
  464. playerTag(player, args);
  465. return EXIT_CONTINUE;
  466. }
  467. //=====================================================================
  468. //Function: playerTag (/modify player tag *)
  469. //Input: Player player: The player using the command
  470. // String[] args: Player, Command, Arguments
  471. //Output: int: Exit Code
  472. //Use: List all invulnerable players
  473. //=====================================================================
  474. public static int playerTag(Player player, String[] args)
  475. {
  476. return EXIT_SUCCESS;
  477. }
  478. //Disable using /modify to add commands (need to make a boolean settings for this)
  479. //ezlist
  480. //ezmodo
  481. /*
  482. //Promote
  483. if (vminecraftSettings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) {
  484. if(split.length != 2)
  485. {
  486. player.sendMessage(Colors.Rose + "Usage is /promote [Player]");
  487. }
  488. Player playerTarget = null;
  489. if(split.length==2){
  490. for( Player p : etc.getServer().getPlayerList())
  491. {
  492. if (p.getName().equalsIgnoreCase(split[1]))
  493. {
  494. playerTarget = p;
  495. }
  496. }
  497. if( playerTarget!=null)
  498. {
  499. String playerTargetGroup[] = playerTarget.getGroups();
  500. String playerGroup[] = player.getGroups();
  501. player.sendMessage("Debug data:");
  502. player.sendMessage("PlayerTarget: "+playerTargetGroup[0]);
  503. player.sendMessage("Player: "+playerGroup[0]);
  504. if(playerTargetGroup[0].equals("admins"))
  505. {
  506. player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher.");
  507. }
  508. if(playerTargetGroup[0].equals("mods") && (playerGroup[0].equals("owner")))
  509. {
  510. playerTarget.setGroups(ranks.Admins);
  511. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  512. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin";
  513. other.gmsg(message);
  514. }
  515. else if (playerTargetGroup[0].equals("trusted") && (playerGroup[0].equals("admins") || playerGroup[0].equals("owner")))
  516. {
  517. playerTarget.setGroups(ranks.Mods);
  518. playerTargetGroup[0]="Mods";
  519. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  520. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod";
  521. other.gmsg(message);
  522. }
  523. else if (playerTargetGroup[0].equals("default") && (playerGroup[0].equals("mods") || playerGroup[0].equals("admins") || player.isInGroup("owner")))
  524. {
  525. playerTarget.setGroups(ranks.Trusted);
  526. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  527. String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted";
  528. other.gmsg(message);
  529. }
  530. return true;
  531. }
  532. else{
  533. player.sendMessage(Colors.Rose + "Player not found");
  534. }
  535. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  536. }
  537. }
  538. //Demote
  539. if (vminecraftSettings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
  540. {
  541. if(split.length != 2)
  542. {
  543. player.sendMessage(Colors.Rose + "Usage is /demote [Player]");
  544. }
  545. Player playerTarget = null;
  546. for( Player p : etc.getServer().getPlayerList())
  547. {
  548. if (p.getName().equalsIgnoreCase(split[1]))
  549. {
  550. playerTarget = p;
  551. }
  552. }
  553. if( playerTarget!=null)
  554. {
  555. if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins")))
  556. {
  557. playerTarget.setGroups(ranks.Mods);
  558. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  559. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod";
  560. other.gmsg(message);
  561. }
  562. if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
  563. {
  564. playerTarget.setGroups(ranks.Trusted);
  565. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  566. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted";
  567. other.gmsg(message);
  568. }
  569. else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins")))
  570. {
  571. playerTarget.setGroups(ranks.Def);
  572. etc.getInstance().getDataSource().modifyPlayer(playerTarget);
  573. String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default";
  574. other.gmsg(message);
  575. }
  576. else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
  577. {
  578. player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower.");
  579. }
  580. }
  581. else{
  582. player.sendMessage(Colors.Rose + "Player not found");
  583. }
  584. log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
  585. return true;
  586. }*/
  587. }
  588. //=====================================================================
  589. //Class: commandList
  590. //Use: The list of commands that will be checked for
  591. //Author: cerevisiae
  592. //=====================================================================
  593. class commandList {
  594. command[] commands;
  595. protected static final Logger log = Logger.getLogger("Minecraft");
  596. static final int EXIT_FAIL = 0,
  597. EXIT_SUCCESS = 1,
  598. EXIT_CONTINUE = 2;
  599. //=====================================================================
  600. //Function: commandList
  601. //Input: None
  602. //Output: None
  603. //Use: Initialize the array of commands
  604. //=====================================================================
  605. public commandList(){
  606. commands = new command[0];
  607. }
  608. //=====================================================================
  609. //Function: register
  610. //Input: String name: The name of the command
  611. // String func: The function to be called
  612. //Output: boolean: Whether the command was input successfully or not
  613. //Use: Registers a command to the command list for checking later
  614. //=====================================================================
  615. public boolean register(String name, String func){
  616. //If the command list isn't empty
  617. if(commands.length > 0)
  618. {
  619. //Check to make sure the command doesn't already exist
  620. for(int i = 0; i < commands.length; i++)
  621. if(commands[i].getName().equalsIgnoreCase(name))
  622. return false;
  623. //Create a new temp array
  624. command[] temp = new command[commands.length + 1];
  625. //Copy the old command list over
  626. System.arraycopy(commands, 0, temp, 0, commands.length);
  627. //Set commands to equal the new array
  628. commands = temp;
  629. } else {
  630. commands = new command[1];
  631. }
  632. //Add the new function to the list
  633. commands[commands.length - 1] = new command(name, func);
  634. //exit successfully
  635. return true;
  636. }
  637. //=====================================================================
  638. //Function: register
  639. //Input: String name: The name of the command
  640. // String func: The function to be called
  641. // String info: The information for the command to put in help
  642. //Output: boolean: Whether the command was input successfully or not
  643. //Use: Registers a command to the command list for checking later
  644. //=====================================================================
  645. public boolean register(String name, String func, String info){
  646. //Add to the /help list
  647. etc.getInstance().addCommand(name, info);
  648. //Finish registering
  649. return register(name, func);
  650. }
  651. //=====================================================================
  652. //Function: register
  653. //Input: String name: The name of the command
  654. // String func: The function to be called
  655. //Output: boolean: Whether the command was input successfully or not
  656. //Use: Registers a command to the command list for checking later
  657. //=====================================================================
  658. public boolean registerAlias(String name, String com, String[] args){
  659. //If the command list isn't empty
  660. if(commands.length > 0)
  661. {
  662. //Check to make sure the command doesn't already exist
  663. for(int i = 0; i < commands.length; i++)
  664. if(commands[i].getName().equalsIgnoreCase(name))
  665. return false;
  666. //Create a new temp array
  667. command[] temp = new command[commands.length + 1];
  668. //Copy the old command list over
  669. System.arraycopy(commands, 0, temp, 0, commands.length);
  670. //Set commands to equal the new array
  671. commands = temp;
  672. } else {
  673. commands = new command[1];
  674. }
  675. //Add the new function to the list
  676. commands[commands.length - 1] = new commandRef(name, com, args);
  677. //exit successfully
  678. return true;
  679. }
  680. //=====================================================================
  681. //Function: register
  682. //Input: String name: The name of the command
  683. // String func: The function to be called
  684. //Output: boolean: Whether the command was input successfully or not
  685. //Use: Registers a command to the command list for checking later
  686. //=====================================================================
  687. public boolean registerAlias(String name, String com){
  688. //If the command list isn't empty
  689. if(commands.length > 0)
  690. {
  691. //Check to make sure the command doesn't already exist
  692. for(int i = 0; i < commands.length; i++)
  693. if(commands[i].getName().equalsIgnoreCase(name))
  694. return false;
  695. //Create a new temp array
  696. command[] temp = new command[commands.length + 1];
  697. //Copy the old command list over
  698. System.arraycopy(commands, 0, temp, 0, commands.length);
  699. //Set commands to equal the new array
  700. commands = temp;
  701. } else {
  702. commands = new command[1];
  703. }
  704. //Add the new function to the list
  705. commands[commands.length - 1] = new commandRef(name, com);
  706. //exit successfully
  707. return true;
  708. }
  709. //=====================================================================
  710. //Function: call
  711. //Input: String name: The name of the command to be run
  712. //Output: boolean: If the command was called successfully
  713. //Use: Attempts to call a command
  714. //=====================================================================
  715. public int call(String name, Player player, String[] arg){
  716. //Make sure the user has access to the command
  717. if(!player.canUseCommand(name)) {
  718. return EXIT_FAIL;
  719. }
  720. //Search for the command
  721. for(command cmd : commands)
  722. {
  723. //When found
  724. if(cmd.getName().equalsIgnoreCase(name))
  725. {
  726. try {
  727. //Call the command and return results
  728. return cmd.call(player, arg);
  729. } catch (SecurityException e) {
  730. log.log(Level.SEVERE, "Exception while running command", e);
  731. } catch (IllegalArgumentException e) {
  732. log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e);
  733. return EXIT_FAIL;
  734. }
  735. }
  736. }
  737. //Something went wrong
  738. return EXIT_FAIL;
  739. }
  740. //=====================================================================
  741. //Class: command
  742. //Use: The specific command
  743. //Author: cerevisiae
  744. //=====================================================================
  745. private class command{
  746. private String commandName;
  747. private String function;
  748. //=====================================================================
  749. //Function: command
  750. //Input: None
  751. //Output: None
  752. //Use: Initialize the command
  753. //=====================================================================
  754. public command(String name, String func){
  755. commandName = name;
  756. function = func;
  757. }
  758. //=====================================================================
  759. //Function: getName
  760. //Input: None
  761. //Output: String: The command name
  762. //Use: Returns the command name
  763. //=====================================================================
  764. public String getName(){return commandName;}
  765. //=====================================================================
  766. //Function: call
  767. //Input: String[] arg: The arguments for the command
  768. //Output: boolean: If the command was called successfully
  769. //Use: Attempts to call the command
  770. //=====================================================================
  771. int call(Player player, String[] arg)
  772. {
  773. Method m;
  774. try {
  775. m = vminecraftCommands.class.getMethod(function, Player.class, String[].class);
  776. m.setAccessible(true);
  777. return (Integer) m.invoke(null, player, arg);
  778. } catch (SecurityException e) {
  779. e.printStackTrace();
  780. } catch (NoSuchMethodException e) {
  781. e.printStackTrace();
  782. } catch (IllegalArgumentException e) {
  783. e.printStackTrace();
  784. } catch (IllegalAccessException e) {
  785. e.printStackTrace();
  786. } catch (InvocationTargetException e) {
  787. e.printStackTrace();
  788. }
  789. return 1;
  790. }
  791. }
  792. //=====================================================================
  793. //Class: commandRef
  794. //Use: A command referencing another command
  795. //Author: cerevisiae
  796. //=====================================================================
  797. private class commandRef extends command{
  798. private String reference;
  799. private String[] args;
  800. //=====================================================================
  801. //Function: command
  802. //Input: String name: The command name
  803. // String com: The command to run
  804. // String[] arg: the arguments to apply
  805. //Output: None
  806. //Use: Initialize the command
  807. //=====================================================================
  808. public commandRef(String name, String com, String[] arg){
  809. super(name, "");
  810. reference = com;
  811. args = arg;
  812. }
  813. //=====================================================================
  814. //Function: command
  815. //Input: String name: The command name
  816. // String com: The command to run
  817. //Output: None
  818. //Use: Initialize the command
  819. //=====================================================================
  820. public commandRef(String name, String com){
  821. super(name, "");
  822. reference = com;
  823. args = null;
  824. }
  825. //=====================================================================
  826. //Function: call
  827. //Input: String[] arg: The arguments for the command
  828. //Output: boolean: If the command was called successfully
  829. //Use: Attempts to call the command
  830. //=====================================================================
  831. int call(Player player, String[] arg)
  832. {
  833. if(args != null) {
  834. String[] temp = new String[args.length];
  835. System.arraycopy(args, 0, temp, 0, args.length);
  836. //Insert the arguments into the pre-set arguments
  837. int lastSet = 0,
  838. argCount = 0;
  839. for(String argument : temp)
  840. {
  841. if(argument.startsWith("%"))
  842. {
  843. int argNum = Integer.parseInt(argument.substring(1));
  844. if( argNum < arg.length )
  845. {
  846. temp[lastSet] = arg[argNum];
  847. argCount++;
  848. }
  849. }
  850. lastSet++;
  851. }
  852. //Append the rest of the arguments to the argument array
  853. if(lastSet < temp.length + arg.length - argCount)
  854. {
  855. String[] temp2 = new String[temp.length + arg.length - argCount];
  856. System.arraycopy(temp, 0, temp2, 0, temp.length);
  857. System.arraycopy(arg, argCount, temp2,
  858. temp.length, arg.length - argCount);
  859. temp = temp2;
  860. }
  861. //Call the referenced command
  862. player.command(reference + " " + etc.combineSplit(0, temp, " "));
  863. } else
  864. player.command(reference);
  865. return EXIT_SUCCESS;
  866. }
  867. }
  868. }