package me.stefvanschie.buildinggame.timers;

import me.stefvanschie.buildinggame.managers.files.SettingsManager;
import me.stefvanschie.buildinggame.managers.messages.MessageManager;
import me.stefvanschie.buildinggame.timers.utils.Timer;
import me.stefvanschie.buildinggame.utils.Arena;
import me.stefvanschie.buildinggame.utils.plot.Plot;

import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

public class WaitTimer extends Timer {

	private int seconds;
	private Arena arena;
	private boolean running = false;
	
	public WaitTimer(int seconds, Arena arena) {
		this.seconds = seconds;
		this.arena = arena;
	}
	
	@Override
	public void run() {
		YamlConfiguration messages = SettingsManager.getInstance().getMessages();
		
		running = true;
		if (seconds <= 0) {
			arena.start();
			running = false;
			this.cancel();
			return;
		} else if (seconds % 15 == 0 || (seconds <= 10 && seconds >= 1)) {
			for (Plot plot : arena.getUsedPlots()) {
				Player player = plot.getGamePlayer().getPlayer();
				MessageManager.getInstance().send(player, messages.getString("lobbyCountdown.message")
						.replace("%seconds%", seconds + "")
						.replace("%minutes", getMinutes() + "")
						.replace("%time%", getMinutes() + ":" + getSecondsFromMinute())
						.replace("%seconds_from_minute%", getSecondsFromMinute() + ""));
			}
		}
		for (Plot plot : arena.getUsedPlots()) {
			Player player = plot.getGamePlayer().getPlayer();
				
			player.setLevel(seconds);
		}
		seconds--;
	}
	
	@Override
	public int getSeconds() {
		return seconds;
	}
	
	@Override
	public boolean isActive() {
		return running;
	}
	
	@Override
	public void setSeconds(int seconds) {
		this.seconds = seconds;
	}
}

@@ -275,16 +275,76 @@
 e.utils.
+GamePlayer;%0Aimport me.stefvanschie.buildinggame.utils.arena.
 Arena;%0Ai
@@ -1040,31 +1040,44 @@
 ) %7B%0A%09%09%09%09
+for (Game
 Player 
-p
+gameP
 layer 
-=
+:
  plot.ge
@@ -1079,34 +1079,70 @@
 ot.getGamePlayer
+s
 ()
+) %7B%0A%09%09%09%09%09Player player = gamePlayer
 .getPlayer();%0A%09%09
@@ -1135,24 +1135,25 @@
 etPlayer();%0A
+%09
 %09%09%09%09MessageM
@@ -1229,32 +1229,33 @@
 message%22)%0A%09%09%09%09%09%09
+%09
 .replace(%22%25secon
@@ -1270,24 +1270,25 @@
 conds + %22%22)%0A
+%09
 %09%09%09%09%09%09.repla
@@ -1319,32 +1319,33 @@
 s() + %22%22)%0A%09%09%09%09%09%09
+%09
 .replace(%22%25time%25
@@ -1392,16 +1392,17 @@
 nute())%0A
+%09
 %09%09%09%09%09%09.r
@@ -1471,14 +1471,20 @@
 %0A%09%09%09
+%09
 %7D%0A
+%09
 %09%09%7D%0A
+%09%09%7D%0A
 %09%09fo
@@ -1525,31 +1525,44 @@
 )) %7B%0A%09%09%09
+for (Game
 Player 
-p
+gameP
 layer 
-=
+:
  plot.ge
@@ -1572,18 +1572,53 @@
 mePlayer
+s
 ()
+) %7B%0A%09%09%09%09Player player = gamePlayer
 .getPlay
@@ -1628,16 +1628,17 @@
 );%0A%09%09%09%09%0A
+%09
 %09%09%09playe
@@ -1658,16 +1658,21 @@
 conds);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%09se

Update WaitTimer.java