net.luckperms.api.model.group.Group Java Examples
The following examples show how to use
net.luckperms.api.model.group.Group.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LuckPermsHandler.java From AuthMeReloaded with GNU General Public License v3.0 | 8 votes |
@Override public boolean addToGroup(OfflinePlayer player, String group) { Group newGroup = luckPerms.getGroupManager().getGroup(group); if (newGroup == null) { return false; } String playerName = player.getName(); if (playerName == null) { return false; } User user = luckPerms.getUserManager().getUser(playerName); if (user == null) { return false; } InheritanceNode node = InheritanceNode.builder(group).build(); DataMutateResult result = user.data().add(node); if (result == DataMutateResult.FAIL) { return false; } luckPerms.getUserManager().saveUser(user); return true; }
Example #2
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public List<String> getAllLoadedGroupNames() { List<String> subjectList = new ArrayList<>(); for (Group group : this.luckPermsApi.getGroupManager().getLoadedGroups()) { final String name = group.getName(); if (name != null) { subjectList.add(name); } } if (!subjectList.contains("public")) { subjectList.add("public"); } return subjectList; }
Example #3
Source File: LuckPermsHandler.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Override public List<String> getGroups(OfflinePlayer player) { String playerName = player.getName(); if (playerName == null) { return Collections.emptyList(); } User user = luckPerms.getUserManager().getUser(playerName); if (user == null) { logger.warning("LuckPermsHandler: tried to get groups for offline user " + player.getName() + " but it isn't loaded!"); return Collections.emptyList(); } return user.getDistinctNodes().stream() .filter(node -> node instanceof InheritanceNode) .map(node -> (InheritanceNode) node) .map(node -> luckPerms.getGroupManager().getGroup(node.getGroupName())) .filter(Objects::nonNull) .sorted((o1, o2) -> { if (o1.getName().equals(user.getPrimaryGroup()) || o2.getName().equals(user.getPrimaryGroup())) { return o1.getName().equals(user.getPrimaryGroup()) ? 1 : -1; } int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0)); return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName()); }) .map(Group::getName) .collect(Collectors.toList()); }
Example #4
Source File: ApiPermissionHolder.java From LuckPerms with MIT License | 5 votes |
@Override public @NonNull Collection<Group> getInheritedGroups(@NonNull QueryOptions queryOptions) { Objects.requireNonNull(queryOptions, "queryOptions"); return this.handle.resolveInheritanceTree(queryOptions).stream() .map(me.lucko.luckperms.common.model.Group::getApiProxy) .collect(ImmutableCollectors.toList()); }
Example #5
Source File: ApiTrack.java From LuckPerms with MIT License | 5 votes |
@Override public String getPrevious(@NonNull Group current) { Objects.requireNonNull(current, "current"); try { return this.handle.getPrevious(ApiGroup.cast(current)); } catch (IllegalArgumentException e) { return null; } }
Example #6
Source File: ApiTrack.java From LuckPerms with MIT License | 5 votes |
@Override public String getNext(@NonNull Group current) { Objects.requireNonNull(current, "current"); try { return this.handle.getNext(ApiGroup.cast(current)); } catch (IllegalArgumentException e) { return null; } }
Example #7
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
@Override public CompletableFuture<Void> save(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new CompletableFuture<>(); } if (permissionHolder instanceof User) { return this.luckPermsApi.getUserManager().saveUser((User) permissionHolder); } else { return this.luckPermsApi.getGroupManager().saveGroup((Group) permissionHolder); } }
Example #8
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public void savePermissionHolder(PermissionHolder holder) { if (holder instanceof User) { this.luckPermsApi.getUserManager().saveUser((User) holder); } else { this.luckPermsApi.getGroupManager().saveGroup((Group) holder); } }
Example #9
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save) { DataMutateResult result = null; if (check) { // If no server context exists, add global this.checkServerContext(contexts); } ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final Node node = this.luckPermsApi.getNodeBuilderRegistry().forPermission().permission(permission).value(value.asBoolean()).context(set).build(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new GDPermissionResult(ResultTypes.FAILURE); } if (value == Tristate.UNDEFINED) { result = permissionHolder.data().remove(node); } else { result = permissionHolder.data().add(node); } if (result.wasSuccessful()) { if (permissionHolder instanceof Group) { // If a group is changed, we invalidate all cache PermissionHolderCache.getInstance().invalidateAllPermissionCache(); } else { // We need to invalidate cache outside of LP listener so we can guarantee proper result returns PermissionHolderCache.getInstance().getOrCreatePermissionCache(holder).invalidateAll(); } if (save) { this.savePermissionHolder(permissionHolder); } return new GDPermissionResult(ResultTypes.SUCCESS, TextComponent.builder().append(result.name()).build()); } return new GDPermissionResult(ResultTypes.FAILURE, TextComponent.builder().append(result.name()).build()); }
Example #10
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public List<String> getAllLoadedGroupNames() { List<String> subjectList = new ArrayList<>(); for (Group group : this.luckPermsApi.getGroupManager().getLoadedGroups()) { final String name = group.getName(); if (name != null) { subjectList.add(name); } } if (!subjectList.contains("public")) { subjectList.add("public"); } return subjectList; }
Example #11
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public Group getLuckPermsGroup(String identifier) { if (identifier.equalsIgnoreCase("default")) { return this.luckPermsApi.getGroupManager().getGroup("default"); } return this.luckPermsApi.getGroupManager().getGroup(identifier); }
Example #12
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public void addActiveContexts(Set<Context> contexts, GDPermissionHolder permissionHolder, GDPlayerData playerData, Claim claim) { if (playerData != null) { playerData.ignoreActiveContexts = true; } final PermissionHolder luckPermsHolder = this.getLuckPermsHolder(permissionHolder); if (luckPermsHolder instanceof Group) { contexts.addAll(this.getGDContexts(this.luckPermsApi.getContextManager().getStaticContext().mutableCopy())); return; } ImmutableContextSet contextSet = this.luckPermsApi.getContextManager().getContext((User) luckPermsHolder).orElse(null); if (contextSet == null) { contextSet = this.luckPermsApi.getContextManager().getStaticContext(); } if (contextSet == null) { return; } MutableContextSet activeContexts = contextSet.mutableCopy(); if (playerData != null && claim != null) { final Claim parent = claim.getParent().orElse(null); if (parent != null && claim.getData() != null && claim.getData().doesInheritParent()) { activeContexts.remove(parent.getContext().getKey(), parent.getContext().getValue()); } else { activeContexts.remove(claim.getContext().getKey(), claim.getContext().getValue()); } } contexts.addAll(this.getGDContexts(activeContexts)); }
Example #13
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save) { DataMutateResult result = null; if (check) { // If no server context exists, add global this.checkServerContext(contexts); } ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final Node node = this.luckPermsApi.getNodeBuilderRegistry().forPermission().permission(permission).value(value.asBoolean()).context(set).build(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new GDPermissionResult(ResultTypes.FAILURE); } if (value == Tristate.UNDEFINED) { result = permissionHolder.data().remove(node); } else { result = permissionHolder.data().add(node); } if (result.wasSuccessful()) { if (permissionHolder instanceof Group) { // If a group is changed, we invalidate all cache PermissionHolderCache.getInstance().invalidateAllPermissionCache(); } else { // We need to invalidate cache outside of LP listener so we can guarantee proper result returns PermissionHolderCache.getInstance().getOrCreatePermissionCache(holder).invalidateAll(); } if (save) { this.savePermissionHolder(permissionHolder); } return new GDPermissionResult(ResultTypes.SUCCESS, TextComponent.builder().append(result.name()).build()); } return new GDPermissionResult(ResultTypes.FAILURE, TextComponent.builder().append(result.name()).build()); }
Example #14
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public void savePermissionHolder(PermissionHolder holder) { if (holder instanceof User) { this.luckPermsApi.getUserManager().saveUser((User) holder); } else { this.luckPermsApi.getGroupManager().saveGroup((Group) holder); } }
Example #15
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
@Override public CompletableFuture<Void> save(GDPermissionHolder holder) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new CompletableFuture<>(); } if (permissionHolder instanceof User) { return this.luckPermsApi.getUserManager().saveUser((User) permissionHolder); } else { return this.luckPermsApi.getGroupManager().saveGroup((Group) permissionHolder); } }
Example #16
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public void addActiveContexts(Set<Context> contexts, GDPermissionHolder permissionHolder, GDPlayerData playerData, Claim claim) { if (playerData != null) { playerData.ignoreActiveContexts = true; } final PermissionHolder luckPermsHolder = this.getLuckPermsHolder(permissionHolder); if (luckPermsHolder instanceof Group) { contexts.addAll(this.getGDContexts(this.luckPermsApi.getContextManager().getStaticContext().mutableCopy())); return; } ImmutableContextSet contextSet = this.luckPermsApi.getContextManager().getContext((User) luckPermsHolder).orElse(null); if (contextSet == null) { contextSet = this.luckPermsApi.getContextManager().getStaticContext(); } if (contextSet == null) { return; } MutableContextSet activeContexts = contextSet.mutableCopy(); if (playerData != null && claim != null) { final Claim parent = claim.getParent().orElse(null); if (parent != null && claim.getData() != null && claim.getData().doesInheritParent()) { activeContexts.remove(parent.getContext().getKey(), parent.getContext().getValue()); } else { activeContexts.remove(claim.getContext().getKey(), claim.getContext().getValue()); } } contexts.addAll(this.getGDContexts(activeContexts)); }
Example #17
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public Group getLuckPermsGroup(String identifier) { if (identifier.equalsIgnoreCase("default")) { return this.luckPermsApi.getGroupManager().getGroup("default"); } return this.luckPermsApi.getGroupManager().getGroup(identifier); }
Example #18
Source File: ApiTrack.java From LuckPerms with MIT License | 4 votes |
@Override public boolean containsGroup(@NonNull Group group) { Objects.requireNonNull(group, "group"); return this.handle.containsGroup(ApiGroup.cast(group)); }
Example #19
Source File: ApiTrack.java From LuckPerms with MIT License | 4 votes |
@Override public @NonNull DataMutateResult removeGroup(@NonNull Group group) { Objects.requireNonNull(group, "group"); return this.handle.removeGroup(ApiGroup.cast(group)); }
Example #20
Source File: ApiTrack.java From LuckPerms with MIT License | 4 votes |
@Override public @NonNull DataMutateResult insertGroup(@NonNull Group group, int position) throws IndexOutOfBoundsException { Objects.requireNonNull(group, "group"); return this.handle.insertGroup(ApiGroup.cast(group), position); }
Example #21
Source File: ApiTrack.java From LuckPerms with MIT License | 4 votes |
@Override public @NonNull DataMutateResult appendGroup(@NonNull Group group) { Objects.requireNonNull(group, "group"); return this.handle.appendGroup(ApiGroup.cast(group)); }
Example #22
Source File: InheritanceNode.java From LuckPerms with MIT License | 2 votes |
/** * Sets the name of group to inherit. * * @param group the group name * @return the builder */ static @NonNull Builder builder(@NonNull Group group) { return builder().group(group); }
Example #23
Source File: PermissionHolder.java From LuckPerms with MIT License | 2 votes |
/** * Gets a collection of the {@link Group}s this holder inherits nodes from. * * <p>If {@link Flag#RESOLVE_INHERITANCE} is set, this will include holders inherited from both * directly and indirectly (through directly inherited groups). It will effectively resolve the * whole "inheritance tree".</p> * * <p>If {@link Flag#RESOLVE_INHERITANCE} is not set, then the traversal will only go one * level up the inheritance tree, and return only directly inherited groups.</p> * * <p>The collection will be ordered according to the platforms inheritance rules. The groups * which are inherited from first will appear earlier in the list.</p> * * <p>The list will not contain the holder.</p> * * @param queryOptions the query options * @return a collection of the groups the holder inherits from * @since 5.1 */ @NonNull Collection<Group> getInheritedGroups(@NonNull QueryOptions queryOptions);
Example #24
Source File: Track.java From LuckPerms with MIT License | 2 votes |
/** * Gets the next group on the track, after the one provided * * <p>{@code null} is returned if the group is not on the track.</p> * * @param current the group before the group being requested * @return the group name, or null if the end of the track has been reached * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ @Nullable String getNext(@NonNull Group current);
Example #25
Source File: Track.java From LuckPerms with MIT License | 2 votes |
/** * Gets the previous group on the track, before the one provided * * <p>{@code null} is returned if the group is not on the track.</p> * * @param current the group after the group being requested * @return the group name, or null if the start of the track has been reached * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ @Nullable String getPrevious(@NonNull Group current);
Example #26
Source File: Track.java From LuckPerms with MIT License | 2 votes |
/** * Appends a group to the end of this track * * @param group the group to append * @return the result of the operation * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ @NonNull DataMutateResult appendGroup(@NonNull Group group);
Example #27
Source File: NodeMutateEvent.java From LuckPerms with MIT License | 2 votes |
/** * Gets whether the target of this event is a {@link Group} * * <p>This is equivalent to checking if getTarget() instanceof Group</p> * * @return if the event is targeting a group */ default boolean isGroup() { return getTarget() instanceof Group; }
Example #28
Source File: GroupCreateEvent.java From LuckPerms with MIT License | 2 votes |
/** * Gets the new group * * @return the new group */ @Param(0) @NonNull Group getGroup();
Example #29
Source File: GroupDataRecalculateEvent.java From LuckPerms with MIT License | 2 votes |
/** * Gets the group whose data was recalculated * * @return the group */ @Param(0) @NonNull Group getGroup();
Example #30
Source File: GroupCacheLoadEvent.java From LuckPerms with MIT License | 2 votes |
/** * Gets the group whose data was loaded * * @return the group */ @Param(0) @NonNull Group getGroup();