use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.
the class ContextManager method getPotentialContexts.
public ImmutableContextSet getPotentialContexts() {
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
for (ContextCalculator<? super S> calculator : this.calculators.calculators()) {
ContextSet potentialContexts;
try {
potentialContexts = calculator.estimatePotentialContexts();
} catch (Throwable e) {
this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst estimating potential contexts", e);
continue;
}
builder.addAll(potentialContexts);
}
return builder.build();
}
use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.
the class ContextSetJsonSerializer method serialize.
public static JsonObject serialize(ContextSet contextSet) {
JsonObject output = new JsonObject();
List<Map.Entry<String, Set<String>>> entries = new ArrayList<>(contextSet.toMap().entrySet());
// sort - consistent output order
entries.sort(Map.Entry.comparingByKey());
for (Map.Entry<String, Set<String>> entry : entries) {
String[] values = entry.getValue().toArray(new String[0]);
switch(values.length) {
case 0:
break;
case 1:
output.addProperty(entry.getKey(), values[0]);
break;
default:
// sort - consistent output order
Arrays.sort(values);
JsonArray arr = new JsonArray();
for (String value : values) {
arr.add(new JsonPrimitive(value));
}
output.add(entry.getKey(), arr);
break;
}
}
return output;
}
use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.
the class LuckPermsVaultPermission method getQueryOptions.
// utility method for getting a contexts instance for a given vault lookup.
QueryOptions getQueryOptions(@Nullable UUID uuid, @Nullable String world) {
ContextSet context;
Player player = Optional.ofNullable(uuid).flatMap(u -> this.plugin.getBootstrap().getPlayer(u)).orElse(null);
if (player != null) {
context = this.plugin.getContextManager().getContext(player);
} else {
context = this.plugin.getContextManager().getStaticContext();
}
String playerWorld = player == null ? null : player.getWorld().getName();
// if world is not null, we want to do a lookup in that specific world
if (world != null && !world.isEmpty() && !world.equalsIgnoreCase(playerWorld)) {
MutableContextSet mutContext = context.mutableCopy();
context = mutContext;
// remove already accumulated worlds
mutContext.removeAll(DefaultContextKeys.WORLD_KEY);
// add the vault world
mutContext.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase(Locale.ROOT));
}
// if we're using a special vault server
if (useVaultServer()) {
MutableContextSet mutContext = context instanceof MutableContextSet ? (MutableContextSet) context : context.mutableCopy();
context = mutContext;
// remove the normal server context from the set
mutContext.remove(DefaultContextKeys.SERVER_KEY, getServer());
// add the vault specific server
if (!getVaultServer().equals("global")) {
mutContext.add(DefaultContextKeys.SERVER_KEY, getVaultServer());
}
}
boolean op = false;
if (player != null) {
op = player.isOp();
} else if (uuid != null && UniqueIdType.determineType(uuid, this.plugin).getType().equals("npc")) {
op = this.plugin.getConfiguration().get(ConfigKeys.VAULT_NPC_OP_STATUS);
}
QueryOptions.Builder builder = QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder();
builder.context(context);
builder.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, isIncludeGlobal());
if (op) {
builder.option(BukkitContextManager.OP_OPTION, true);
}
return builder.build();
}
use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.
the class ContextSetConfigurateSerializer method serializeContextSet.
public static ConfigurationNode serializeContextSet(ContextSet contextSet) {
ConfigurationNode data = ConfigurationNode.root();
Map<String, Set<String>> map = contextSet.toMap();
for (Map.Entry<String, Set<String>> entry : map.entrySet()) {
List<String> values = new ArrayList<>(entry.getValue());
int size = values.size();
if (size == 1) {
data.getNode(entry.getKey()).setValue(values.get(0));
} else if (size > 1) {
data.getNode(entry.getKey()).setValue(values);
}
}
return data;
}
use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.
the class UserInfo method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, User target, ArgumentList args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
Message.USER_INFO_GENERAL.send(sender, target.getUsername().orElse("Unknown"), target.getUniqueId().toString(), UniqueIdType.determineType(target.getUniqueId(), plugin).describe(), plugin.getBootstrap().isPlayerOnline(target.getUniqueId()));
Map<Boolean, List<InheritanceNode>> parents = target.normalData().inheritanceAsSortedSet().stream().filter(Node::getValue).collect(Collectors.groupingBy(Node::hasExpiry, Collectors.toList()));
List<InheritanceNode> temporaryParents = parents.getOrDefault(true, Collections.emptyList());
List<InheritanceNode> permanentParents = parents.getOrDefault(false, Collections.emptyList());
if (!permanentParents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (InheritanceNode node : permanentParents) {
Message.INFO_PARENT_NODE_ENTRY.send(sender, node);
}
}
if (!temporaryParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (InheritanceNode node : temporaryParents) {
Message.INFO_PARENT_TEMPORARY_NODE_ENTRY.send(sender, node);
}
}
QueryOptions queryOptions = plugin.getQueryOptionsForUser(target).orElse(null);
boolean active = true;
if (queryOptions == null) {
active = false;
queryOptions = plugin.getContextManager().getStaticQueryOptions();
}
ContextSet contextSet = queryOptions.context();
MonitoredMetaCache data = target.getCachedData().getMetaData(queryOptions);
String prefix = data.getPrefix(CheckOrigin.INTERNAL).result();
String suffix = data.getSuffix(CheckOrigin.INTERNAL).result();
String primaryGroup = data.getPrimaryGroup(CheckOrigin.INTERNAL);
Map<String, List<String>> meta = data.getMeta(CheckOrigin.INTERNAL);
Message.USER_INFO_CONTEXTUAL_DATA.send(sender, active, contextSet, prefix, suffix, primaryGroup, meta);
}
Aggregations