use of me.lucko.luckperms.common.node.NodeModel in project LuckPerms by lucko.
the class ConfigurateDao method readNodes.
private static Set<NodeModel> readNodes(ConfigurationNode data) {
Set<NodeModel> nodes = new HashSet<>();
if (data.getNode("permissions").hasListChildren()) {
List<? extends ConfigurationNode> children = data.getNode("permissions").getChildrenList();
for (ConfigurationNode appended : children) {
String plainValue = appended.getValue(Types::strictAsString);
if (plainValue != null) {
nodes.add(NodeModel.of(plainValue));
continue;
}
Map.Entry<String, ConfigurationNode> entry = parseEntry(appended);
if (entry == null) {
continue;
}
nodes.addAll(readAttributes(entry.getValue(), entry.getKey()));
}
}
if (data.getNode("parents").hasListChildren()) {
List<? extends ConfigurationNode> children = data.getNode("parents").getChildrenList();
for (ConfigurationNode appended : children) {
String stringValue = appended.getValue(Types::strictAsString);
if (stringValue != null) {
nodes.add(NodeModel.of(NodeFactory.groupNode(stringValue)));
continue;
}
Map.Entry<String, ConfigurationNode> entry = parseEntry(appended);
if (entry == null) {
continue;
}
nodes.add(readAttributes(entry.getValue(), c -> NodeFactory.groupNode(entry.getKey())));
}
}
for (ChatMetaType chatMetaType : ChatMetaType.values()) {
String keyName = chatMetaType.toString() + "es";
if (data.getNode(keyName).hasListChildren()) {
List<? extends ConfigurationNode> children = data.getNode(keyName).getChildrenList();
for (ConfigurationNode appended : children) {
Map.Entry<String, ConfigurationNode> entry = parseEntry(appended);
if (entry == null) {
continue;
}
nodes.add(readAttributes(entry.getValue(), c -> NodeFactory.chatMetaNode(chatMetaType, c.getNode("priority").getInt(0), entry.getKey())));
}
}
}
if (data.getNode("meta").hasListChildren()) {
List<? extends ConfigurationNode> children = data.getNode("meta").getChildrenList();
for (ConfigurationNode appended : children) {
Map.Entry<String, ConfigurationNode> entry = parseEntry(appended);
if (entry == null) {
continue;
}
nodes.add(readAttributes(entry.getValue(), c -> NodeFactory.metaNode(entry.getKey(), entry.getValue().getNode("value").getString("null"))));
}
}
return nodes;
}
use of me.lucko.luckperms.common.node.NodeModel in project LuckPerms by lucko.
the class ConfigurateDao method getUsersWithPermission.
@Override
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) throws Exception {
List<HeldPermission<UUID>> held = new ArrayList<>();
File[] files = getDirectory(StorageLocation.USER).listFiles(getFileTypeFilter());
if (files == null) {
throw new IllegalStateException("Users directory matched no files.");
}
for (File file : files) {
try {
registerFileAction(StorageLocation.USER, file);
ConfigurationNode object = readFile(file);
UUID holder = UUID.fromString(file.getName().substring(0, file.getName().length() - this.fileExtension.length()));
Set<NodeModel> nodes = readNodes(object);
for (NodeModel e : nodes) {
if (!e.getPermission().equalsIgnoreCase(permission)) {
continue;
}
held.add(NodeHeldPermission.of(holder, e));
}
} catch (Exception e) {
throw reportException(file.getName(), e);
}
}
return held;
}
use of me.lucko.luckperms.common.node.NodeModel in project LuckPerms by lucko.
the class ConfigurateDao method getGroupsWithPermission.
@Override
public List<HeldPermission<String>> getGroupsWithPermission(String permission) throws Exception {
List<HeldPermission<String>> held = new ArrayList<>();
File[] files = getDirectory(StorageLocation.GROUP).listFiles(getFileTypeFilter());
if (files == null) {
throw new IllegalStateException("Groups directory matched no files.");
}
for (File file : files) {
try {
registerFileAction(StorageLocation.GROUP, file);
ConfigurationNode object = readFile(file);
String holder = file.getName().substring(0, file.getName().length() - this.fileExtension.length());
Set<NodeModel> nodes = readNodes(object);
for (NodeModel e : nodes) {
if (!e.getPermission().equalsIgnoreCase(permission)) {
continue;
}
held.add(NodeHeldPermission.of(holder, e));
}
} catch (Exception e) {
throw reportException(file.getName(), e);
}
}
return held;
}
use of me.lucko.luckperms.common.node.NodeModel in project LuckPerms by lucko.
the class MongoDao method getGroupsWithPermission.
@Override
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
List<HeldPermission<String>> held = new ArrayList<>();
MongoCollection<Document> c = this.database.getCollection(this.prefix + "groups");
try (MongoCursor<Document> cursor = c.find().iterator()) {
while (cursor.hasNext()) {
Document d = cursor.next();
String holder = d.getString("_id");
Set<NodeModel> nodes = new HashSet<>(nodesFromDoc(d));
for (NodeModel e : nodes) {
if (!e.getPermission().equalsIgnoreCase(permission)) {
continue;
}
held.add(NodeHeldPermission.of(holder, e));
}
}
}
return held;
}
use of me.lucko.luckperms.common.node.NodeModel 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;
}
Aggregations