package net.zyuiop.crosspermissions.api;

import net.zyuiop.crosspermissions.api.database.RedisDatabase;
import net.zyuiop.crosspermissions.api.database.DatabaseManager;
import net.zyuiop.crosspermissions.api.permissions.PermissionGroup;
import net.zyuiop.crosspermissions.api.permissions.PermissionUser;
import net.zyuiop.crosspermissions.api.rawtypes.RawPlayer;
import net.zyuiop.crosspermissions.api.rawtypes.RawPlugin;
import net.zyuiop.crosspermissions.api.uuids.UUIDTranslator;

import java.util.UUID;

public class PermissionsAPI {

	protected RawPlugin plugin;
	protected String defGroup;
	protected DatabaseManager dbmanager = null;
	public static PermissionsAPI permissionsAPI;
    protected UUIDTranslator translator;
	
	public PermissionsAPI(RawPlugin plugin, String defGroup, RedisDatabase database) {
		this.plugin = plugin;
		plugin.logInfo("Loading PermissionsAPI");
        plugin.logInfo("Loading DBManager");
		this.dbmanager = new DatabaseManager(this, database);
		this.defGroup = defGroup;

		plugin.logInfo("Trying to recover default group " + defGroup);
		dbmanager.checkDefaultGroup(defGroup);

        this.translator = new UUIDTranslator(this);
		permissionsAPI = this;
        plugin.logInfo("Loaded PermissionsAPI successfully !");
	}

    public UUIDTranslator getTranslator() {
        return translator;
    }

    public PermissionGroup getDefGroup() {
		return dbmanager.getGroup(defGroup);
	}
	
	public RawPlugin getPlugin() {
		return plugin;
	}

	public void onPlayerJoin(RawPlayer p) {
		PermissionUser u = getUser(p.getUniqueId());
		for (String perm : u.getPermissions().keySet()) 
			p.setPermission(perm, u.getPermissions().get(perm));
		plugin.logInfo("Loaded permissions for player "+p.getUniqueId());
	}
	
	public PermissionUser getUser(UUID u) {
		return dbmanager.getUser(u);
	}
	
	public PermissionGroup getGroup(String name) {
		return dbmanager.getGroup(name);
	}

    public DatabaseManager getManager() {
        return dbmanager;
    }
}

@@ -87,86 +87,9 @@
 ase.
-RedisDatabase;%0Aimport net.zyuiop.crosspermissions.api.database.DatabaseManager
+*
 ;%0Aim
@@ -524,16 +524,17 @@
 otected 
+I
 Database
@@ -646,17 +646,16 @@
 slator;%0A
-%09
 %0A%09public
@@ -703,16 +703,17 @@
 defGroup
+n
 , RedisD
@@ -742,112 +742,26 @@
 this
-.
+(
 plugin
- = plugin;%0A%09%09plugin.logInfo(%22Loading PermissionsAPI%22);%0A        plugin.logInfo(%22Loading DBManager%22
+, defGroupn
 );%0A%09
@@ -818,36 +818,8 @@
 se);
-%0A%09%09this.defGroup = defGroup;
 %0A%0A%09%09
@@ -922,16 +922,501 @@
 Group);%0A
+%09%7D%0A%0A%09public PermissionsAPI(RawPlugin plugin, String defGroupn, SQLDatabase database) %7B%0A%09%09this(plugin, defGroupn);%0A%09%09this.dbmanager = new SQLDatabaseManager(this, database);%0A%0A%09%09plugin.logInfo(%22Trying to recover default group %22 + defGroup);%0A%09%09dbmanager.checkDefaultGroup(defGroup);%0A%09%7D%0A%0A%09private PermissionsAPI(RawPlugin plugin, String defGroup) %7B%0A%09%09this.plugin = plugin;%0A%09%09plugin.logInfo(%22Loading PermissionsAPI%22);%0A        plugin.logInfo(%22Loading DBManager%22);%0A%09%09this.defGroup = defGroup;
 %0A       
@@ -2214,16 +2214,17 @@
  public 
+I
 Database

Support SQL database