package team.unstudio.udpl.util;

import java.util.Map;
import java.util.Set;

import javax.annotation.Nonnull;

import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;

import com.google.common.collect.Sets;

import team.unstudio.udpl.core.UDPLib;

public final class CacheUtils {
	
	private CacheUtils(){}
	
	private static Set<Map<Player,?>> PLAYER_CACHES = Sets.newHashSet();
	
	public static void initCacheUtils(){
		Bukkit.getPluginManager().registerEvents(new CacheListener(), UDPLib.getInstance());
	}
	
	public static void registerPlayerCache(@Nonnull Map<Player,?> cache){
		Validate.notNull(cache);
		PLAYER_CACHES.add(cache);
	}
	
	public static void unregisterPlayerCache(@Nonnull Map<Player,?> cache){
		Validate.notNull(cache);
		PLAYER_CACHES.remove(cache);
	}
	
	private static class CacheListener implements Listener{
		
		@EventHandler(priority=EventPriority.MONITOR)
		public void onQuit(PlayerQuitEvent event){
			Player player = event.getPlayer();
			CacheUtils.PLAYER_CACHES.forEach(cache->cache.remove(player));
		}
	}
}

@@ -25,24 +25,54 @@
 pl.util;%0D%0A%0D%0A
+import java.util.Collection;%0D%0A
 import java.
@@ -597,24 +597,115 @@
 ,?%3E%3E PLAYER_
+MAP_CACHES = Sets.newHashSet();%0D%0A%09private static Set%3CCollection%3CPlayer%3E%3E PLAYER_COLLECTION_
 CACHES = Set
@@ -971,145 +971,462 @@
 YER_
-CACHES.add(cache);%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void unregisterPlayerCache(@Nonnull Map%3CPlayer,?%3E cache)%7B%0D%0A%09%09Validate.notNull(cache);%0D%0A%09%09PLAYER
+MAP_CACHES.add(cache);%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void registerPlayerCache(@Nonnull Collection%3CPlayer%3E cache)%7B%0D%0A%09%09Validate.notNull(cache);%0D%0A%09%09PLAYER_COLLECTION_CACHES.add(cache);%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void unregisterPlayerCache(@Nonnull Map%3CPlayer,?%3E cache)%7B%0D%0A%09%09Validate.notNull(cache);%0D%0A%09%09PLAYER_MAP_CACHES.remove(cache);%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void unregisterPlayerCache(@Nonnull Collection%3CPlayer%3E cache)%7B%0D%0A%09%09Validate.notNull(cache);%0D%0A%09%09PLAYER_COLLECTION
 _CAC
@@ -1655,25 +1655,85 @@
 %0A%09%09%09
-CacheUtils.PLAYER
+PLAYER_MAP_CACHES.forEach(cache-%3Ecache.remove(player));%0D%0A%09%09%09PLAYER_COLLECTION
 _CAC

Update CacheUtils