Optimize parent resolution in info commands (#3309)

This commit is contained in:
Sxtanna 2022-02-09 15:15:18 -05:00 committed by GitHub
parent b13a74c61e
commit d45d9a295b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 22 deletions

View File

@ -42,6 +42,7 @@ import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.query.QueryOptions;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -60,26 +61,23 @@ public class GroupInfo extends ChildCommand<Group> {
Message.GROUP_INFO_GENERAL.send(sender, target.getName(), target.getPlainDisplayName(), target.getWeight());
List<InheritanceNode> parents = target.normalData().inheritanceAsSortedSet().stream()
Map<Boolean, List<InheritanceNode>> parents = target.normalData().inheritanceAsSortedSet().stream()
.filter(Node::getValue)
.filter(n -> !n.hasExpiry())
.collect(Collectors.toList());
.collect(Collectors.groupingBy(Node::hasExpiry, Collectors.toList()));
List<InheritanceNode> tempParents = target.normalData().inheritanceAsSortedSet().stream()
.filter(Node::getValue)
.filter(Node::hasExpiry)
.collect(Collectors.toList());
List<InheritanceNode> temporaryParents = parents.getOrDefault(true, Collections.emptyList());
List<InheritanceNode> permanentParents = parents.getOrDefault(false, Collections.emptyList());
if (!parents.isEmpty()) {
if (!permanentParents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (InheritanceNode node : parents) {
for (InheritanceNode node : permanentParents) {
Message.INFO_PARENT_NODE_ENTRY.send(sender, node);
}
}
if (!tempParents.isEmpty()) {
if (!temporaryParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (InheritanceNode node : tempParents) {
for (InheritanceNode node : temporaryParents) {
Message.INFO_PARENT_TEMPORARY_NODE_ENTRY.send(sender, node);
}
}

View File

@ -44,6 +44,7 @@ import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.query.QueryOptions;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -67,26 +68,23 @@ public class UserInfo extends ChildCommand<User> {
plugin.getBootstrap().isPlayerOnline(target.getUniqueId())
);
List<InheritanceNode> parents = target.normalData().inheritanceAsSortedSet().stream()
Map<Boolean, List<InheritanceNode>> parents = target.normalData().inheritanceAsSortedSet().stream()
.filter(Node::getValue)
.filter(n -> !n.hasExpiry())
.collect(Collectors.toList());
.collect(Collectors.groupingBy(Node::hasExpiry, Collectors.toList()));
List<InheritanceNode> tempParents = target.normalData().inheritanceAsSortedSet().stream()
.filter(Node::getValue)
.filter(Node::hasExpiry)
.collect(Collectors.toList());
List<InheritanceNode> temporaryParents = parents.getOrDefault(true, Collections.emptyList());
List<InheritanceNode> permanentParents = parents.getOrDefault(false, Collections.emptyList());
if (!parents.isEmpty()) {
if (!permanentParents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (InheritanceNode node : parents) {
for (InheritanceNode node : permanentParents) {
Message.INFO_PARENT_NODE_ENTRY.send(sender, node);
}
}
if (!tempParents.isEmpty()) {
if (!temporaryParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (InheritanceNode node : tempParents) {
for (InheritanceNode node : temporaryParents) {
Message.INFO_PARENT_TEMPORARY_NODE_ENTRY.send(sender, node);
}
}