vminecraftCommands.java 32 KB

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