/jump/src/Jump.java

https://github.com/ricin/minecraft-hey0-plugins · Java · 142 lines · 97 code · 45 blank · 0 comment · 22 complexity · 3bfa44a5f946d510ccbbd321cc087b6e MD5 · raw file

  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5. public class Jump extends Plugin {
  6. private JumpListener listener = new JumpListener();
  7. static final Logger log = Logger.getLogger("Minecraft");
  8. public void enable() {
  9. log.info("[Jump] Mod Enabled.");
  10. etc.getInstance().addCommand("/jump", "<Username> - Request a jump to a player");
  11. etc.getInstance().addCommand("/accept", "<Username> - Accept a jump from a player");
  12. }
  13. public void disable() {
  14. etc.getInstance().removeCommand("/jump");
  15. etc.getInstance().removeCommand("/accept");
  16. log.info("[Jump] Mod Disabled");
  17. }
  18. public void initialize() {
  19. etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
  20. }
  21. public class JumpListener extends PluginListener
  22. {
  23. public boolean onCommand(Player player, String[] split) {
  24. if (!player.canUseCommand(split[0])) {
  25. return false;
  26. }
  27. if (split[0].equalsIgnoreCase("/jump")) {
  28. if (split.length < 2) {
  29. player.sendMessage(Colors.Red + split[0] + " <Username>");
  30. return true;
  31. }
  32. Player destplayer = etc.getServer().matchPlayer(split[1]);
  33. if (destplayer != null) {
  34. if (destplayer.getName().equalsIgnoreCase(player.getName())) {
  35. player.sendMessage(Colors.Rose + "You're already here!");
  36. return true;
  37. }
  38. if (etc.getServer().isTimerExpired(player.getName().toLowerCase() + destplayer.getName().toLowerCase())) {
  39. player.sendMessage(Colors.Red + "You can request a jump to a player once every 30 seconds");
  40. return true;
  41. }
  42. else
  43. {
  44. destplayer.sendMessage(Colors.Red + player.getName() + " wants to jump to your location. Use the command /accept " + player.getName() + " to accept, you have 30 seconds.");
  45. player.sendMessage(Colors.Red + "Request sent to " + destplayer.getName() + ".");
  46. etc.getServer().setTimer(player.getName().toLowerCase() + destplayer.getName().toLowerCase(), 500);
  47. return true;
  48. }
  49. } else {
  50. player.sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
  51. return true;
  52. }
  53. } else if (split[0].equalsIgnoreCase("/accept")) {
  54. if (split.length < 2) {
  55. player.sendMessage(Colors.Red + split[0] + " <Username>");
  56. return true;
  57. }
  58. Player sourceplayer = etc.getServer().matchPlayer(split[1]);
  59. if (sourceplayer != null) {
  60. if (sourceplayer.getName().equalsIgnoreCase(player.getName())) {
  61. player.sendMessage(Colors.Rose + "You're already here!");
  62. return true;
  63. }
  64. if (! etc.getServer().isTimerExpired(sourceplayer.getName().toLowerCase() + player.getName().toLowerCase()))
  65. {
  66. player.sendMessage(Colors.Red + "FAILED: The player must request a teleport and you must respond within 30 seconds");
  67. return true;
  68. }
  69. else {
  70. sourceplayer.teleportTo((BaseEntity)player);
  71. sourceplayer.sendMessage(Colors.Red + "Woosh!");
  72. etc.getServer().setTimer(sourceplayer.getName().toLowerCase() + player.getName().toLowerCase(), 1);
  73. return true;
  74. }
  75. } else {
  76. player.sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
  77. return true;
  78. }
  79. }
  80. else {
  81. return false;
  82. }
  83. }
  84. }
  85. public List<Player> getPlayersWithPrefix(String playerName)
  86. {
  87. List<Player> players = new ArrayList<Player>();
  88. for (Player p : etc.getServer().getPlayerList()) {
  89. if (p != null) {
  90. if (p.getName().toLowerCase().startsWith(playerName)) {
  91. players.add(p);
  92. }
  93. }
  94. }
  95. return players;
  96. }
  97. }