Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. package de.ttt.countdowns;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Sound;
  5. import org.bukkit.entity.Player;
  6.  
  7. import de.ttt.gamestates.GameState;
  8. import de.ttt.gamestates.GameStateManager;
  9. import de.ttt.gamestates.LobbyState;
  10. import de.ttt.main.Main;
  11. import me.ttt.utils.Title;
  12.  
  13. public class LobbyCountdown extends Countdown {
  14.  
  15. private static final int CONTDOWN_TIME = 60, IDLE_TIME = 20;
  16.  
  17. private GameStateManager gameStateManager;
  18.  
  19. private int seconds;
  20. private boolean isRunning;
  21. private int idleID;
  22. private boolean isIdling;
  23. private boolean isStarting;
  24.  
  25. public LobbyCountdown(GameStateManager gameStateManager) {
  26. this.gameStateManager = gameStateManager;
  27. seconds = 61;
  28. }
  29.  
  30. @Override
  31. public void start() {
  32. for(Player all : Bukkit.getOnlinePlayers()) {
  33. isRunning = true;
  34. taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(gameStateManager.getPlugin(), new Runnable() {
  35.  
  36. @Override
  37. public void run() {
  38. if(seconds >= 1)
  39. all.setLevel(seconds);
  40. all.setExp((float)seconds / 60);
  41. switch(seconds) {
  42. case 60: case 30: case 15: case 10: case 5: case 4: case 3: case 2:
  43. all.sendMessage(Main.PREFIX + "§7Das Spiel startet in §a" + seconds + " §7Sekunden§7.");
  44. all.playSound(all.getLocation(), Sound.NOTE_PLING, 1, 1);
  45. Title.sendTitle(all, 5, 10, 5, "§a" + seconds, "§4");
  46. if(seconds == 15)
  47. isStarting = true;
  48. break;
  49. case 1:
  50. all.sendMessage(Main.PREFIX + "§7Das Spiel startet in §aeiner §7Sekunde§7.");
  51. all.playSound(all.getLocation(), Sound.NOTE_PLING, 1, 1);
  52. break;
  53. case 0:
  54. gameStateManager.setGameState(GameState.INGAME_STATE);
  55. break;
  56.  
  57. default:
  58. break;
  59. }
  60. seconds --;
  61. }
  62. }, 0, 20);
  63. }
  64. }
  65.  
  66. @Override
  67. public void stop() {
  68. if(isRunning) {
  69. Bukkit.getScheduler().cancelTask(taskID);
  70. isRunning = false;
  71. seconds = CONTDOWN_TIME;
  72. }
  73. }
  74.  
  75. public void startIdle() {
  76. for(Player all : Bukkit.getOnlinePlayers()) {
  77. isIdling = true;
  78. idleID = Bukkit.getScheduler().scheduleSyncRepeatingTask(gameStateManager.getPlugin(), new Runnable() {
  79.  
  80. @Override
  81. public void run() {
  82. int missingPlayers = LobbyState.MIN_PLAYERS - gameStateManager.getPlugin().getPlayers().size();
  83. if(missingPlayers != 1)
  84. all.sendMessage(Main.PREFIX + "§cEs fehlen noch §6" + missingPlayers + " Spieler §cbis zum Start!");
  85. else
  86. all.sendMessage(Main.PREFIX + "§cEs fehlt noch §6ein Spieler §cbis zum Start!");
  87. }
  88. }, 0, IDLE_TIME * 20);
  89. }
  90. }
  91.  
  92. public void stopIdle() {
  93. if(isIdling) {
  94. Bukkit.getScheduler().cancelTask(idleID);
  95. isIdling = false;
  96. }
  97. }
  98.  
  99. public boolean isRunning() {
  100. return isRunning;
  101. }
  102.  
  103. public boolean isStarting() {
  104. return isStarting;
  105. }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement