Search in sources :

Example 1 with OnStartupTasks

use of fr.xephi.authme.initialization.OnStartupTasks in project AuthMeReloaded by AuthMe.

the class AuthMe method initialize.

/**
     * Initialize the plugin and all the services.
     */
private void initialize() {
    // Set the Logger instance and log file path
    ConsoleLogger.setLogger(getLogger());
    ConsoleLogger.setLogFile(new File(getDataFolder(), LOG_FILENAME));
    // Check java version
    if (!SystemUtils.isJavaVersionAtLeast(1.8f)) {
        throw new IllegalStateException("You need Java 1.8 or above to run this plugin!");
    }
    OnStartupTasks.verifyIfLegacyJarIsNeeded();
    // Create plugin folder
    getDataFolder().mkdir();
    // Create injector, provide elements from the Bukkit environment and register providers
    injector = new InjectorBuilder().addHandlers(new FactoryDependencyHandler(), new SingletonStoreDependencyHandler()).addDefaultHandlers("fr.xephi.authme").create();
    injector.register(AuthMe.class, this);
    injector.register(Server.class, getServer());
    injector.register(PluginManager.class, getServer().getPluginManager());
    injector.register(BukkitScheduler.class, getServer().getScheduler());
    injector.provide(DataFolder.class, getDataFolder());
    injector.registerProvider(Settings.class, SettingsProvider.class);
    injector.registerProvider(DataSource.class, DataSourceProvider.class);
    // Get settings and set up logger
    settings = injector.getSingleton(Settings.class);
    ConsoleLogger.setLoggingOptions(settings);
    OnStartupTasks.setupConsoleFilter(settings, getLogger());
    // Set all service fields on the AuthMe class
    instantiateServices(injector);
    // Convert deprecated PLAINTEXT hash entries
    MigrationService.changePlainTextToSha256(settings, database, new Sha256());
    // If the server is empty (fresh start) just set all the players as unlogged
    if (bukkitService.getOnlinePlayers().isEmpty()) {
        database.purgeLogged();
    }
    // Register event listeners
    registerEventListeners(injector);
    // Start Email recall task if needed
    OnStartupTasks onStartupTasks = injector.newInstance(OnStartupTasks.class);
    onStartupTasks.scheduleRecallEmailTask();
}
Also used : OnStartupTasks(fr.xephi.authme.initialization.OnStartupTasks) SingletonStoreDependencyHandler(fr.xephi.authme.initialization.factory.SingletonStoreDependencyHandler) FactoryDependencyHandler(fr.xephi.authme.initialization.factory.FactoryDependencyHandler) InjectorBuilder(ch.jalu.injector.InjectorBuilder) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) RestrictionSettings(fr.xephi.authme.settings.properties.RestrictionSettings) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Settings(fr.xephi.authme.settings.Settings) EmailSettings(fr.xephi.authme.settings.properties.EmailSettings) Sha256(fr.xephi.authme.security.crypts.Sha256)

Aggregations

InjectorBuilder (ch.jalu.injector.InjectorBuilder)1 OnStartupTasks (fr.xephi.authme.initialization.OnStartupTasks)1 FactoryDependencyHandler (fr.xephi.authme.initialization.factory.FactoryDependencyHandler)1 SingletonStoreDependencyHandler (fr.xephi.authme.initialization.factory.SingletonStoreDependencyHandler)1 Sha256 (fr.xephi.authme.security.crypts.Sha256)1 Settings (fr.xephi.authme.settings.Settings)1 EmailSettings (fr.xephi.authme.settings.properties.EmailSettings)1 PluginSettings (fr.xephi.authme.settings.properties.PluginSettings)1 RestrictionSettings (fr.xephi.authme.settings.properties.RestrictionSettings)1 SecuritySettings (fr.xephi.authme.settings.properties.SecuritySettings)1 File (java.io.File)1 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)1