From 862c164cf3ba09a86016f0bdb53ab88a78fa7891 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 30 Nov 2022 13:35:34 +0100 Subject: [PATCH] added method in PermGroup to get groups that inherit the current group --- .../java/fr/pandacube/lib/permissions/PermGroup.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandalib-permissions/src/main/java/fr/pandacube/lib/permissions/PermGroup.java b/pandalib-permissions/src/main/java/fr/pandacube/lib/permissions/PermGroup.java index ba05f8d..5752844 100644 --- a/pandalib-permissions/src/main/java/fr/pandacube/lib/permissions/PermGroup.java +++ b/pandalib-permissions/src/main/java/fr/pandacube/lib/permissions/PermGroup.java @@ -1,5 +1,6 @@ package fr.pandacube.lib.permissions; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -35,6 +36,17 @@ public final class PermGroup extends PermEntity { .collect(Collectors.toList()); } + /** + * Gets all the groups that directly inherits from this group. + * @return the groups that directly inherits from this group. + */ + public List getInheritedGroups() { + CachedGroup thisCG = getBackendEntity(); + return fromCachedGroups(Permissions.backendReader.getGroups().stream() + .filter(cg -> cg.inheritances.contains(thisCG)) + .toList()); + } + /** * Tells if this group is a default group. * A player inherits all default groups when they don’t explicitely inherit from at least one group.