package cc.lukatown.icefox.plugincore.Functions;

import cc.lukatown.icefox.plugincore.PluginCore;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.bukkit.entity.Player;

/**
 * *******************************************
 * Created by MXD on 14-10-14.
 * for 2dmmc
 * E-mail : i@mxd.moe
 * ********************************************
 */
public class PluginCoreFunction_Permission {
    private static GroupManager groupManager = PluginCore.groupManager;

    public static boolean addPrefix(Player player, String prefix) {
        final OverloadedWorldHolder handler = groupManager.getWorldsHolder().getWorldData(player);

        if (handler == null) {
            return false;
        }

        handler.getUser(player.getName()).getVariables().addVar(player.getName(), prefix);
        return true;
    }

    public static String getPrefix(Player player) {
        final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);

        if (handler == null) {
            return null;
        }

        return handler.getUserPrefix(player.getName());
    }

    public static boolean addPermissions(Player player, String permissions) {
        final OverloadedWorldHolder handler = groupManager.getWorldsHolder().getWorldData(player);

        if (handler == null) {
            return false;
        }

        handler.getUser(player.getName()).addPermission(permissions);
        return true;
    }

    public static boolean getPermission(Player player, String permission) {
        final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);

        if (handler == null) {
            return false;
        }

        return handler.has(player, permission);
    }

}
