use of net.luckperms.api.context.ImmutableContextSet 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.ImmutableContextSet in project LuckPerms by lucko.
the class MetaRemoveChatMeta method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
int priority = args.getPriority(0);
String meta = args.getOrDefault(1, "null");
ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
// Handle bulk removal
if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
target.removeIf(DataType.NORMAL, context, this.type.nodeType().predicate(n -> n.getPriority() == priority && !n.hasExpiry()), false);
Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, target, this.type, priority, context);
LoggedAction.build().source(sender).target(target).description("meta", "remove" + this.type.name().toLowerCase(Locale.ROOT), priority, "*", context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
return;
}
DataMutateResult result = target.unsetNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build());
if (result.wasSuccessful()) {
Message.REMOVE_CHATMETA_SUCCESS.send(sender, target, this.type, meta, priority, context);
LoggedAction.build().source(sender).target(target).description("meta", "remove" + this.type.name().toLowerCase(Locale.ROOT), priority, meta, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOES_NOT_HAVE_CHAT_META.send(sender, target, this.type, meta, priority, context);
}
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class ParentSetTrack method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
final String trackName = args.get(0).toLowerCase(Locale.ROOT);
if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) {
Message.TRACK_INVALID_ENTRY.send(sender, trackName);
return;
}
Track track = StorageAssistant.loadTrack(trackName, sender, plugin);
if (track == null) {
return;
}
if (track.getSize() <= 1) {
Message.TRACK_EMPTY.send(sender, track.getName());
return;
}
int index = args.getIntOrDefault(1, -1);
String groupName;
if (index > 0) {
List<String> trackGroups = track.getGroups();
if (index - 1 >= trackGroups.size()) {
Message.DOES_NOT_EXIST.send(sender, String.valueOf(index));
return;
}
groupName = track.getGroups().get(index - 1);
} else {
groupName = args.getLowercase(1, DataConstraints.GROUP_NAME_TEST);
if (!track.containsGroup(groupName)) {
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
return;
}
}
ImmutableContextSet context = args.getContextOrDefault(2, plugin).immutableCopy();
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
if (group == null) {
return;
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, group, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, track.getName(), group.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
target.removeIf(DataType.NORMAL, context, NodeType.INHERITANCE.predicate(n -> track.containsGroup(n.getGroupName())), false);
target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
Message.SET_TRACK_PARENT_SUCCESS.send(sender, target, track.getName(), group, context);
LoggedAction.build().source(sender).target(target).description("parent", "settrack", track.getName(), groupName, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class PermissionCheck method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
String node = args.get(0);
// accumulate nodes
List<Node> own = new ArrayList<>();
List<Node> inherited = new ArrayList<>();
List<Node> wildcards = new ArrayList<>();
List<Node> resolved = target.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
for (Node n : resolved) {
if (matches(node, n, plugin)) {
if (isInherited(n, target)) {
inherited.add(n);
} else {
own.add(n);
}
}
if (matchesWildcard(node, n, plugin)) {
wildcards.add(n);
}
}
// send results
Message.PERMISSION_CHECK_INFO_HEADER.send(sender, node);
if (own.isEmpty()) {
Message.PERMISSION_CHECK_INFO_NOT_DIRECTLY.send(sender, target, node);
} else {
for (Node n : own) {
Message.PERMISSION_CHECK_INFO_DIRECTLY.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts());
}
}
if (inherited.isEmpty()) {
Message.PERMISSION_CHECK_INFO_NOT_INHERITED.send(sender, target, node);
} else {
for (Node n : inherited) {
String origin = n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
Message.PERMISSION_CHECK_INFO_INHERITED.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts(), origin);
}
}
for (Node n : wildcards) {
if (isInherited(n, target)) {
String origin = n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
Message.PERMISSION_CHECK_INFO_INHERITED.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts(), origin);
} else {
Message.PERMISSION_CHECK_INFO_DIRECTLY.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts());
}
}
// blank line
sender.sendMessage(Message.prefixed(Component.empty()));
// perform a "real" check
QueryOptions queryOptions = target.getQueryOptions();
TristateResult checkResult = target.getCachedData().getPermissionData(queryOptions).checkPermission(node, CheckOrigin.INTERNAL);
Tristate result = checkResult.result();
String processor = checkResult.processorClassFriendly();
Node cause = checkResult.node();
ImmutableContextSet context = queryOptions.context();
// send results
Message.PERMISSION_CHECK_RESULT.send(sender, node, result, processor, cause, context);
}
use of net.luckperms.api.context.ImmutableContextSet in project LuckPerms by lucko.
the class OptionUnset method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
String key = args.get(0);
ImmutableContextSet contextSet = args.getContextOrEmpty(1);
if (subjectData.unsetOption(contextSet, key).join()) {
SpongeCommandUtils.sendPrefixed(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
SpongeCommandUtils.sendPrefixed(sender, "Unable to unset option. Are you sure the Subject has it set?");
}
}
Aggregations