use of me.lucko.luckperms.common.model.PermissionHolder 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.PermissionHolder in project LuckPerms by lucko.
the class HolderSubject method getParents.
@Override
public ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
InheritanceGraph graph = this.plugin.getInheritanceHandler().getGraph(this.plugin.getContextManager().formContexts(contexts));
Iterable<PermissionHolder> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this.parent);
ImmutableList.Builder<LPSubjectReference> subjects = ImmutableList.builder();
for (PermissionHolder parent : traversal) {
if (!(parent instanceof Group)) {
continue;
}
subjects.add(((SpongeGroup) parent).sponge().toReference());
}
return subjects.build();
}
use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.
the class ApplyEditsCommand method read.
private boolean read(JsonObject data, String code, Sender sender, LuckPermsPlugin plugin) {
if (!data.has("who") || data.get("who").getAsString().isEmpty()) {
Message.APPLY_EDITS_NO_TARGET.send(sender);
return false;
}
String who = data.get("who").getAsString();
PermissionHolder holder = WebEditor.getHolderFromIdentifier(plugin, sender, who);
if (holder == null) {
// the #getHolderFromIdentifier method will send the error message onto the sender
return false;
}
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return false;
}
Set<NodeModel> nodes = WebEditor.deserializePermissions(data.getAsJsonArray("nodes"));
Set<Node> before = new HashSet<>(holder.getEnduringNodes().values());
Set<Node> after = nodes.stream().map(NodeModel::toNode).collect(Collectors.toSet());
Map.Entry<Set<Node>, Set<Node>> diff = diff(before, after);
int additions = diff.getKey().size();
int deletions = diff.getValue().size();
if (additions == 0 && deletions == 0) {
return false;
}
ExtendedLogEntry.build().actor(sender).acted(holder).action("applyedits", code).build().submit(plugin, sender);
holder.setEnduringNodes(after);
String additionsSummary = "addition" + (additions == 1 ? "" : "s");
String deletionsSummary = "deletion" + (deletions == 1 ? "" : "s");
Message.APPLY_EDITS_SUCCESS.send(sender, holder.getFriendlyName());
Message.APPLY_EDITS_SUCCESS_SUMMARY.send(sender, additions, additionsSummary, deletions, deletionsSummary);
for (Node n : diff.getKey()) {
Message.APPLY_EDITS_DIFF_ADDED.send(sender, formatNode(n));
}
for (Node n : diff.getValue()) {
Message.APPLY_EDITS_DIFF_REMOVED.send(sender, formatNode(n));
}
StorageAssistant.save(holder, sender, plugin);
return true;
}
use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.
the class MetaInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(ChatMetaType type, PermissionHolder holder, String label, LocalizedNode node) {
if (!node.getLocation().equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
if (group != null) {
holder = group;
}
}
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> ¥a" + type.getEntry(node).getKey() + " ¥7- ¥r" + type.getEntry(node).getValue(), " ", "¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFriendlyName()), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.
the class MetaInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, LocalizedNode node) {
if (!node.getLocation().equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
if (group != null) {
holder = group;
}
}
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> ¥r" + node.getMeta().getKey() + " ¥7- ¥r" + node.getMeta().getValue(), " ", "¥7Click to remove this meta pair from " + holder.getFriendlyName()), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
Aggregations