package fr.aumgn.dac2.stage;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;

import fr.aumgn.dac2.arena.Arena;

public class JoinStage implements Stage, Listener {

    private final Arena arena;

    public JoinStage(Arena arena) {
        this.arena = arena;
    }

    @Override
    public Arena getArena() {
        return arena;
    }

    @Override
    public void start() {
    }

    @Override
    public void stop() {
    }

    @Override
    public Listener[] getListeners() {
        return new Listener[] { this };
    }

    @Override
    public boolean contains(Player player) {
        return false;
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent event) {
    }
}

@@ -23,16 +23,62 @@
 stage;%0A%0A
+import java.util.List;%0Aimport java.util.Map;%0A%0A
 import o
@@ -130,54 +130,133 @@
 ent.
-EventHandl
+Listen
 er;%0A
+%0A
 import 
-org.bukkit.event.Listener
+fr.aumgn.bukkitutils.localization.PluginMessages;%0Aimport fr.aumgn.bukkitutils.playerid.map.PlayersIdHashMap
 ;%0Aim
@@ -264,82 +264,188 @@
 ort 
-org
+fr.aumgn
 .bukkit
-.event
+utils
 .player
+id.map
 .Player
-QuitEvent;%0A%0Aimport fr.aumgn.dac2.arena.Arena
+sIdMap;%0Aimport fr.aumgn.bukkitutils.util.Util;%0Aimport fr.aumgn.dac2.DAC;%0Aimport fr.aumgn.dac2.arena.Arena;%0Aimport fr.aumgn.dac2.config.Color
 ;%0A%0Ap
@@ -496,16 +496,43 @@
 ener %7B%0A%0A
+    private final DAC dac;%0A
     priv
@@ -553,16 +553,108 @@
 a arena;
+%0A    private final Map%3CString, Color%3E colors;%0A    private final PlayersIdMap%3CColor%3E players;
 %0A%0A    pu
@@ -668,16 +668,25 @@
 inStage(
+DAC dac, 
 Arena ar
@@ -709,142 +709,514 @@
 his.
-arena = arena;%0A    %7D%0A%0A    @Override%0A    public Arena getArena() %7B%0A        return arena;%0A    %7D%0A%0A    @Override%0A    public void start() %7B
+dac = dac;%0A        this.arena = arena;%0A        this.colors = dac.getColors().toMap();%0A        this.players = new PlayersIdHashMap%3CColor%3E();%0A    %7D%0A%0A    @Override%0A    public Arena getArena() %7B%0A        return arena;%0A    %7D%0A%0A    @Override%0A    public void start() %7B%0A        PluginMessages messages = dac.getMessages();%0A        Util.broadcast(messages.get(%22joinstage.start1%22, arena.getName()));%0A                //, %22dac.game.watch%22);%0A        Util.broadcast(messages.get(%22joinstage.start2%22));//, %22dac.game.watch%22);
 %0A   
@@ -1350,18 +1350,10 @@
 ner%5B
+0
 %5D
- %7B this %7D
 ;%0A  
@@ -1435,87 +1435,732 @@
 urn 
-false;%0A    %7D%0A%0A    @EventHandler%0A    public void onQuit(PlayerQuitEvent event) %7B
+players.containsKey(player);%0A    %7D%0A%0A    public void addPlayer(Player player, List%3CString%3E colorsName) %7B%0A        Color color = null;%0A        for (String rawColorName : colorsName) %7B%0A            String colorName = rawColorName.toLowerCase();%0A            if (colors.containsKey(colorName)) %7B%0A                color = colors.get(colorName);%0A                break;%0A            %7D%0A        %7D%0A%0A        addPlayer(player, color);%0A    %7D%0A%0A    public void addPlayer(Player player, Color color) %7B%0A        if (color == null %7C%7C !colors.containsValue(color)) %7B%0A            // Get first color available%0A            color = colors.values().iterator().next();%0A        %7D%0A%0A        players.put(player, color);%0A        colors.remove(color.getName());
 %0A   

Add JoinStage