use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.
the class ArgumentPermissions method checkViewPerms.
/**
* Checks if the sender has permission to view 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 view
* @return true if the sender should NOT be allowed to view the target, true if they should
*/
public static boolean checkViewPerms(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 view themselves
Tristate state = sender.getPermissionValue(base.getPermission() + ".view.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_VIEW_SELF);
return !globalState.asBoolean();
}
} else {
// they're trying to view another user
Tristate state = sender.getPermissionValue(base.getPermission() + ".view.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_VIEW_OTHERS);
return !globalState.asBoolean();
}
}
} else if (target instanceof Group) {
Group targetGroup = (Group) target;
Tristate state = sender.getPermissionValue(base.getPermission() + ".view." + 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_VIEW.apply(targetGroup.getName()));
return !globalState.asBoolean();
}
} else if (target instanceof Track) {
Track targetTrack = (Track) target;
Tristate state = sender.getPermissionValue(base.getPermission() + ".view." + 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_VIEW.apply(targetTrack.getName()));
return !globalState.asBoolean();
}
}
return false;
}
use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.
the class BungeePermissionCheckListener method onPlayerPermissionCheck.
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
if (!(e.getSender() instanceof ProxiedPlayer)) {
return;
}
Objects.requireNonNull(e.getPermission(), "permission");
Objects.requireNonNull(e.getSender(), "sender");
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
if (user == null) {
this.plugin.getLogger().warn("A permission check was made for player " + player.getName() + " - " + player.getUniqueId() + ", " + "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?", new Exception());
e.setHasPermission(false);
return;
}
QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player);
Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), CheckOrigin.PLATFORM_API_HAS_PERMISSION).result();
if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
// just use the result provided by the proxy when the event was created
return;
}
e.setHasPermission(result.asBoolean());
}
use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.
the class BungeePermissionCheckListener method onPlayerTristateCheck.
@EventHandler
public void onPlayerTristateCheck(TristateCheckEvent e) {
if (!(e.getSender() instanceof ProxiedPlayer)) {
return;
}
Objects.requireNonNull(e.getPermission(), "permission");
Objects.requireNonNull(e.getSender(), "sender");
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
if (user == null) {
this.plugin.getLogger().warn("A permission check was made for player " + player.getName() + " - " + player.getUniqueId() + ", " + "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?", new Exception());
e.setResult(Tristate.UNDEFINED);
return;
}
QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player);
Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), CheckOrigin.PLATFORM_API_HAS_PERMISSION_SET).result();
if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
// just use the result provided by the proxy when the event was created
return;
}
e.setResult(result);
}
use of net.luckperms.api.util.Tristate in project LuckPerms by lucko.
the class BungeePermissionCheckListener method onOtherPermissionCheck.
@EventHandler(priority = EventPriority.HIGHEST)
public void onOtherPermissionCheck(PermissionCheckEvent e) {
if (e.getSender() instanceof ProxiedPlayer) {
return;
}
Objects.requireNonNull(e.getPermission(), "permission");
Objects.requireNonNull(e.getSender(), "sender");
String permission = e.getPermission();
Tristate result = Tristate.of(e.hasPermission());
VerboseCheckTarget target = VerboseCheckTarget.internal(e.getSender().getName());
this.plugin.getVerboseHandler().offerPermissionCheckEvent(CheckOrigin.PLATFORM_API_HAS_PERMISSION, 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 SpongeSenderFactory method getPermissionValue.
@Override
protected Tristate getPermissionValue(Audience source, String node) {
if (!(source instanceof Subject)) {
throw new IllegalStateException("Source is not a subject");
}
final Subject subject = (Subject) source;
Tristate result = CompatibilityUtil.convertTristate(subject.permissionValue(node));
// check the permdefault
if (result == Tristate.UNDEFINED && subject.hasPermission(node)) {
result = Tristate.TRUE;
}
return result;
}
Aggregations