Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. package me.vinum.colorrush.game;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Location;
  9. import org.bukkit.World;
  10. import org.bukkit.entity.Player;
  11.  
  12. import me.vinum.colorrush.ColorRush;
  13.  
  14. public class Game {
  15.  
  16. String mapName;
  17. int countdownRunnable = 404;
  18.  
  19. public void startCountdown(int time) {
  20. if(countdownRunnable == 404) {
  21. return;
  22. }
  23. countdownRunnable = Bukkit.getScheduler().scheduleSyncRepeatingTask(ColorRush.colorRush, new Runnable() {
  24.  
  25. int timer = time;
  26.  
  27. @Override
  28. public void run() {
  29. if(timer == 120 || timer == 60 || timer == 30 || timer == 15 || timer == 10 || timer == 5 || timer == 4 || timer == 3 || timer == 120 || timer == 2 || timer == 1) {
  30. for(Player player : Bukkit.getOnlinePlayers()) {
  31. if(timer == 1) {
  32. player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lCOLOR RUSH &8&l| &bThe game will start in &3" + timer + " &bsecond"));
  33. }else {
  34. player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lCOLOR RUSH &8&l| &bThe game will start in &3" + timer + " &bseconds"));
  35. }
  36. }
  37. }
  38. if(timer <= 0) {
  39. Bukkit.getScheduler().cancelTask(countdownRunnable);
  40. startGame();
  41. }
  42.  
  43. }
  44. }, 0, 20);
  45.  
  46. }
  47.  
  48. void startGame() {
  49. // teleports players in
  50. ArrayList<Location> spawns = new ArrayList<Location>();
  51. for(String spawn : ColorRush.colorRush.getConfig().getStringList("map." + mapName + ".spawns")) {
  52. String[] split = spawn.split(",");
  53. World world = Bukkit.getWorld(split[0]);
  54. int x = Integer.parseInt(split[1]);
  55. int y = Integer.parseInt(split[2]);
  56. int z = Integer.parseInt(split[3]);
  57. spawns.add(new Location(world, x, y, z));
  58. }
  59. Random rand = new Random();
  60. for(Player player : Bukkit.getOnlinePlayers()) {
  61. Location randomSpawn = spawns.get(rand.nextInt(spawns.size()));
  62. player.teleport(randomSpawn);
  63. player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lCOLOR RUSH &8&l| &bThe game has started!"));
  64. }
  65.  
  66. }
  67.  
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement