Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.vinum.colorrush.game;
- import java.util.ArrayList;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.entity.Player;
- import me.vinum.colorrush.ColorRush;
- public class Game {
- String mapName;
- int countdownRunnable = 404;
- public void startCountdown(int time) {
- if(countdownRunnable == 404) {
- return;
- }
- countdownRunnable = Bukkit.getScheduler().scheduleSyncRepeatingTask(ColorRush.colorRush, new Runnable() {
- int timer = time;
- @Override
- public void run() {
- if(timer == 120 || timer == 60 || timer == 30 || timer == 15 || timer == 10 || timer == 5 || timer == 4 || timer == 3 || timer == 120 || timer == 2 || timer == 1) {
- for(Player player : Bukkit.getOnlinePlayers()) {
- if(timer == 1) {
- player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lCOLOR RUSH &8&l| &bThe game will start in &3" + timer + " &bsecond"));
- }else {
- player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lCOLOR RUSH &8&l| &bThe game will start in &3" + timer + " &bseconds"));
- }
- }
- }
- if(timer <= 0) {
- Bukkit.getScheduler().cancelTask(countdownRunnable);
- startGame();
- }
- }
- }, 0, 20);
- }
- void startGame() {
- // teleports players in
- ArrayList<Location> spawns = new ArrayList<Location>();
- for(String spawn : ColorRush.colorRush.getConfig().getStringList("map." + mapName + ".spawns")) {
- String[] split = spawn.split(",");
- World world = Bukkit.getWorld(split[0]);
- int x = Integer.parseInt(split[1]);
- int y = Integer.parseInt(split[2]);
- int z = Integer.parseInt(split[3]);
- spawns.add(new Location(world, x, y, z));
- }
- Random rand = new Random();
- for(Player player : Bukkit.getOnlinePlayers()) {
- Location randomSpawn = spawns.get(rand.nextInt(spawns.size()));
- player.teleport(randomSpawn);
- player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9&lCOLOR RUSH &8&l| &bThe game has started!"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement