Search in sources :

Example 1 with SlimefunStartupTask

use of io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask in project Slimefun4 by Slimefun.

the class Slimefun method onPluginStart.

/**
 * This is our start method for a correct Slimefun installation.
 */
private void onPluginStart() {
    long timestamp = System.nanoTime();
    Logger logger = getLogger();
    // Check if Paper (<3) is installed
    if (PaperLib.isPaper()) {
        logger.log(Level.INFO, "Paper was detected! Performance optimizations have been applied.");
    } else {
        PaperLib.suggestPaper(this);
    }
    // Check if CS-CoreLib is installed (it is no longer needed)
    if (getServer().getPluginManager().getPlugin("CS-CoreLib") != null) {
        StartupWarnings.discourageCSCoreLib(logger);
    }
    // Encourage newer Java version
    if (NumberUtils.getJavaVersion() < RECOMMENDED_JAVA_VERSION) {
        StartupWarnings.oldJavaVersion(logger, RECOMMENDED_JAVA_VERSION);
    }
    // If the server has no "data-storage" folder, it's _probably_ a new install. So mark it for metrics.
    isNewlyInstalled = !new File("data-storage/Slimefun").exists();
    // Creating all necessary Folders
    logger.log(Level.INFO, "Creating directories...");
    createDirectories();
    // Load various config settings into our cache
    registry.load(this, config);
    // Set up localization
    logger.log(Level.INFO, "Loading language files...");
    String chatPrefix = config.getString("options.chat-prefix");
    String serverDefaultLanguage = config.getString("options.language");
    local = new LocalizationService(this, chatPrefix, serverDefaultLanguage);
    int networkSize = config.getInt("networks.max-size");
    // Make sure that the network size is a valid input
    if (networkSize < 1) {
        logger.log(Level.WARNING, "Your 'networks.max-size' setting is misconfigured! It must be at least 1, it was set to: {0}", networkSize);
        networkSize = 1;
    }
    networkManager = new NetworkManager(networkSize, config.getBoolean("networks.enable-visualizer"), config.getBoolean("networks.delete-excess-items"));
    // Setting up bStats
    new Thread(metricsService::start, "Slimefun Metrics").start();
    // Starting the Auto-Updater
    if (config.getBoolean("options.auto-update")) {
        logger.log(Level.INFO, "Starting Auto-Updater...");
        updaterService.start();
    } else {
        updaterService.disable();
    }
    // Registering all GEO Resources
    logger.log(Level.INFO, "Loading GEO-Resources...");
    GEOResourcesSetup.setup();
    logger.log(Level.INFO, "Loading Tags...");
    loadTags();
    logger.log(Level.INFO, "Loading items...");
    loadItems();
    logger.log(Level.INFO, "Loading researches...");
    loadResearches();
    registry.setResearchingEnabled(getResearchCfg().getBoolean("enable-researching"));
    PostSetup.setupWiki();
    logger.log(Level.INFO, "Registering listeners...");
    registerListeners();
    // Initiating various Stuff and all items with a slight delay (0ms after the Server finished loading)
    runSync(new SlimefunStartupTask(this, () -> {
        textureService.register(registry.getAllSlimefunItems(), true);
        permissionsService.register(registry.getAllSlimefunItems(), true);
        // This try/catch should prevent buggy Spigot builds from blocking item loading
        try {
            recipeService.refresh();
        } catch (Exception | LinkageError x) {
            logger.log(Level.SEVERE, x, () -> "An Exception occurred while iterating through the Recipe list on Minecraft Version " + minecraftVersion.getName() + " (Slimefun v" + getVersion() + ")");
        }
    }), 0);
    // Setting up our commands
    try {
        command.register();
    } catch (Exception | LinkageError x) {
        logger.log(Level.SEVERE, "An Exception occurred while registering the /slimefun command", x);
    }
    // Armor Update Task
    if (config.getBoolean("options.enable-armor-effects")) {
        boolean radioactiveFire = config.getBoolean("options.burn-players-when-radioactive");
        getServer().getScheduler().runTaskTimerAsynchronously(this, new ArmorTask(radioactiveFire), 0L, config.getInt("options.armor-update-interval") * 20L);
    }
    // Starting our tasks
    autoSavingService.start(this, config.getInt("options.auto-save-delay-in-minutes"));
    hologramsService.start();
    ticker.start(this);
    // Loading integrations
    logger.log(Level.INFO, "Loading Third-Party plugin integrations...");
    integrations.start();
    gitHubService.start(this);
    // Hooray!
    logger.log(Level.INFO, "Slimefun has finished loading in {0}", getStartupTime(timestamp));
}
Also used : ArmorTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask) LocalizationService(io.github.thebusybiscuit.slimefun4.core.services.LocalizationService) SlimefunStartupTask(io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask) Logger(java.util.logging.Logger) TagMisconfigurationException(io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException) NetworkManager(io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile)

Aggregations

TagMisconfigurationException (io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException)1 NetworkManager (io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager)1 LocalizationService (io.github.thebusybiscuit.slimefun4.core.services.LocalizationService)1 ArmorTask (io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask)1 SlimefunStartupTask (io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask)1 File (java.io.File)1 Logger (java.util.logging.Logger)1 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)1