package com.github.niwaniwa.we.core.player;

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.bukkit.configuration.serialization.ConfigurationSerializable;

import com.github.niwaniwa.we.core.json.JsonManager;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

public class AltAccount implements ConfigurationSerializable {

	private final List<String> players;

	public AltAccount() {
		this.players = new ArrayList<>();
	}

	public List<String> get(){
		return players;
	}

	public boolean add(UUID player){
		return players.add(player.toString());
	}

	public boolean contains(WhitePlayer player){
		return players.contains(player.getUniqueId().toString());
	}

	public boolean remove(Object o){
		return players.remove(o);
	}

	public static void determine(WhitePlayer player) {
		if(!(player instanceof WhiteEggPlayer)){ throw new IllegalArgumentException(String.format("Class %s does not extends WhiteEggPlayer", new Object[] { player.getClass().getSimpleName() })); }
		WhiteEggPlayer egg = (WhiteEggPlayer) player;
		for(WhitePlayer p : WhitePlayerFactory.getPlayers()){
			if(!(p instanceof WhiteEggPlayer)){ continue; }
			WhiteEggPlayer egg2 = (WhiteEggPlayer) p;
			if(getAddress(egg.getAddress()).equalsIgnoreCase(getAddress(egg2.getAddress()))){
				egg.addAccount(p);
				egg2.addAccount(egg);
//				WhiteEggSubAccountJoinEvent event = new WhiteEggSubAccountJoinEvent(egg2, egg);
//				Util.callEvent(event);
			}
		}
	}

	private static String getAddress(InetSocketAddress address){
		String[] loginAdress = address.getAddress().toString().split("/");
		loginAdress = loginAdress[1].split(":");
		return loginAdress[0];
	}

	@Override
	public String toString() {
		return this.serialize().toString();
	}

	@Override
	public Map<String, Object> serialize() {
		Map<String, Object> serialize = new HashMap<>();
		serialize.put("player", players);
		return null;
	}

	public static AltAccount parser(String jsonString){
		JsonObject json = new JsonManager().createJsonObject(jsonString);
		AltAccount alt = new AltAccount();
		JsonElement obj = json.get("account");
		if(obj == null || !obj.isJsonArray()){ return alt; }
		JsonArray array = obj.getAsJsonArray();
		array.forEach(element -> alt.add(UUID.fromString(element.getAsString())));
		return alt;
	}

}

@@ -309,24 +309,140 @@
 ore.
-json.JsonManager
+event.WhiteEggSubAccountJoinEvent;%0Aimport com.github.niwaniwa.we.core.json.JsonManager;%0Aimport com.github.niwaniwa.we.core.util.Util
 ;%0Aim
@@ -1149,117 +1149,88 @@
 ion(
-String.format(%22Class %25s does not extends WhiteEggPlayer%22, new Object%5B%5D %7B player.getClass().getSimpleName() %7D)
+%22Class %22 + player.getClass().getSimpleName() +%22 does not extends WhiteEggPlayer%22
 ); %7D
@@ -1560,26 +1560,24 @@
 count(egg);%0A
-//
 %09%09%09%09WhiteEgg
@@ -1652,10 +1652,8 @@
 g);%0A
-//
 %09%09%09%09

Change message