@@ -0,0 +1,3325 @@
+/*%0A * This file is part of Orbit, licenced under the MIT Licence (MIT)%0A *%0A * Copyright (c) Vayzd Network %3Chttps://www.vayzd.net/%3E%0A * Copyright (c) contributors%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the Software is%0A * furnished to do so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in all%0A * copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0A * SOFTWARE.%0A */%0Apackage net.vayzd.orbit.datastore.group;%0A%0Aimport lombok.*;%0A%0Aimport java.util.*;%0Aimport java.util.concurrent.*;%0Aimport java.util.regex.*;%0A%0Aimport static java.util.regex.Pattern.*;%0A%0Afinal class PermissionMatcher %7B%0A%0A    private ConcurrentMap%3CString, Boolean%3E cache = null;%0A    private Set%3CPattern%3E patternSet;%0A    @Getter%0A    private final TreeSet%3CString%3E permissionSet;%0A%0A    PermissionMatcher(TreeSet%3CString%3E permissionSet, boolean caching) %7B%0A        this.patternSet = new HashSet%3C%3E();%0A        this.permissionSet = permissionSet;%0A        deliver();%0A        if (caching) %7B%0A            cache = new ConcurrentHashMap%3C%3E();%0A        %7D%0A    %7D%0A%0A    void updatePermissionSet(TreeSet%3CString%3E updatedSet) %7B%0A        permissionSet.clear();%0A        permissionSet.addAll(updatedSet);%0A        deliver();%0A        purgeCache();%0A    %7D%0A%0A    boolean hasPermission(String permission) %7B%0A        if (cache != null && cache.containsKey(permission)) %7B%0A            return cache.get(permission);%0A        %7D%0A        for (Pattern pattern : patternSet) %7B%0A            if (pattern.matcher(permission).matches()) %7B%0A                if (cache != null) %7B%0A                    cache.put(permission, true);%0A                %7D%0A                return true;%0A            %7D%0A        %7D%0A        if (cache != null) %7B%0A            cache.put(permission, false);%0A        %7D%0A        return false;%0A    %7D%0A%0A    private void purgeCache() %7B%0A        if (cache != null) %7B%0A            cache.clear();%0A        %7D%0A    %7D%0A%0A    private void deliver() %7B%0A        patternSet.clear();%0A        permissionSet.forEach(permission -%3E patternSet.add(create(permission)));%0A    %7D%0A%0A    private Pattern create(String permission) %7B%0A        try %7B%0A            return compile(prepare(permission), Pattern.CASE_INSENSITIVE);%0A        %7D catch (PatternSyntaxException ex) %7B%0A            return compile(quote(permission), Pattern.CASE_INSENSITIVE);%0A        %7D%0A    %7D%0A%0A    private String prepare(String permission) %7B%0A        if (permission.startsWith(%22$%22)) %7B%0A            return permission.substring(1);%0A        %7D%0A        return permission.replace(%22.%22, %22%5C%5C.%22).replace(%22*%22, %22(.*)%22);%0A    %7D%0A%7D

Add PermissionMatcher class