Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.tehkode.permissions;
- import java.util.HashSet;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.logging.Logger;
- import ru.tehkode.permissions.events.PermissionEntityEvent.Action;
- public class PermissionGroup
- extends PermissionEntity
- implements Comparable<PermissionGroup>
- {
- protected int weight = 0;
- protected boolean dirtyWeight = true;
- private final PermissionsGroupData data;
- public PermissionGroup(String groupName, PermissionsGroupData data, PermissionManager manager)
- {
- super(groupName, manager);
- this.data = data;
- }
- protected PermissionsGroupData getData()
- {
- return this.data;
- }
- public void initialize()
- {
- super.initialize();
- if (isDebug()) {
- this.manager.getLogger().info("Group " + getIdentifier() + " initialized");
- }
- }
- public PermissionEntity.Type getType()
- {
- return PermissionEntity.Type.GROUP;
- }
- public int getWeight()
- {
- if (this.dirtyWeight)
- {
- this.weight = getOptionInteger("weight", null, 0);
- this.dirtyWeight = false;
- }
- return this.weight;
- }
- public void setWeight(int weight)
- {
- setOption("weight", Integer.toString(weight));
- this.dirtyWeight = true;
- callEvent(PermissionEntityEvent.Action.WEIGHT_CHANGED);
- }
- public boolean isRanked()
- {
- return getRank() > 0;
- }
- public int getRank()
- {
- return getOwnOptionInteger("rank", null, 0);
- }
- public void setRank(int rank)
- {
- if (rank > 0) {
- setOption("rank", Integer.toString(rank));
- } else {
- setOption("rank", null);
- }
- callEvent(PermissionEntityEvent.Action.RANK_CHANGED);
- }
- public String getRankLadder()
- {
- return getOption("rank-ladder", "", "default");
- }
- public void setRankLadder(String rankLadder)
- {
- if ((rankLadder.isEmpty()) || (rankLadder.equals("default"))) {
- rankLadder = null;
- }
- setOption("rank-ladder", rankLadder);
- callEvent(PermissionEntityEvent.Action.RANK_CHANGED);
- }
- public boolean isChildOf(PermissionGroup group, String worldName, boolean checkInheritance)
- {
- return isChildOf(group, worldName, checkInheritance ? new HashSet() : null);
- }
- private boolean isChildOf(PermissionGroup group, String worldName, Set<String> visitedParents)
- {
- if (group == null) {
- return false;
- }
- if (visitedParents != null) {
- visitedParents.add(getIdentifier());
- }
- for (String parentGroup : getData().getParents(worldName)) {
- if ((visitedParents == null) || (!visitedParents.contains(parentGroup)))
- {
- if (group.getIdentifier().equals(parentGroup)) {
- return true;
- }
- if ((visitedParents != null) && (this.manager.getGroup(parentGroup).isChildOf(group, worldName, visitedParents))) {
- return true;
- }
- }
- }
- return false;
- }
- public boolean isChildOf(PermissionGroup group, boolean checkInheritance)
- {
- for (String worldName : getWorlds()) {
- if (isChildOf(group, worldName, checkInheritance)) {
- return true;
- }
- }
- return isChildOf(group, null, checkInheritance);
- }
- public boolean isChildOf(PermissionGroup group, String worldName)
- {
- return isChildOf(group, worldName, false);
- }
- public boolean isChildOf(PermissionGroup group)
- {
- return isChildOf(group, false);
- }
- public boolean isChildOf(String groupName, String worldName, boolean checkInheritance)
- {
- return isChildOf(this.manager.getGroup(groupName), worldName, checkInheritance);
- }
- public boolean isChildOf(String groupName, boolean checkInheritance)
- {
- return isChildOf(this.manager.getGroup(groupName), checkInheritance);
- }
- public boolean isChildOf(String groupName, String worldName)
- {
- return isChildOf(groupName, worldName, false);
- }
- public boolean isChildOf(String groupName)
- {
- return isChildOf(groupName, false);
- }
- public List<PermissionGroup> getChildGroups(String worldName)
- {
- return this.manager.getGroups(getIdentifier(), worldName, false);
- }
- public List<PermissionGroup> getChildGroups()
- {
- return this.manager.getGroups(getIdentifier(), false);
- }
- public List<PermissionGroup> getDescendantGroups(String worldName)
- {
- return this.manager.getGroups(getIdentifier(), worldName, true);
- }
- public List<PermissionGroup> getDescendantGroups()
- {
- return this.manager.getGroups(getIdentifier(), true);
- }
- public Set<PermissionUser> getUsers(String worldName)
- {
- return this.manager.getUsers(getIdentifier(), worldName, false);
- }
- public Set<PermissionUser> getUsers()
- {
- return this.manager.getUsers(getIdentifier());
- }
- public Set<PermissionUser> getActiveUsers()
- {
- return this.manager.getActiveUsers(getIdentifier());
- }
- public Set<PermissionUser> getActiveUsers(boolean inheritance)
- {
- return this.manager.getActiveUsers(getIdentifier(), inheritance);
- }
- public boolean isDefault(String worldName)
- {
- return getOwnOptionBoolean("default", worldName, false);
- }
- public void setDefault(boolean def, String worldName)
- {
- setOption("default", String.valueOf(def), worldName);
- callEvent(PermissionEntityEvent.Action.DEFAULTGROUP_CHANGED);
- }
- protected void clearCache()
- {
- for (PermissionUser user : getActiveUsers()) {
- user.clearCache();
- }
- }
- public final void remove()
- {
- for (String world : getWorlds()) {
- clearChildren(world);
- }
- clearChildren(null);
- super.remove();
- }
- private void clearChildren(String worldName)
- {
- for (PermissionGroup group : getChildGroups(worldName))
- {
- List<PermissionGroup> parentGroups = new LinkedList(group.getOwnParents(worldName));
- parentGroups.remove(this);
- group.setParents(parentGroups, worldName);
- }
- for (PermissionUser user : getUsers(worldName)) {
- user.removeGroup(this, worldName);
- }
- }
- public int compareTo(PermissionGroup o)
- {
- return getWeight() - o.getWeight();
- }
- @Deprecated
- public String[] getParentGroupsNames(String worldName)
- {
- return (String[])getParentIdentifiers(worldName).toArray(new String[0]);
- }
- @Deprecated
- public String[] getParentGroupsNames()
- {
- return (String[])getParentIdentifiers().toArray(new String[0]);
- }
- @Deprecated
- public void setParentGroups(List<String> parentGroups, String worldName)
- {
- setParentsIdentifier(parentGroups, worldName);
- }
- @Deprecated
- public void setParentGroups(List<String> parentGroups)
- {
- setParentsIdentifier(parentGroups);
- }
- @Deprecated
- public void setParentGroupObjects(List<PermissionGroup> parentGroups, String worldName)
- {
- setParents(parentGroups, worldName);
- }
- @Deprecated
- public void setParentGroupObjects(List<PermissionGroup> parentGroups)
- {
- setParents(parentGroups);
- }
- @Deprecated
- public List<PermissionGroup> getParentGroups(String worldName)
- {
- return getParents(worldName);
- }
- @Deprecated
- public List<PermissionGroup> getParentGroups()
- {
- return getParentGroups(null);
- }
- @Deprecated
- public Map<String, List<PermissionGroup>> getAllParentGroups()
- {
- return getAllParents();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement