net.luckperms.api.model.user.User Java Examples
The following examples show how to use
net.luckperms.api.model.user.User.
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 | 7 votes |
public User getLuckPermsUser(String identifier) { User user = null; UUID uuid = null; if (identifier.length() == 36) { try { uuid = UUID.fromString(identifier); } catch (IllegalArgumentException e) { e.printStackTrace(); } } else { user = this.luckPermsApi.getUserManager().getUser(identifier); if (user == null) { try { uuid = this.luckPermsApi.getUserManager().lookupUniqueId(identifier).get(); } catch (Throwable t) { // ignore } } } if (uuid != null) { user = this.getUserSubject(uuid); } return user; }
Example #3
Source File: LuckPermsHandler.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Override public boolean isInGroup(OfflinePlayer player, String group) { String playerName = player.getName(); if (playerName == null) { return false; } User user = luckPerms.getUserManager().getUser(playerName); if (user == null) { logger.warning("LuckPermsHandler: tried to check group for offline user " + player.getName() + " but it isn't loaded!"); return false; } InheritanceNode inheritanceNode = InheritanceNode.builder(group).build(); return user.data().contains(inheritanceNode, NodeEqualityPredicate.EXACT).asBoolean(); }
Example #4
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public User getLuckPermsUser(String identifier) { User user = null; UUID uuid = null; if (identifier.length() == 36) { try { uuid = UUID.fromString(identifier); } catch (IllegalArgumentException e) { e.printStackTrace(); } } else { user = this.luckPermsApi.getUserManager().getUser(identifier); if (user == null) { try { uuid = this.luckPermsApi.getUserManager().lookupUniqueId(identifier).get(); } catch (Throwable t) { // ignore } } } if (uuid != null) { user = this.getUserSubject(uuid); } return user; }
Example #5
Source File: LuckPermsHandler.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Override public boolean removeFromGroup(OfflinePlayer player, String group) { String playerName = player.getName(); if (playerName == null) { return false; } User user = luckPerms.getUserManager().getUser(playerName); if (user == null) { logger.warning("LuckPermsHandler: tried to remove group for offline user " + player.getName() + " but it isn't loaded!"); return false; } InheritanceNode groupNode = InheritanceNode.builder(group).build(); boolean result = user.data().remove(groupNode) != DataMutateResult.FAIL; luckPerms.getUserManager().saveUser(user); return result; }
Example #6
Source File: LuckPerms5Hook.java From BungeeChat2 with GNU General Public License v3.0 | 6 votes |
private QueryOptions getQueryOptions(Optional<User> user) { final ContextManager contextManager = api.getContextManager(); final QueryOptions queryOptions = user.flatMap(contextManager::getQueryOptions) .orElseGet(contextManager::getStaticQueryOptions); if (fixContexts && (queryOptions.mode() == QueryMode.CONTEXTUAL)) { final MutableContextSet context = queryOptions.context().mutableCopy(); context .getValues(DefaultContextKeys.WORLD_KEY) .forEach(world -> context.add(DefaultContextKeys.SERVER_KEY, world)); return queryOptions.toBuilder().context(context).build(); } else { return queryOptions; } }
Example #7
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public UUID lookupUserUniqueId(String name) { final User user = this.getLuckPermsUser(name); if (user != null) { return user.getUniqueId(); } return null; }
Example #8
Source File: ApiPlayerAdapter.java From LuckPerms with MIT License | 5 votes |
@Override public @NonNull User getUser(@NonNull P player) { Objects.requireNonNull(player, "player"); me.lucko.luckperms.common.model.User user = this.userManager.getIfLoaded(this.contextManager.getUniqueId(checkType(player))); Objects.requireNonNull(user, "user"); return user.getApiProxy(); }
Example #9
Source File: LuckPermsHook.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
private void handle(NodeMutateEvent event, Node node, boolean add) { if (event.isUser() && node.getType() == NodeType.INHERITANCE) { String groupName = NodeType.INHERITANCE.cast(node).getGroupName(); UUID uuid = ((User) event.getTarget()).getUniqueId(); Map<String, List<String>> justModified = DiscordSRV.getPlugin() .getGroupSynchronizationManager().getJustModifiedGroups().getOrDefault(uuid, null); if (justModified != null && justModified.getOrDefault(add ? "add" : "remove", Collections.emptyList()).remove(groupName)) { return; } handle(((User) event.getTarget()).getUniqueId()); } }
Example #10
Source File: LuckPermsHandler.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Override public boolean hasPermissionOffline(String name, PermissionNode node) { User user = luckPerms.getUserManager().getUser(name); if (user == null) { logger.warning("LuckPermsHandler: tried to check permission for offline user " + name + " but it isn't loaded!"); return false; } CachedPermissionData permissionData = user.getCachedData() .getPermissionData(QueryOptions.builder(QueryMode.NON_CONTEXTUAL).build()); return permissionData.checkPermission(node.getNode()).asBoolean(); }
Example #11
Source File: LuckPermsHandler.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Override public boolean setGroup(OfflinePlayer player, String group) { String playerName = player.getName(); if (playerName == null) { return false; } User user = luckPerms.getUserManager().getUser(playerName); if (user == null) { logger.warning("LuckPermsHandler: tried to set group for offline user " + player.getName() + " but it isn't loaded!"); return false; } InheritanceNode groupNode = InheritanceNode.builder(group).build(); DataMutateResult result = user.data().add(groupNode); if (result == DataMutateResult.FAIL) { return false; } user.data().clear(node -> { if (!(node instanceof InheritanceNode)) { return false; } InheritanceNode inheritanceNode = (InheritanceNode) node; return !inheritanceNode.equals(groupNode); }); luckPerms.getUserManager().saveUser(user); return true; }
Example #12
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 #13
Source File: HookLuckPerms.java From NametagEdit with GNU General Public License v3.0 | 5 votes |
private void onUserDataRecalculateEvent(UserDataRecalculateEvent event) { User user = event.getUser(); Player player = Bukkit.getPlayer(user.getUniqueId()); if (player != null) { handler.applyTagToPlayer(player, false); } }
Example #14
Source File: LuckPerms5Hook.java From BungeeChat2 with GNU General Public License v3.0 | 5 votes |
private Optional<CachedMetaData> getMetaData(BungeeChatAccount account) { final Optional<User> user = Optional.ofNullable(api.getUserManager().getUser(account.getUniqueId())); return user.map(User::getCachedData) .map(data -> data.getMetaData(getQueryOptions(user))) .filter(Objects::nonNull); }
Example #15
Source File: PluginHooks.java From TAB with Apache License 2.0 | 5 votes |
public static String[] UltraPermissions_getAllGroups(ITabPlayer p) { try { UltraPermissionsAPI api = null; if (p instanceof me.neznamy.tab.platforms.bungee.TabPlayer) { api = UltraPermissionsBungee.getAPI(); } if (p instanceof me.neznamy.tab.platforms.bukkit.TabPlayer) { api = UltraPermissions.getAPI(); } if (api == null) { Shared.errorManager.printError("UltraPermissions getAPI returned null"); return new String[]{"null"}; } me.TechsCode.UltraPermissions.storage.objects.User user = api.getUsers().name(p.getName()); if (user == null) { Shared.errorManager.printError("UltraPermissions returned null user for " + p.getName() + " (" + p.getUniqueId() + ")"); return new String[]{"null"}; } List<String> groups = new ArrayList<String>(); for (Group group : user.getGroups().bestToWorst().get()) { groups.add(group.getName()); } return groups.toArray(new String[0]); } catch (Throwable e) { return Shared.errorManager.printError(new String[] {"null"}, "Failed to get permission groups of " + p.getName() + " using UltraPermissions", e); } }
Example #16
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 #17
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 #18
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 #19
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public List<String> getAllLoadedPlayerNames() { List<String> subjectList = new ArrayList<>(); for (User user : this.luckPermsApi.getUserManager().getLoadedUsers()) { final String name = user.getUsername(); if (name != null) { subjectList.add(name); } } if (!subjectList.contains("public")) { subjectList.add("public"); } return subjectList; }
Example #20
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public UUID lookupUserUniqueId(String name) { final User user = this.getLuckPermsUser(name); if (user != null) { return user.getUniqueId(); } return null; }
Example #21
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 #22
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 #23
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 #24
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public List<String> getAllLoadedPlayerNames() { List<String> subjectList = new ArrayList<>(); for (User user : this.luckPermsApi.getUserManager().getLoadedUsers()) { final String name = user.getUsername(); if (name != null) { subjectList.add(name); } } if (!subjectList.contains("public")) { subjectList.add("public"); } return subjectList; }
Example #25
Source File: LuckPermsBridge.java From LunaChat with GNU Lesser General Public License v3.0 | 4 votes |
/** * プレイヤーのprefixを取得します。 * @param uniqueId プレイヤーのUUID * @return プレイヤーのprefix */ public String getPlayerPrefix(UUID uniqueId) { User user = api.getUserManager().getUser(uniqueId); String prefix = user.getCachedData().getMetaData().getPrefix(); return (prefix != null) ? prefix : ""; }
Example #26
Source File: ApiContextManager.java From LuckPerms with MIT License | 4 votes |
@Override public @NonNull Optional<QueryOptions> getQueryOptions(@NonNull User user) { Objects.requireNonNull(user, "user"); return this.plugin.getQueryOptionsForUser(ApiUser.cast(user)); }
Example #27
Source File: ApiContextManager.java From LuckPerms with MIT License | 4 votes |
@Override public @NonNull Optional<ImmutableContextSet> getContext(@NonNull User user) { Objects.requireNonNull(user, "user"); return this.plugin.getQueryOptionsForUser(ApiUser.cast(user)).map(QueryOptions::context); }
Example #28
Source File: LuckPermsBridge.java From LunaChat with GNU Lesser General Public License v3.0 | 4 votes |
/** * プレイヤーのsuffixを取得します。 * @param uniqueId プレイヤーのUUID * @return プレイヤーのsuffix */ public String getPlayerSuffix(UUID uniqueId) { User user = api.getUserManager().getUser(uniqueId); String suffix = user.getCachedData().getMetaData().getSuffix(); return (suffix != null) ? suffix : ""; }
Example #29
Source File: ApiTrack.java From LuckPerms with MIT License | 4 votes |
@Override public @NonNull DemotionResult demote(@NonNull User user, @NonNull ContextSet contextSet) { return this.handle.demote(ApiUser.cast(user), contextSet, Predicates.alwaysTrue(), null, true); }
Example #30
Source File: ApiTrack.java From LuckPerms with MIT License | 4 votes |
@Override public @NonNull PromotionResult promote(@NonNull User user, @NonNull ContextSet contextSet) { return this.handle.promote(ApiUser.cast(user), contextSet, Predicates.alwaysTrue(), null, true); }