use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class PermissionSet method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
String node = args.get(0);
Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
if (subjectData.setPermission(contextSet, node, tristate).join()) {
MessageUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?");
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class DescriptionBuilder method register.
@Nonnull
@Override
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(ContextSet.empty(), this.id, assignment.getValue());
}
this.service.getPlugin().getPermissionVault().offer(this.id);
// null stuff so this instance can be reused
this.roles.clear();
this.id = null;
this.description = null;
return description.sponge();
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class DescriptionBuilder method register.
@Nonnull
@Override
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(ContextSet.empty(), this.id, assignment.getValue());
}
this.service.getPlugin().getPermissionVault().offer(this.id);
// null stuff so this instance can be reused
this.roles.clear();
this.id = null;
this.description = null;
return description.sponge();
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class SpongeWildcardProcessor method hasPermission.
@Override
public Tristate hasPermission(String permission) {
String node = permission;
while (true) {
int endIndex = node.lastIndexOf(ImmutableNode.NODE_SEPARATOR);
if (endIndex == -1) {
break;
}
node = node.substring(0, endIndex);
if (!node.isEmpty()) {
Tristate t = Tristate.fromNullableBoolean(this.sourceMap.get(node));
if (t != Tristate.UNDEFINED) {
return t;
}
}
}
return Tristate.UNDEFINED;
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class VaultPermissionHook method groupHasPermission.
@Override
public boolean groupHasPermission(String world, String name, String permission) {
Objects.requireNonNull(name, "name");
Objects.requireNonNull(permission, "permission");
Group group = getGroup(name);
if (group == null) {
return false;
}
Contexts contexts = contextForLookup(null, world);
PermissionCache permissionData = group.getCachedData().getPermissionData(contexts);
Tristate result = permissionData.getPermissionValue(permission, CheckOrigin.INTERNAL);
if (log()) {
logMsg("#groupHasPermission: %s - %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), permission, result);
}
return result.asBoolean();
}
Aggregations