<commit_before>/*
 * PermissionsEx - Permissions plugin for Bukkit
 * Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package ru.tehkode.permissions;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

/**
 *
 * @author code
 */
public abstract class PermissionUser extends PermissionEntity {

    protected PermissionGroup[] cachedGroups = null;
    protected HashMap<String, String[]> cachedPermissions = new HashMap<String, String[]>();
    protected String cachedPrefix = null;
    protected String cachedSuffix = null;
    protected HashMap<String, String> cachedAnwsers = new HashMap<String, String>();

    public PermissionUser(String playerName, PermissionManager manager) {
        super(playerName, manager);
    }

    protected abstract String[] getOwnPermissions(String world);

    public abstract void setGroups(String[] groups);

    protected abstract String[] getGroupsNamesImpl();

    public void setGroups(PermissionGroup[] parentGroups) {
        List<String> groups = new LinkedList<String>();

        for (PermissionGroup group : parentGroups) {
            groups.add(group.getName());
        }

        this.setGroups(groups.toArray(new String[0]));
    }

    public boolean inGroup(PermissionGroup group, boolean checkInheritance) {
        for (PermissionGroup parentGroup : this.getGroups()) {
            if (parentGroup.equals(group)) {
                return true;
            }

            if (checkInheritance && parentGroup.isChildOf(parentGroup, true)) {
                return true;
            }
        }

        return false;
    }

    public boolean inGroup(String groupName, boolean checkInheritance) {
        return this.inGroup(this.manager.getGroup(groupName), checkInheritance);
    }

    public boolean inGroup(PermissionGroup group) {
        return this.inGroup(group, true);
    }

    public boolean inGroup(String groupName) {
        return this.inGroup(this.manager.getGroup(groupName), true);
    }

    public PermissionGroup[] getGroups() {
        if (this.cachedGroups == null) {
            Set<PermissionGroup> groups = new LinkedHashSet<PermissionGroup>();<commit_msg>Bugfix for inGroup PermissionUser. Sorry! :(<commit_after>/*
 * PermissionsEx - Permissions plugin for Bukkit
 * Copyright (C) 2011 t3hk0d3 http://www.tehkode.ru
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package ru.tehkode.permissions;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

/**
 *
 * @author code
 */
public abstract class PermissionUser extends PermissionEntity {

    protected PermissionGroup[] cachedGroups = null;
    protected HashMap<String, String[]> cachedPermissions = new HashMap<String, String[]>();
    protected String cachedPrefix = null;
    protected String cachedSuffix = null;
    protected HashMap<String, String> cachedAnwsers = new HashMap<String, String>();

    public PermissionUser(String playerName, PermissionManager manager) {
        super(playerName, manager);
    }

    protected abstract String[] getOwnPermissions(String world);

    public abstract void setGroups(String[] groups);

    protected abstract String[] getGroupsNamesImpl();

    public void setGroups(PermissionGroup[] parentGroups) {
        List<String> groups = new LinkedList<String>();

        for (PermissionGroup group : parentGroups) {
            groups.add(group.getName());
        }

        this.setGroups(groups.toArray(new String[0]));
    }

    public boolean inGroup(PermissionGroup group, boolean checkInheritance) {
        for (PermissionGroup parentGroup : this.getGroups()) {
            if (parentGroup.equals(group)) {
                return true;
            }

            if (checkInheritance && parentGroup.isChildOf(group, true)) {
                return true;
            }
        }

        return false;
    }

    public boolean inGroup(String groupName, boolean checkInheritance) {
        return this.inGroup(this.manager.getGroup(groupName), checkInheritance);
    }

    public boolean inGroup(PermissionGroup group) {
        return this.inGroup(group, true);
    }

    public boolean inGroup(String groupName) {
        return this.inGroup(this.manager.getGroup(groupName), true);
    }

    public PermissionGroup[] getGroups() {
        if (this.cachedGroups == null) {
            Set<PermissionGroup> groups = new LinkedHashSet<PermissionGroup>();
{'fraction_non_alphanumeric': 0.08878582077190658, 'fraction_numerical': 0.006625807520291536, 'mean_word_length': 3.3470122390208785, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7586659', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1527, 'n_words': 534}