use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class PermissionHolder method exportNodesAndShorthand.
public Map<String, Boolean> exportNodesAndShorthand(boolean lowerCase) {
List<LocalizedNode> entries = resolveInheritances();
Map<String, Boolean> perms = new HashMap<>();
boolean applyShorthand = this.plugin.getConfiguration().get(ConfigKeys.APPLYING_SHORTHAND);
for (Node node : entries) {
String perm = lowerCase ? node.getPermission().toLowerCase().intern() : node.getPermission();
if (perms.putIfAbsent(perm, node.getValuePrimitive()) == null && applyShorthand) {
List<String> shorthand = node.resolveShorthand();
if (!shorthand.isEmpty()) {
for (String s : shorthand) {
perms.putIfAbsent((lowerCase ? s.toLowerCase() : s).intern(), node.getValuePrimitive());
}
}
}
}
return ImmutableMap.copyOf(perms);
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class PermissionHolder method accumulateMeta.
public MetaAccumulator accumulateMeta(MetaAccumulator accumulator) {
if (accumulator == null) {
accumulator = MetaAccumulator.makeFromConfig(this.plugin);
}
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph();
Iterable<PermissionHolder> traversal = graph.traverse(this.plugin.getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this);
for (PermissionHolder holder : traversal) {
List<Node> nodes = holder.getOwnNodes();
for (Node node : nodes) {
if (!node.getValuePrimitive())
continue;
if (!node.isMeta() && !node.isPrefix() && !node.isSuffix())
continue;
accumulator.accumulateNode(ImmutableLocalizedNode.of(node, holder.getObjectName()));
}
OptionalInt w = getWeight();
if (w.isPresent()) {
accumulator.accumulateWeight(w.getAsInt());
}
}
return accumulator;
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class ConfigurateDao method loadGroup.
@Override
public Optional<Group> loadGroup(String name) throws Exception {
Group group = this.plugin.getGroupManager().getIfLoaded(name);
if (group != null) {
group.getIoLock().lock();
}
try {
ConfigurationNode object = readFile(StorageLocation.GROUP, name);
if (object == null) {
return Optional.empty();
}
if (group == null) {
group = this.plugin.getGroupManager().getOrMake(name);
group.getIoLock().lock();
}
Set<NodeModel> data = readNodes(object);
Set<Node> nodes = data.stream().map(NodeModel::toNode).collect(Collectors.toSet());
group.setEnduringNodes(nodes);
} catch (Exception e) {
throw reportException(name, e);
} finally {
if (group != null) {
group.getIoLock().unlock();
}
}
group.getRefreshBuffer().requestDirectly();
return Optional.of(group);
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class AbstractUserManager method giveDefaultIfNeeded.
@Override
public boolean giveDefaultIfNeeded(User user, boolean save) {
boolean work = false;
// check that they are actually a member of their primary group, otherwise remove it
if (this.plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION_METHOD).equals("stored")) {
String pg = user.getPrimaryGroup().getValue();
boolean has = false;
for (Node node : user.getEnduringNodes().get(ImmutableContextSet.empty())) {
if (node.isGroupNode() && node.getGroupName().equalsIgnoreCase(pg)) {
has = true;
break;
}
}
// need to find a new primary group for the user.
if (!has) {
String group = user.getEnduringNodes().get(ImmutableContextSet.empty()).stream().filter(Node::isGroupNode).findFirst().map(Node::getGroupName).orElse(null);
// if the group is null, it'll be resolved in the next step
if (group != null) {
user.getPrimaryGroup().setStoredValue(group);
work = true;
}
}
}
// check that all users are member of at least one group
boolean hasGroup = false;
if (user.getPrimaryGroup().getStoredValue().isPresent()) {
for (Node node : user.getEnduringNodes().values()) {
if (node.hasSpecificContext()) {
continue;
}
if (node.isGroupNode()) {
hasGroup = true;
break;
}
}
}
if (!hasGroup) {
user.getPrimaryGroup().setStoredValue(NodeFactory.DEFAULT_GROUP_NAME);
user.setPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build());
work = true;
}
if (work && save) {
this.plugin.getStorage().saveUser(user);
}
return work;
}
use of me.lucko.luckperms.api.Node in project LuckPerms by lucko.
the class LogNotify method isIgnoring.
public static boolean isIgnoring(LuckPermsPlugin plugin, UUID uuid) {
User user = plugin.getUserManager().getIfLoaded(uuid);
if (user == null) {
return false;
}
Optional<Node> ret = user.getOwnNodes().stream().filter(n -> n.getPermission().equalsIgnoreCase("luckperms.log.notify.ignoring")).findFirst();
// if set to false, ignore it, return false
return ret.map(Node::getValuePrimitive).orElse(false);
}
Aggregations