Search in sources :

Example 1 with LangUtil

use of com.alpsbte.plotsystem.utils.io.language.LangUtil in project Plot-System by AlpsBTE.

the class PlotSystem method onEnable.

@Override
public void onEnable() {
    // Disable Logging
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
    plugin = this;
    String successPrefix = ChatColor.DARK_GRAY + "[" + ChatColor.DARK_GREEN + "✔" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY;
    String errorPrefix = ChatColor.DARK_GRAY + "[" + ChatColor.RED + "X" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY;
    Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "------------------ Plot-System V" + VERSION + " ------------------");
    Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "Starting plugin...");
    Bukkit.getConsoleSender().sendMessage("");
    // Check for required dependencies, if it returns false disable plugin
    if (!DependencyManager.checkForRequiredDependencies()) {
        Bukkit.getConsoleSender().sendMessage(errorPrefix + "Could not load required dependencies.");
        Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "Missing Dependencies:");
        DependencyManager.missingDependencies.forEach(dependency -> Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + " - " + dependency));
        this.getServer().getPluginManager().disablePlugin(this);
        return;
    }
    Bukkit.getConsoleSender().sendMessage(successPrefix + "Successfully loaded required dependencies.");
    // Load config, if it throws an exception disable plugin
    try {
        configManager = new ConfigUtil();
        Bukkit.getConsoleSender().sendMessage(successPrefix + "Successfully loaded configuration files.");
    } catch (ConfigNotImplementedException ex) {
        Bukkit.getConsoleSender().sendMessage(errorPrefix + "Could not load configuration file.");
        Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "The config file must be configured!");
        this.getServer().getPluginManager().disablePlugin(this);
        return;
    }
    this.configManager.reloadFiles();
    // Load language files
    try {
        langUtil = new LangUtil();
        Bukkit.getConsoleSender().sendMessage(successPrefix + "Successfully loaded language files.");
    } catch (Exception ex) {
        Bukkit.getConsoleSender().sendMessage(errorPrefix + "Could not load language file.");
        Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        this.getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // Initialize database connection
    try {
        DatabaseConnection.InitializeDatabase();
        Bukkit.getConsoleSender().sendMessage(successPrefix + "Successfully initialized database connection.");
    } catch (Exception ex) {
        Bukkit.getConsoleSender().sendMessage(errorPrefix + "Could not initialize database connection.");
        Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        this.getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // Register event listeners
    try {
        this.getServer().getPluginManager().registerEvents(new EventListener(), this);
        this.getServer().getPluginManager().registerEvents(new MenuFunctionListener(), this);
        Bukkit.getConsoleSender().sendMessage(successPrefix + "Successfully registered event listeners.");
    } catch (Exception ex) {
        Bukkit.getConsoleSender().sendMessage(errorPrefix + "Could not register event listeners.");
        Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        this.getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // Register commands
    try {
        commandManager = new CommandManager();
        commandManager.init();
        Bukkit.getConsoleSender().sendMessage(successPrefix + "Successfully registered commands.");
    } catch (Exception ex) {
        Bukkit.getConsoleSender().sendMessage(errorPrefix + "Could not register commands.");
        Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        this.getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // Check for extensions
    Bukkit.getConsoleSender().sendMessage("");
    Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "Extensions:");
    if (DependencyManager.isHolographicDisplaysEnabled()) {
        reloadHolograms();
        Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "- HolographicDisplays (Leaderboards)");
    } else {
        Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "No extensions enabled.");
    }
    // Check for updates
    Bukkit.getConsoleSender().sendMessage("");
    Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "Update-Checker:");
    UpdateChecker.getVersion(version -> {
        if (version.equalsIgnoreCase(VERSION)) {
            Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "You are using the latest stable version.");
        } else {
            UpdateChecker.isUpdateAvailable = true;
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You are using a outdated version!");
            Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "Latest version: " + ChatColor.GREEN + version + ChatColor.GRAY + " | Your version: " + ChatColor.RED + VERSION);
            Bukkit.getConsoleSender().sendMessage(ChatColor.GRAY + "Update here: " + ChatColor.AQUA + "https://github.com/AlpsBTE/Plot-System/releases");
        }
    });
    PlotManager.checkPlotsForLastActivity();
    PlotManager.syncPlotSchematicFiles();
    pluginEnabled = true;
    Bukkit.getConsoleSender().sendMessage("");
    Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "Enabled Plot-System plugin.");
    Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "------------------------------------------------------");
    Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + "Made by " + ChatColor.RED + "Alps BTE (AT/CH/LI)");
    Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + "GitHub: " + ChatColor.WHITE + "https://github.com/AlpsBTE/Plot-System");
    Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "------------------------------------------------------");
}
Also used : ConfigNotImplementedException(com.alpsbte.plotsystem.utils.io.config.ConfigNotImplementedException) ConfigUtil(com.alpsbte.plotsystem.utils.io.config.ConfigUtil) MenuFunctionListener(org.ipvp.canvas.MenuFunctionListener) EventListener(com.alpsbte.plotsystem.core.EventListener) LangUtil(com.alpsbte.plotsystem.utils.io.language.LangUtil) ConfigNotImplementedException(com.alpsbte.plotsystem.utils.io.config.ConfigNotImplementedException) IOException(java.io.IOException)

Aggregations

EventListener (com.alpsbte.plotsystem.core.EventListener)1 ConfigNotImplementedException (com.alpsbte.plotsystem.utils.io.config.ConfigNotImplementedException)1 ConfigUtil (com.alpsbte.plotsystem.utils.io.config.ConfigUtil)1 LangUtil (com.alpsbte.plotsystem.utils.io.language.LangUtil)1 IOException (java.io.IOException)1 MenuFunctionListener (org.ipvp.canvas.MenuFunctionListener)1