# Source code
source: package: co.aikar.commands, class: JDACommandPermissionResolver

    001package co.aikar.commands;
    002
    003import net.dv8tion.jda.api.Permission;
    004
    005import java.util.HashMap;
    006import java.util.Locale;
    007import java.util.Map;
    008
    009public class JDACommandPermissionResolver implements CommandPermissionResolver {
    010    private Map<String, Integer> discordPermissionOffsets;
    011
    012    public JDACommandPermissionResolver() {
    013        discordPermissionOffsets = new HashMap<>();
    014        for (Permission permission : Permission.values()) {
    015            discordPermissionOffsets.put(permission.name().toLowerCase(Locale.ENGLISH).replaceAll("_", "-"), permission.getOffset());
    016        }
    017    }
    018
    019    @Override
    020    public boolean hasPermission(JDACommandManager manager, JDACommandEvent event, String permission) {
    021        // Explicitly return true if the issuer is the bot's owner. They are always allowed.
    022        if (manager.getBotOwnerId() == event.getIssuer().getAuthor().getIdLong()) {
    023            return true;
    024        }
    025
    026        // Return false on webhook messages, as they cannot have permissions defined.
    027        if (event.getIssuer().isWebhookMessage()) {
    028            return false;
    029        }
    030
    031        Integer permissionOffset = discordPermissionOffsets.get(permission);
    032        if (permissionOffset == null) {
    033            return false;
    034        }
    035
    036        return event.getIssuer().getMember().hasPermission(
    037                Permission.getFromOffset(permissionOffset)
    038        );
    039    }
    040}