package de.st_ddt.crazyutil.modules.login;

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

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import de.st_ddt.crazyutil.modules.Module;

public class LoginModule implements Module
{

	public final static List<Class<? extends LoginSystem>> LOGINSYSTEMS = new ArrayList<Class<? extends LoginSystem>>();
	static
	{
		LOGINSYSTEMS.add(NoLoginSystem.class);
	}
	private static LoginSystem loginModule;

	public static void init(final String chatHeader, final CommandSender sender)
	{
		if (loginModule == null)
			new LoginModule().initialize(chatHeader, sender);
	}

	public LoginSystem getLoginSystem()
	{
		return loginModule;
	}

	public static void setPermissionModule(final LoginSystem loginModule)
	{
		LoginModule.loginModule = loginModule;
	}

	public static boolean hasAccount(final OfflinePlayer player)
	{
		return loginModule.hasAccount(player);
	}

	public static boolean isLoggedIn(final Player player)
	{
		return loginModule.isLoggedIn(player);
	}

	public LoginModule()
	{
		super();
		MODULES.put("login", this);
	}

	@Override
	public boolean initialize(final String chatHeader, final CommandSender sender)
	{
		sender.sendMessage(chatHeader + "Checking login modules:");
		for (final Class<? extends LoginSystem> clazz : LOGINSYSTEMS)
		{
			final String name = clazz.getAnnotation(Named.class).name();
			sender.sendMessage(chatHeader + ChatColor.YELLOW + "- " + name);
			if (registerLoginModule(clazz))
			{
				sender.sendMessage(chatHeader + "Activated " + ChatColor.GREEN + loginModule.getName() + ChatColor.WHITE + " Login Module!");
				return true;
			}
		}
		return false;
	}

	public static boolean registerLoginModule(final Class<? extends LoginSystem> clazz)
	{
		final PluginDepency plugin = clazz.getAnnotation(PluginDepency.class);
		if (plugin != null)
			if (Bukkit.getPluginManager().getPlugin(plugin.depend()) == null)
				return false;
		try
		{
			loginModule = clazz.newInstance();
			return true;
		}
		catch (final Exception e)
		{
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public final String getName()
	{
		return "LoginModule";
	}

	@Override
	public boolean isActive()
	{
		return loginModule != null;
	}
}

@@ -2028,16 +2028,17 @@
 %0A%09%09%09if (
+!
 Bukkit.g
@@ -2055,25 +2055,31 @@
 nager().
-get
+is
 Plugin
+Enabled
 (plugin.
@@ -2087,24 +2087,16 @@
 epend())
- == null
 )%0D%0A%09%09%09%09r

check whether plugins are enabled instead of checking whether they are installed or not