Search in sources :

Example 1 with PermissionVault

use of me.lucko.luckperms.common.treeview.PermissionVault in project LuckPerms by lucko.

the class TabCompletions method getPermissionTabComplete.

public static List<String> getPermissionTabComplete(List<String> args, PermissionVault cache) {
    if (args.size() <= 1) {
        if (args.isEmpty() || args.get(0).equals("")) {
            return cache.getRootNode().getChildren().map(Map::keySet).map(s -> (List<String>) new ArrayList<>(s)).orElse(Collections.emptyList());
        }
        String start = args.get(0).toLowerCase();
        List<String> parts = new ArrayList<>(Splitter.on('.').splitToList(start));
        TreeNode root = cache.getRootNode();
        if (parts.size() <= 1) {
            if (!root.getChildren().isPresent()) {
                return Collections.emptyList();
            }
            return root.getChildren().get().keySet().stream().filter(s -> s.startsWith(start)).collect(Collectors.toList());
        }
        String incomplete = parts.remove(parts.size() - 1);
        for (String s : parts) {
            if (!root.getChildren().isPresent()) {
                return Collections.emptyList();
            }
            TreeNode n = root.getChildren().get().get(s);
            if (n == null) {
                return Collections.emptyList();
            }
            root = n;
        }
        if (!root.getChildren().isPresent()) {
            return Collections.emptyList();
        }
        return root.getChildren().get().keySet().stream().filter(s -> s.startsWith(incomplete)).map(s -> parts.stream().collect(Collectors.joining(".")) + "." + s).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
Also used : PermissionVault(me.lucko.luckperms.common.treeview.PermissionVault) TreeNode(me.lucko.luckperms.common.treeview.TreeNode) Arrays(java.util.Arrays) List(java.util.List) Map(java.util.Map) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Splitter(com.google.common.base.Splitter) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TreeNode(me.lucko.luckperms.common.treeview.TreeNode) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with PermissionVault

use of me.lucko.luckperms.common.treeview.PermissionVault in project LuckPerms by lucko.

the class AbstractLuckPermsPlugin method enable.

public final void enable() {
    // send the startup banner
    displayBanner(getConsoleSender());
    // load some utilities early
    this.verboseHandler = new VerboseHandler();
    this.permissionVault = new PermissionVault();
    this.logDispatcher = new LogDispatcher(this);
    // load configuration
    getLogger().info("Loading configuration...");
    this.configuration = new AbstractConfiguration(this, provideConfigurationAdapter());
    this.configuration.loadAll();
    // load locale
    this.localeManager = new SimpleLocaleManager();
    this.localeManager.tryLoad(this, new File(getBootstrap().getConfigDirectory(), "lang.yml"));
    // now the configuration is loaded, we can create a storage factory and load initial dependencies
    StorageFactory storageFactory = new StorageFactory(this);
    Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
    this.dependencyManager.loadStorageDependencies(storageTypes);
    // register listeners
    registerPlatformListeners();
    // first, setup the file watcher, if enabled
    if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
        this.fileWatcher = new FileWatcher(this);
        getBootstrap().getScheduler().asyncRepeating(this.fileWatcher, 30L);
    }
    // initialise storage
    this.storage = storageFactory.getInstance(StorageType.H2);
    this.messagingService = provideMessagingFactory().getInstance();
    // setup the update task buffer
    this.updateTaskBuffer = new UpdateTaskBuffer(this);
    // register commands
    registerCommands();
    // load internal managers
    getLogger().info("Loading internal permission managers...");
    this.inheritanceHandler = new InheritanceHandler(this);
    this.cachedStateManager = new CachedStateManager();
    // setup user/group/track manager
    setupManagers();
    // init calculator factory
    this.calculatorFactory = provideCalculatorFactory();
    // setup contextmanager & register common calculators
    setupContextManager();
    getContextManager().registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
    // setup platform hooks
    setupPlatformHooks();
    // register with the LP API
    this.apiProvider = new LuckPermsApiProvider(this);
    this.eventFactory = new EventFactory(this, this.apiProvider);
    ApiRegistrationUtil.registerProvider(this.apiProvider);
    registerApiOnPlatform(this.apiProvider);
    // schedule update tasks
    int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
    if (mins > 0) {
        long ticks = mins * 60 * 20;
        getBootstrap().getScheduler().asyncRepeating(() -> this.updateTaskBuffer.request(), ticks);
    }
    getBootstrap().getScheduler().asyncLater(() -> this.updateTaskBuffer.request(), 40L);
    // run an update instantly.
    getLogger().info("Performing initial data load...");
    try {
        new UpdateTask(this, true).run();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // init housekeeping tasks
    registerHousekeepingTasks();
    // perform any platform-specific final setup tasks
    performFinalSetup();
    getLogger().info("Successfully enabled. (took " + (System.currentTimeMillis() - getBootstrap().getStartupTime()) + "ms)");
}
Also used : UpdateTask(me.lucko.luckperms.common.tasks.UpdateTask) LuckPermsApiProvider(me.lucko.luckperms.common.api.LuckPermsApiProvider) VerboseHandler(me.lucko.luckperms.common.verbose.VerboseHandler) StorageType(me.lucko.luckperms.common.storage.StorageType) PermissionVault(me.lucko.luckperms.common.treeview.PermissionVault) EventFactory(me.lucko.luckperms.common.event.EventFactory) AbstractConfiguration(me.lucko.luckperms.common.config.AbstractConfiguration) CachedStateManager(me.lucko.luckperms.common.caching.handlers.CachedStateManager) InheritanceHandler(me.lucko.luckperms.common.inheritance.InheritanceHandler) SimpleLocaleManager(me.lucko.luckperms.common.locale.SimpleLocaleManager) StorageFactory(me.lucko.luckperms.common.storage.StorageFactory) FileWatcher(me.lucko.luckperms.common.storage.dao.file.FileWatcher) UpdateTaskBuffer(me.lucko.luckperms.common.buffers.UpdateTaskBuffer) LogDispatcher(me.lucko.luckperms.common.actionlog.LogDispatcher) File(java.io.File) LuckPermsCalculator(me.lucko.luckperms.common.contexts.LuckPermsCalculator)

Aggregations

PermissionVault (me.lucko.luckperms.common.treeview.PermissionVault)2 Splitter (com.google.common.base.Splitter)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 LogDispatcher (me.lucko.luckperms.common.actionlog.LogDispatcher)1 LuckPermsApiProvider (me.lucko.luckperms.common.api.LuckPermsApiProvider)1 UpdateTaskBuffer (me.lucko.luckperms.common.buffers.UpdateTaskBuffer)1 CachedStateManager (me.lucko.luckperms.common.caching.handlers.CachedStateManager)1 AbstractConfiguration (me.lucko.luckperms.common.config.AbstractConfiguration)1 LuckPermsCalculator (me.lucko.luckperms.common.contexts.LuckPermsCalculator)1 EventFactory (me.lucko.luckperms.common.event.EventFactory)1 InheritanceHandler (me.lucko.luckperms.common.inheritance.InheritanceHandler)1 SimpleLocaleManager (me.lucko.luckperms.common.locale.SimpleLocaleManager)1 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)1 StorageFactory (me.lucko.luckperms.common.storage.StorageFactory)1