Search in sources :

Example 1 with EnvironmentVariableConfigAdapter

use of me.lucko.luckperms.common.config.generic.adapter.EnvironmentVariableConfigAdapter in project LuckPerms by lucko.

the class AbstractLuckPermsPlugin method enable.

public final void enable() {
    // load the sender factory instance
    setupSenderFactory();
    // send the startup banner
    Message.STARTUP_BANNER.send(getConsoleSender(), getBootstrap());
    // load some utilities early
    this.verboseHandler = new VerboseHandler(getBootstrap().getScheduler());
    this.logDispatcher = new LogDispatcher(this);
    // load configuration
    getLogger().info("Loading configuration...");
    ConfigurationAdapter configFileAdapter = provideConfigurationAdapter();
    this.configuration = new LuckPermsConfiguration(this, new MultiConfigurationAdapter(this, new SystemPropertyConfigAdapter(this), new EnvironmentVariableConfigAdapter(this), configFileAdapter));
    // setup a bytebin instance
    this.httpClient = new OkHttpClient.Builder().callTimeout(15, TimeUnit.SECONDS).build();
    this.bytebin = new BytebinClient(this.httpClient, getConfiguration().get(ConfigKeys.BYTEBIN_URL), "luckperms");
    this.bytesocks = new BytesocksClient(this.httpClient, getConfiguration().get(ConfigKeys.BYTESOCKS_HOST), "luckperms/editor");
    this.webEditorStore = new WebEditorStore(this);
    // init translation repo and update bundle files
    this.translationRepository = new TranslationRepository(this);
    this.translationRepository.scheduleRefresh();
    // 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();
    this.dependencyManager.loadStorageDependencies(storageTypes);
    // register listeners
    registerPlatformListeners();
    // first, setup the file watcher, if enabled
    if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
        try {
            this.fileWatcher = new FileWatcher(this, getBootstrap().getDataDirectory());
        } catch (Throwable e) {
            // catch throwable here, seems some JVMs throw UnsatisfiedLinkError when trying
            // to create a watch service. see: https://github.com/lucko/LuckPerms/issues/2066
            getLogger().warn("Error occurred whilst trying to create a file watcher:", e);
        }
    }
    // initialise storage
    this.storage = storageFactory.getInstance();
    this.messagingService = provideMessagingFactory().getInstance();
    // setup the update task buffer
    this.syncTaskBuffer = new SyncTask.Buffer(this);
    // register commands
    registerCommands();
    // load internal managers
    getLogger().info("Loading internal permission managers...");
    this.inheritanceGraphFactory = new InheritanceGraphFactory(this);
    // setup user/group/track manager
    setupManagers();
    // init calculator factory
    this.calculatorFactory = provideCalculatorFactory();
    // setup contextmanager & register common calculators
    setupContextManager();
    getContextManager().registerCalculator(new ConfigurationContextCalculator(getConfiguration()));
    // setup platform hooks
    setupPlatformHooks();
    // register with the LP API
    this.apiProvider = new LuckPermsApiProvider(this);
    this.apiProvider.ensureApiWasLoadedByPlugin();
    this.eventDispatcher = new EventDispatcher(provideEventBus(this.apiProvider));
    getBootstrap().getScheduler().executeAsync(GeneratedEventClass::preGenerate);
    ApiRegistrationUtil.registerProvider(this.apiProvider);
    registerApiOnPlatform(this.apiProvider);
    // setup extension manager
    this.extensionManager = new SimpleExtensionManager(this);
    this.extensionManager.loadExtensions(getBootstrap().getConfigDirectory().resolve("extensions"));
    // schedule update tasks
    int syncMins = getConfiguration().get(ConfigKeys.SYNC_TIME);
    if (syncMins > 0) {
        getBootstrap().getScheduler().asyncRepeating(() -> this.syncTaskBuffer.request(), syncMins, TimeUnit.MINUTES);
    }
    // run an update instantly.
    getLogger().info("Performing initial data load...");
    try {
        new SyncTask(this).run();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // init housekeeping tasks
    registerHousekeepingTasks();
    // perform any platform-specific final setup tasks
    performFinalSetup();
    Duration timeTaken = Duration.between(getBootstrap().getStartupTime(), Instant.now());
    getLogger().info("Successfully enabled. (took " + timeTaken.toMillis() + "ms)");
}
Also used : LuckPermsApiProvider(me.lucko.luckperms.common.api.LuckPermsApiProvider) VerboseHandler(me.lucko.luckperms.common.verbose.VerboseHandler) OkHttpClient(okhttp3.OkHttpClient) SyncTask(me.lucko.luckperms.common.tasks.SyncTask) WebEditorStore(me.lucko.luckperms.common.webeditor.store.WebEditorStore) BytebinClient(me.lucko.luckperms.common.http.BytebinClient) StorageFactory(me.lucko.luckperms.common.storage.StorageFactory) EventDispatcher(me.lucko.luckperms.common.event.EventDispatcher) MultiConfigurationAdapter(me.lucko.luckperms.common.config.generic.adapter.MultiConfigurationAdapter) ConfigurationAdapter(me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter) LogDispatcher(me.lucko.luckperms.common.actionlog.LogDispatcher) SystemPropertyConfigAdapter(me.lucko.luckperms.common.config.generic.adapter.SystemPropertyConfigAdapter) BytesocksClient(me.lucko.luckperms.common.http.BytesocksClient) ConfigurationContextCalculator(me.lucko.luckperms.common.context.calculator.ConfigurationContextCalculator) GeneratedEventClass(me.lucko.luckperms.common.event.gen.GeneratedEventClass) StorageType(me.lucko.luckperms.common.storage.StorageType) TranslationRepository(me.lucko.luckperms.common.locale.TranslationRepository) Duration(java.time.Duration) InheritanceGraphFactory(me.lucko.luckperms.common.inheritance.InheritanceGraphFactory) IOException(java.io.IOException) EnvironmentVariableConfigAdapter(me.lucko.luckperms.common.config.generic.adapter.EnvironmentVariableConfigAdapter) FileWatcher(me.lucko.luckperms.common.storage.implementation.file.watcher.FileWatcher) SimpleExtensionManager(me.lucko.luckperms.common.extension.SimpleExtensionManager) LuckPermsConfiguration(me.lucko.luckperms.common.config.LuckPermsConfiguration) MultiConfigurationAdapter(me.lucko.luckperms.common.config.generic.adapter.MultiConfigurationAdapter)

Aggregations

IOException (java.io.IOException)1 Duration (java.time.Duration)1 LogDispatcher (me.lucko.luckperms.common.actionlog.LogDispatcher)1 LuckPermsApiProvider (me.lucko.luckperms.common.api.LuckPermsApiProvider)1 LuckPermsConfiguration (me.lucko.luckperms.common.config.LuckPermsConfiguration)1 ConfigurationAdapter (me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter)1 EnvironmentVariableConfigAdapter (me.lucko.luckperms.common.config.generic.adapter.EnvironmentVariableConfigAdapter)1 MultiConfigurationAdapter (me.lucko.luckperms.common.config.generic.adapter.MultiConfigurationAdapter)1 SystemPropertyConfigAdapter (me.lucko.luckperms.common.config.generic.adapter.SystemPropertyConfigAdapter)1 ConfigurationContextCalculator (me.lucko.luckperms.common.context.calculator.ConfigurationContextCalculator)1 EventDispatcher (me.lucko.luckperms.common.event.EventDispatcher)1 GeneratedEventClass (me.lucko.luckperms.common.event.gen.GeneratedEventClass)1 SimpleExtensionManager (me.lucko.luckperms.common.extension.SimpleExtensionManager)1 BytebinClient (me.lucko.luckperms.common.http.BytebinClient)1 BytesocksClient (me.lucko.luckperms.common.http.BytesocksClient)1 InheritanceGraphFactory (me.lucko.luckperms.common.inheritance.InheritanceGraphFactory)1 TranslationRepository (me.lucko.luckperms.common.locale.TranslationRepository)1 StorageFactory (me.lucko.luckperms.common.storage.StorageFactory)1 StorageType (me.lucko.luckperms.common.storage.StorageType)1 FileWatcher (me.lucko.luckperms.common.storage.implementation.file.watcher.FileWatcher)1