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

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

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import com.github.niwaniwa.we.core.WhiteEggCore;
import com.github.niwaniwa.we.core.player.OfflineWhitePlayer;
import com.github.niwaniwa.we.core.player.WhitePlayer;
import com.github.niwaniwa.we.core.player.WhitePlayerFactory;
import com.github.niwaniwa.we.core.player.rank.Rank;
import com.github.niwaniwa.we.core.twitter.ServerTwitterManager;
import com.github.niwaniwa.we.core.util.Util;

/**
 * WhiteEggAPIの実装クラス
 * @author niwaniwa
 *
 */
public class WhiteEggAPIImpl {

	public WhiteEggAPIImpl() {
	}


	public List<WhitePlayer> getOnlinePlayers() {
		List<WhitePlayer> result = new ArrayList<>();
		for(Player p : Bukkit.getOnlinePlayers()){
			result.add(WhitePlayerFactory.getInstance(p));
		}
		return result;
	}


	public List<Rank> getRanks() {
		return Rank.getRanks();
	}


	public void RankBroadcastMessage(Rank rank, String message) {
		WhiteEggAPI.getOnlinePlayers().stream()
						.filter(p -> p.getRanks().contains(rank))
						.forEach(p -> p.sendMessage(message));
	}


	public void WorldBroadcastMessage(World world, String message) {
		world.getPlayers().forEach(p -> p.sendMessage(message));
	}


	public OfflineWhitePlayer getOfflinePlayer(String name) {
		@SuppressWarnings("deprecation")
		OfflinePlayer offline = Bukkit.getOfflinePlayer(name);
		return WhitePlayerFactory.getInstance((Player) offline);
	}


	public WhitePlayer getPlayer(String name) {
		Player player = Util.getOnlinePlayer(name);
		if(player == null){
			return null;
		}
		return WhitePlayerFactory.getInstance(player);
	}


	public WhitePlayer getPlayer(UUID uuid) {
		Player player = Util.getOnlinePlayer(uuid);
		if(player == null){
			WhitePlayer white = WhitePlayerFactory.getInstance((Player) Bukkit.getPlayer(uuid));
			return white;
		}
		return WhitePlayerFactory.getInstance(player);
	}


	public WhitePlayer getPlayer(Player player) {
		return WhitePlayerFactory.getInstance(player);
	}

	@Deprecated

	public boolean registerToggle(Plugin plugin, String tag, String permission, String custam,
			Map<String, Object> toggles, boolean isHide) {
		return false;
	}


	public boolean useDataBase() {
		return WhiteEggCore.getConf().useDataBase();
	}


	public void tweet(String tweet) {
		ServerTwitterManager.getInstance().tweet(tweet);
	}


}

@@ -1600,24 +1600,207 @@
 nce(
-(Player) offline
+offline.getPlayer());%0A%09%7D%0A%0A%09public OfflineWhitePlayer getOfflinePlayer(UUID uuid) %7B%0A%09%09OfflinePlayer offline = Bukkit.getOfflinePlayer(uuid);%0A%09%09return WhitePlayerFactory.getInstance(offline.getPlayer()
 );%0A%09
@@ -2104,116 +2104,22 @@
 ll)%7B
-%0A%09%09%09WhitePlayer white = WhitePlayerFactory.getInstance((Player) Bukkit.getPlayer(uuid));%0A%09%09%09return white;%0A%09%09
+ return null; 
 %7D%0A%09%09

Fix get offlineplayer - オフラインプレイヤーの取得時にエラーをはかれる問題を修正