package com.nubebuster.hg;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import com.nubebuster.hg.kits.Kit;

public class Gamer {

	private String name;
	private UUID uuid;
	private Kit kit = Kit.getKitFromName("None");
	private boolean alive = false;

	private Gamer(Player player) {
		this.name = player.getName();
		this.uuid = player.getUniqueId();
		gamers.add(this);
	}

	public Kit getKit() {
		return kit;
	}

	public Player getPlayer() {
		return Bukkit.getPlayer(uuid);
	}

	public void setKit(Kit kit) {
		this.kit = kit;
	}

	public String getName() {
		return name;
	}

	public UUID getUUID() {
		return uuid;
	}

	public boolean isAlive() {
		return alive;
	}

	public void setAlive(boolean alive) {
		this.alive = alive;
	}

	public void remove() {
		gamers.remove(this);
	}

	private static final List<Gamer> gamers = new ArrayList<Gamer>();

	public static Gamer getGamer(Player p) {
		for (Gamer g : gamers)
			if (g.getName().equalsIgnoreCase(p.getName()))
				return g;
		return new Gamer(p);
	}

	/**
	 * @deprecated use getGamer(UUID) instead
	 */
	@Deprecated
	public static Gamer getGamer(String name) {
		for (Gamer g : gamers)
			if (g.getName().equalsIgnoreCase(name))
				return g;
		return null;
	}

	public static Gamer getGamer(UUID id) {
		for (Gamer g : gamers)
			if (g.getPlayer().getUniqueId().equals(id))
				return g;
		return null;
	}

	public static List<Gamer> getGamers() {
		return gamers;
	}

	public static List<Gamer> getAliveGamers() {
		List<Gamer> alive = new ArrayList<Gamer>();
		boolean started = HG.HG.gameTime > -1;
		for (Gamer g : gamers)
			if (started ? g.isAlive() : g.getPlayer().getGameMode() == GameMode.SURVIVAL)
				alive.add(g);
		return alive;
	}

	public void applyKit() {
		if (kit.getItems() != null)
			for (ItemStack is : kit.getItems())
				getPlayer().getInventory().addItem(is);
	}
}

@@ -45,24 +45,79 @@
 .ArrayList;%0A
+import java.util.Collection;%0Aimport java.util.HashMap;%0A
 import java.
@@ -567,20 +567,26 @@
 %09gamers.
-add(
+put(uuid, 
 this);%0A%09
@@ -991,28 +991,28 @@
 .remove(
-this
+uuid
 );%0A%09%7D%0A%0A%09
 private 
@@ -1003,16 +1003,19 @@
 );%0A%09%7D%0A%0A%09
+// 
 private 
@@ -1073,16 +1073,97 @@
 er%3E();%0A%0A
+%09private static final HashMap%3CUUID, Gamer%3E gamers = new HashMap%3CUUID, Gamer%3E();%0A%0A
 %09public 
@@ -1194,37 +1194,32 @@
 ayer p) %7B%0A%09%09
-for (
 Gamer g 
 : gamers)%0A%09%09
@@ -1210,90 +1210,63 @@
 r g 
-:
+=
  gamers
-)%0A%09%09%09if (g.getName().equalsIgnoreCase(p.getName()))%0A%09%09%09%09return g;%0A%09%09return
+.get(p.getUniqueId());%0A%09%09return g != null ? g :
  new
@@ -1406,32 +1406,41 @@
 Gamer g : gamers
+.values()
 )%0A%09%09%09if (g.getNa
@@ -1548,105 +1548,29 @@
 %7B%0A%09%09
-for (Gamer g : gamers)%0A%09%09%09if (g.getPlayer().getUniqueId().equals(id))%0A%09%09%09%09return g;%0A%09%09return null
+return gamers.get(id)
 ;%0A%09%7D
@@ -1578,36 +1578,42 @@
 %0A%09public static 
-List
+Collection
 %3CGamer%3E getGamer
@@ -1633,16 +1633,25 @@
 n gamers
+.values()
 ;%0A%09%7D%0A%0A%09p
@@ -1804,16 +1804,25 @@
 : gamers
+.values()
 )%0A%09%09%09if 

Update 1.12