use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.
the class DescriptionBuilder method register.
@Override
@NonNull
public PermissionDescription register() throws IllegalStateException {
if (this.id == null) {
throw new IllegalStateException("id cannot be null");
}
LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
// Set role-templates
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
for (Map.Entry<String, Tristate> assignment : this.roles.entrySet()) {
LPSubject roleSubject = subjects.loadSubject(assignment.getKey()).join();
roleSubject.getTransientSubjectData().setPermission(ImmutableContextSetImpl.EMPTY, this.id, assignment.getValue());
}
// null stuff so this instance can be reused
this.roles.clear();
this.id = null;
this.description = null;
return description.sponge();
}
use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.
the class BungeePermissionCheckListener method onOtherTristateCheck.
@EventHandler(priority = EventPriority.HIGHEST)
public void onOtherTristateCheck(TristateCheckEvent e) {
if (e.getSender() instanceof ProxiedPlayer) {
return;
}
Objects.requireNonNull(e.getPermission(), "permission");
Objects.requireNonNull(e.getSender(), "sender");
String permission = e.getPermission();
Tristate result = e.getResult();
VerboseCheckTarget target = VerboseCheckTarget.internal(e.getSender().getName());
this.plugin.getVerboseHandler().offerPermissionCheckEvent(CheckOrigin.PLATFORM_API_HAS_PERMISSION_SET, target, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.forMonitoredResult(result));
this.plugin.getPermissionRegistry().offer(permission);
}
use of net.luckperms.api.util.Tristate 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.util.Tristate in project LuckPerms by lucko.
the class ArgumentPermissions method checkModifyPerms.
/**
* Checks if the sender has permission to modify the given target
*
* @param plugin the plugin instance
* @param sender the sender to check
* @param base the base permission for the command
* @param target the object the sender is truing to modify
* @return true if the sender should NOT be allowed to modify the target, true if they should
*/
public static boolean checkModifyPerms(LuckPermsPlugin plugin, Sender sender, CommandPermission base, Object target) {
if (!plugin.getConfiguration().get(ConfigKeys.USE_ARGUMENT_BASED_COMMAND_PERMISSIONS)) {
return false;
}
if (target instanceof User) {
User targetUser = (User) target;
if (targetUser.getUniqueId().equals(sender.getUniqueId())) {
// the sender is trying to edit themselves
Tristate state = sender.getPermissionValue(base.getPermission() + ".modify.self");
if (state != Tristate.UNDEFINED) {
return !state.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalState = sender.getPermissionValue(USER_MODIFY_SELF);
return !globalState.asBoolean();
}
} else {
// they're trying to edit another user
Tristate state = sender.getPermissionValue(base.getPermission() + ".modify.others");
if (state != Tristate.UNDEFINED) {
return !state.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalState = sender.getPermissionValue(USER_MODIFY_OTHERS);
return !globalState.asBoolean();
}
}
} else if (target instanceof Group) {
Group targetGroup = (Group) target;
Tristate state = sender.getPermissionValue(base.getPermission() + ".modify." + targetGroup.getName());
if (state != Tristate.UNDEFINED) {
return !state.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalState = sender.getPermissionValue(GROUP_MODIFY.apply(targetGroup.getName()));
return !globalState.asBoolean();
}
} else if (target instanceof Track) {
Track targetTrack = (Track) target;
Tristate state = sender.getPermissionValue(base.getPermission() + ".modify." + targetTrack.getName());
if (state != Tristate.UNDEFINED) {
return !state.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalState = sender.getPermissionValue(TRACK_MODIFY.apply(targetTrack.getName()));
return !globalState.asBoolean();
}
} else {
throw new IllegalStateException();
}
}
use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.
the class PermissionSet method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) throws CommandException {
String node = args.get(0);
Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
ImmutableContextSet contextSet = args.getContextOrEmpty(2);
if (subjectData.setPermission(contextSet, node, tristate).join()) {
SpongeCommandUtils.sendPrefixed(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase(Locale.ROOT) + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
SpongeCommandUtils.sendPrefixed(sender, "Unable to set permission. Does the Subject already have it set?");
}
}
Aggregations