use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class AbstractCachedData method reloadMeta.
@Nonnull
@Override
public CompletableFuture<MetaCache> reloadMeta(@Nonnull MetaContexts contexts) {
Objects.requireNonNull(contexts, "contexts");
// get the previous value - to use when recalculating
MetaCache previous = this.meta.getIfPresent(contexts);
// invalidate the entry
this.meta.invalidate(contexts);
// repopulate the cache
return CompletableFuture.supplyAsync(() -> this.meta.get(contexts, c -> calculateMeta(c, previous)));
}
use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class AbstractCachedData method reloadPermissions.
@Nonnull
@Override
public CompletableFuture<PermissionCache> reloadPermissions(@Nonnull Contexts contexts) {
Objects.requireNonNull(contexts, "contexts");
// get the previous value - to use when recalculating
PermissionCache previous = this.permission.getIfPresent(contexts);
// invalidate the entry
this.permission.invalidate(contexts);
// repopulate the cache
return CompletableFuture.supplyAsync(() -> this.permission.get(contexts, c -> calculatePermissions(c, previous)));
}
use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class ParentsByWeightHolder method calculateValue.
@Override
protected String calculateValue() {
Contexts contexts = this.user.getPlugin().getContextForUser(this.user).orElse(null);
if (contexts == null) {
contexts = this.user.getPlugin().getContextManager().getStaticContexts();
}
Set<Group> groups = new LinkedHashSet<>();
for (Node node : this.user.getOwnNodes(contexts.getContexts())) {
if (!node.getValuePrimitive() || !node.isGroupNode()) {
continue;
}
Group group = this.user.getPlugin().getGroupManager().getIfLoaded(node.getGroupName());
if (group != null) {
groups.add(group);
}
}
Group bestGroup = null;
if (!groups.isEmpty()) {
int best = 0;
for (Group g : groups) {
int weight = g.getWeight().orElse(0);
if (bestGroup == null || g.getWeight().orElse(0) > best) {
bestGroup = g;
best = weight;
}
}
}
return bestGroup == null ? null : bestGroup.getName();
}
use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class DebugCommand method getPlayersData.
private static JObject getPlayersData(LuckPermsPlugin plugin) {
JObject ret = new JObject();
Set<UUID> onlinePlayers = plugin.getBootstrap().getOnlinePlayers().collect(Collectors.toSet());
ret.add("count", onlinePlayers.size());
JArray playerArray = new JArray();
for (UUID uuid : onlinePlayers) {
User user = plugin.getUserManager().getIfLoaded(uuid);
if (user == null) {
playerArray.add(new JObject().add("uniqueId", uuid.toString()).add("loaded", false));
continue;
}
playerArray.add(new JObject().add("uniqueId", uuid.toString()).add("loaded", true).add("username", user.getName().orElse("null")).add("primaryGroup", new JObject().add("type", user.getPrimaryGroup().getClass().getName()).add("value", user.getPrimaryGroup().getValue()).add("storedValue", user.getPrimaryGroup().getStoredValue().orElse("null"))).add("activeContext", () -> {
JObject obj = new JObject();
Contexts contexts = plugin.getContextForUser(user).orElse(null);
if (contexts != null) {
MetaContexts metaContexts = plugin.getContextManager().formMetaContexts(contexts);
obj.add("data", new JObject().add("permissions", serializePermissionsData(user.getCachedData().getPermissionData(contexts))).add("meta", serializeMetaData(user.getCachedData().getMetaData(metaContexts)))).add("contextSet", ContextSetJsonSerializer.serializeContextSet(contexts.getContexts())).add("settings", serializeContextsSettings(contexts)).add("metaSettings", serializeMetaContextsSettings(metaContexts));
}
return obj;
}));
}
ret.add("players", playerArray);
return ret;
}
use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class UserInfo method execute.
@SuppressWarnings("unchecked")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Message status = plugin.getBootstrap().isPlayerOnline(user.getUuid()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
Message.USER_INFO_GENERAL.send(sender, user.getName().orElse("Unknown"), user.getUuid(), user.getUuid().version() == 4 ? "&2mojang" : "&8offline", status.asString(plugin.getLocaleManager()), user.getPrimaryGroup().getValue());
Set<Node> parents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isPermanent).collect(Collectors.toSet());
Set<Node> tempParents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isTemporary).collect(Collectors.toSet());
if (!parents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (Node node : parents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
}
}
if (!tempParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (Node node : tempParents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
Message.EMPTY.send(sender, "&f- &2- expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()));
}
}
String context = "&bNone";
String prefix = "&bNone";
String suffix = "&bNone";
String meta = "&bNone";
Contexts contexts = plugin.getContextForUser(user).orElse(null);
if (contexts != null) {
ContextSet contextSet = contexts.getContexts();
if (!contextSet.isEmpty()) {
context = contextSet.toSet().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
}
MetaData data = user.getCachedData().getMetaData(contexts);
if (data.getPrefix() != null) {
prefix = "&f\"" + data.getPrefix() + "&f\"";
}
if (data.getSuffix() != null) {
suffix = "&f\"" + data.getSuffix() + "&f\"";
}
ListMultimap<String, String> metaMap = data.getMetaMultimap();
if (!metaMap.isEmpty()) {
meta = metaMap.entries().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
}
}
Message.USER_INFO_DATA.send(sender, MessageUtils.formatBoolean(contexts != null), context, prefix, suffix, meta);
return CommandResult.SUCCESS;
}
Aggregations