package com.lactem.pvz.tasks;

import java.util.Iterator;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;

import com.lactem.pvz.game.Game;
import com.lactem.pvz.main.Main;

public class GameRunnable implements Runnable {
	public int id;
	public Game game;

	@Override
	public void run() {
		try {
			game.setTimeLeft(game.getTimeLeft() - 1);
			Objective objective = game.getBoard().getObjective(
					DisplaySlot.SIDEBAR);
			game.getBoard().resetScores(
					Bukkit.getOfflinePlayer((game.getTimeLeft() + 1)
							+ " seconds"));
			int num = 0;
			for (int i = 0; i < game.getRows().size(); i++) {
				if (!game.getRows().get(i).isEndpointTaken())
					num++;
			}
			game.getBoard()
					.resetScores(Bukkit.getOfflinePlayer("" + (num + 1)));
			Score time = objective.getScore(Bukkit.getOfflinePlayer(ChatColor
					.translateAlternateColorCodes('&', "&lTime Remaining")));
			time.setScore(4);
			Score intTime = objective.getScore(Bukkit.getOfflinePlayer(game
					.getTimeLeft() + " seconds"));
			intTime.setScore(3);
			Score endpoints = objective.getScore(Bukkit
					.getOfflinePlayer(ChatColor.translateAlternateColorCodes(
							'&', "&lRows Remaining")));
			endpoints.setScore(2);
			Score numEnds = objective.getScore(Bukkit
					.getOfflinePlayer("" + num));
			numEnds.setScore(1);
		} catch (NullPointerException e) {
		}
		if (game.getTimeLeft() <= 0) {
			Main.gameManager.endGame(game, true);
			Bukkit.getServer().getScheduler().cancelTask(id);
		}
		Iterator<UUID> i = game.getPlants().getMembers().keySet().iterator();
		while (i.hasNext()) {
			UUID uuid = i.next();
			for (Player player : Bukkit.getServer().getOnlinePlayers()) {
				update(player, uuid);
			}
		}
		Iterator<UUID> i2 = game.getZombies().getMembers().keySet().iterator();
		while (i2.hasNext()) {
			UUID uuid = i2.next();
			for (Player player : Bukkit.getServer().getOnlinePlayers()) {
				update(player, uuid);
			}
		}
	}

	private void update(Player player, UUID uuid) {
		if (player.getUniqueId() == uuid) {
			player.setFoodLevel(20);
			player.setScoreboard(game.getBoard());
		}
	}
}
@@ -641,32 +641,8 @@
 %09%09%09%09
-Bukkit.getOfflinePlayer(
 (gam
@@ -674,33 +674,32 @@
 %09%09%09+ %22 seconds%22)
-)
 ;%0A%09%09%09int num = 0
@@ -861,32 +861,8 @@
 res(
-Bukkit.getOfflinePlayer(
 %22%22 +
@@ -872,17 +872,16 @@
 um + 1))
-)
 ;%0A%09%09%09Sco
@@ -913,32 +913,8 @@
 ore(
-Bukkit.getOfflinePlayer(
 Chat
@@ -975,25 +975,24 @@
 Remaining%22))
-)
 ;%0A%09%09%09time.se
@@ -1044,32 +1044,8 @@
 ore(
-Bukkit.getOfflinePlayer(
 game
@@ -1078,17 +1078,16 @@
 econds%22)
-)
 ;%0A%09%09%09int
@@ -1148,38 +1148,8 @@
 ore(
-Bukkit%0A%09%09%09%09%09.getOfflinePlayer(
 Chat
@@ -1216,17 +1216,16 @@
 ining%22))
-)
 ;%0A%09%09%09end
@@ -1286,38 +1286,8 @@
 ore(
-Bukkit%0A%09%09%09%09%09.getOfflinePlayer(
 %22%22 +
@@ -1291,17 +1291,16 @@
 %22 + num)
-)
 ;%0A%09%09%09num

Update deprecated scoreboard