use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class ExpireTemporaryTask method run.
@Override
public void run() {
boolean groupChanges = false;
for (Group group : this.plugin.getGroupManager().getAll().values()) {
if (shouldSkip(group)) {
continue;
}
if (group.auditTemporaryPermissions()) {
this.plugin.getStorage().saveGroup(group);
groupChanges = true;
}
}
for (User user : this.plugin.getUserManager().getAll().values()) {
if (shouldSkip(user)) {
continue;
}
if (user.auditTemporaryPermissions()) {
this.plugin.getStorage().saveUser(user);
if (!groupChanges) {
user.getRefreshBuffer().request();
}
}
}
if (groupChanges) {
this.plugin.getUpdateTaskBuffer().request();
}
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class GroupReference method apply.
@Override
public void apply(LuckPermsPlugin plugin, Consumer<Group> consumer) {
Group group = plugin.getGroupManager().getIfLoaded(this.id);
if (group == null)
return;
consumer.accept(group);
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class AllParentsByWeightHolder method calculateValue.
@Override
protected String calculateValue() {
Contexts contexts = this.user.getPlugin().getContextForUser(this.user).orElse(null);
if (contexts == null) {
contexts = this.user.getPlugin().getContextManager().getStaticContexts();
}
InheritanceGraph graph = this.user.getPlugin().getInheritanceHandler().getGraph(contexts);
// fully traverse the graph, obtain a list of permission holders the user inherits from
List<PermissionHolder> traversal = ImmutableList.copyOf(graph.traverse(this.user.getPlugin().getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this.user));
Group bestGroup = null;
if (!traversal.isEmpty()) {
int best = 0;
for (PermissionHolder holder : traversal) {
if (!(holder instanceof Group)) {
continue;
}
Group g = ((Group) holder);
int weight = g.getWeight().orElse(0);
if (bestGroup == null || g.getWeight().orElse(0) > best) {
bestGroup = g;
best = weight;
}
}
}
return bestGroup == null ? null : bestGroup.getName();
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class ConfigurateDao method createAndLoadGroup.
@Override
public Group createAndLoadGroup(String name) throws Exception {
Group group = this.plugin.getGroupManager().getOrMake(name);
group.getIoLock().lock();
try {
ConfigurationNode object = readFile(StorageLocation.GROUP, name);
if (object != null) {
Set<Node> nodes = readNodes(object).stream().map(NodeModel::toNode).collect(Collectors.toSet());
group.setEnduringNodes(nodes);
} else {
ConfigurationNode data = SimpleConfigurationNode.root();
data.getNode("name").setValue(group.getName());
Set<NodeModel> nodes = group.getEnduringNodes().values().stream().map(NodeModel::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
writeNodes(data, nodes);
saveFile(StorageLocation.GROUP, name, data);
}
} catch (Exception e) {
throw reportException(name, e);
} finally {
group.getIoLock().unlock();
}
group.getRefreshBuffer().requestDirectly();
return group;
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class WebEditor method getHolderFromIdentifier.
public static PermissionHolder getHolderFromIdentifier(LuckPermsPlugin plugin, Sender sender, String who) {
if (who.startsWith(GROUP_ID_PATTERN)) {
String group = who.substring(GROUP_ID_PATTERN.length());
Group holder = plugin.getGroupManager().getIfLoaded(group);
if (holder == null) {
Message.APPLY_EDITS_TARGET_GROUP_NOT_EXISTS.send(sender, group);
}
return holder;
} else if (who.startsWith(USER_ID_PATTERN)) {
String user = who.substring(USER_ID_PATTERN.length());
UUID uuid = Uuids.parseNullable(user);
if (uuid == null) {
Message.APPLY_EDITS_TARGET_USER_NOT_UUID.send(sender, user);
return null;
}
User holder = plugin.getStorage().loadUser(uuid, null).join();
if (holder == null) {
Message.APPLY_EDITS_TARGET_USER_UNABLE_TO_LOAD.send(sender, uuid.toString());
}
return holder;
} else {
Message.APPLY_EDITS_TARGET_UNKNOWN.send(sender, who);
return null;
}
}
Aggregations