use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class DefaultsProcessor method hasPermission.
@Override
public Tristate hasPermission(String permission) {
Tristate t = this.plugin.getDefaultPermissionMap().lookupDefaultPermission(permission, this.isOp);
if (t != Tristate.UNDEFINED) {
return t;
}
Permission defPerm = this.plugin.getPermissionMap().get(permission);
return defPerm == null ? Tristate.UNDEFINED : Tristate.fromBoolean(defPerm.getDefault().getValue(this.isOp));
}
use of me.lucko.luckperms.api.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();
String name = "internal/" + e.getSender().getName();
this.plugin.getVerboseHandler().offerCheckData(CheckOrigin.PLATFORM_LOOKUP_CHECK, name, ContextSet.empty(), permission, result);
this.plugin.getPermissionVault().offer(permission);
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class CheckCommand method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
String target = args.get(0);
String permission = args.get(1);
User user;
UUID u = Uuids.parseNullable(target);
if (u != null) {
user = plugin.getUserManager().getIfLoaded(u);
} else {
user = plugin.getUserManager().getByUsername(target);
}
if (user == null) {
Message.USER_NOT_ONLINE.send(sender, target);
return CommandResult.STATE_ERROR;
}
Tristate tristate = user.getCachedData().getPermissionData(plugin.getContextForUser(user).orElse(plugin.getContextManager().getStaticContexts())).getPermissionValue(permission, CheckOrigin.INTERNAL);
Message.CHECK_RESULT.send(sender, user.getFriendlyName(), permission, MessageUtils.formatTristate(tristate));
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class PermissionCheck method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
String node = ArgumentParser.parseString(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
Tristate result = holder.hasPermission(NodeFactory.builder(node).withExtraContext(context).build(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
String s = MessageUtils.formatTristate(result);
Message.CHECK_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context));
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.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.getUuid().equals(sender.getUuid())) {
// the sender is trying to edit themselves
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify.self");
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(USER_MODIFY_SELF);
return !globalRet.asBoolean();
}
} else {
// they're trying to edit another user
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify.others");
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(USER_MODIFY_OTHERS);
return !globalRet.asBoolean();
}
}
} else if (target instanceof Group) {
Group targetGroup = ((Group) target);
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify." + targetGroup.getName());
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(GROUP_MODIFY.apply(targetGroup.getName()));
return !globalRet.asBoolean();
}
} else if (target instanceof Track) {
Track targetTrack = ((Track) target);
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify." + targetTrack.getName());
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(TRACK_MODIFY.apply(targetTrack.getName()));
return !globalRet.asBoolean();
}
} else {
throw new IllegalStateException();
}
}
Aggregations