Search in sources :

Example 1 with FileStats

use of pl.plajer.villagedefense3.database.FileStats in project Village_Defense by Plajer.

the class Main method onEnable.

@Override
public void onEnable() {
    version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
    new ConfigurationManager(this);
    LanguageManager.init(this);
    if (!(getVersion().equalsIgnoreCase("v1_8_R3") || getVersion().equalsIgnoreCase("v1_9_R1") || getVersion().equalsIgnoreCase("v1_11_R1") || getVersion().equalsIgnoreCase("v1_12_R1"))) {
        BigTextUtils.thisVersionIsNotSupported();
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Your server version is not supported by Village Defense!");
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Sadly, we must shut off. Maybe you consider changing your server version?");
        forceDisable = true;
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    try {
        Class.forName("org.spigotmc.SpigotConfig");
    } catch (Exception e) {
        BigTextUtils.thisVersionIsNotSupported();
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Your server software is not supported by Village Defense!");
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "We support only Spigot and Spigot forks only! Shutting off...");
        forceDisable = true;
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // check if using releases before 2.1.0
    if (LanguageManager.getLanguageFile().isSet("STATS-AboveLine") && LanguageManager.getLanguageFile().isSet("SCOREBOARD-Zombies")) {
        migrateToNewFormat();
    }
    // check if using releases 2.1.0+
    if (LanguageManager.getLanguageFile().isSet("File-Version") && getConfig().isSet("Config-Version")) {
        migrateToNewFormat();
    }
    LanguageManager.saveDefaultLanguageFile();
    saveDefaultConfig();
    debug = getConfig().getBoolean("Debug");
    if (Main.isDebugged()) {
        System.out.println("[Village Debugger] Village Defense setup started!");
    }
    setupFiles();
    debugChecker();
    LanguageMigrator.languageFileUpdate();
    setupLocale();
    initializeClasses();
    String currentVersion = "v" + Bukkit.getPluginManager().getPlugin("VillageDefense").getDescription().getVersion();
    if (getConfig().getBoolean("Update-Notifier.Enabled")) {
        try {
            UpdateChecker.checkUpdate(currentVersion);
            String latestVersion = UpdateChecker.getLatestVersion();
            if (latestVersion != null) {
                latestVersion = "v" + latestVersion;
                if (latestVersion.contains("b")) {
                    Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[VillageDefense] Your software is ready for update! However it's a BETA VERSION. Proceed with caution.");
                    Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[VillageDefense] Current version %old%, latest version %new%".replaceAll("%old%", currentVersion).replaceAll("%new%", latestVersion));
                } else {
                    BigTextUtils.updateIsHere();
                    Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Your Village Defense plugin is up to date! Download it to keep with latest changes and fixes.");
                    Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Disable this option in config.yml if you wish.");
                    Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "Current version: " + ChatColor.RED + currentVersion + ChatColor.YELLOW + " Latest version: " + ChatColor.GREEN + latestVersion);
                }
            }
        } catch (Exception ex) {
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[VillageDefense] An error occured while checking for update!");
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Please check internet connection or check for update via WWW site directly!");
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "WWW site https://www.spigotmc.org/resources/minigame-village-defence-1-12-and-1-8-8.41869/");
        }
    }
    STARTING_TIMER_TIME = getConfig().getInt("Starting-Waiting-Time");
    MINI_ZOMBIE_SPEED = (float) getConfig().getDouble("Mini-Zombie-Speed");
    ZOMBIE_SPEED = (float) getConfig().getDouble("Zombie-Speed");
    databaseActivated = getConfig().getBoolean("DatabaseActivated");
    inventoryManagerEnabled = getConfig().getBoolean("InventoryManager");
    if (databaseActivated) {
        database = new MySQLDatabase(this);
    } else {
        fileStats = new FileStats(this);
    }
    bossbarEnabled = getConfig().getBoolean("Bossbar-Enabled");
    if (is1_8_R3()) {
        bossbarEnabled = false;
    }
    getServer().getPluginManager().registerEvents(this, this);
    BreakFenceListener listener = new BreakFenceListener();
    listener.runTaskTimer(this, 1L, 20L);
    setupGameKits();
    SpecialItem.loadAll();
    registerArenas();
    new ShopManager();
    // we must start it after instances load!
    signManager = new SignManager(this);
    chatFormat = getConfig().getBoolean("ChatFormat-Enabled");
    ConfigurationSection cs = getConfig().getConfigurationSection("CustomPermissions");
    for (String key : cs.getKeys(false)) {
        customPermissions.put(key, getConfig().getInt("CustomPermissions." + key));
        if (isDebugged()) {
            System.out.println("[Village Debugger] Loaded custom permission " + key + "!");
        }
    }
    for (Player p : Bukkit.getOnlinePlayers()) {
        UserManager.registerUser(p.getUniqueId());
    }
    if (databaseActivated) {
        for (Player p : Bukkit.getOnlinePlayers()) {
            MySQLConnectionUtils.loadPlayerStats(p, this);
        }
    } else {
        fileStats.loadStatsForPlayersOnline();
    }
    StatsStorage.plugin = this;
    setupPermissions();
}
Also used : SignManager(pl.plajer.villagedefense3.handlers.SignManager) Player(org.bukkit.entity.Player) BreakFenceListener(pl.plajer.villagedefense3.creatures.BreakFenceListener) FileStats(pl.plajer.villagedefense3.database.FileStats) MySQLDatabase(pl.plajer.villagedefense3.database.MySQLDatabase) ShopManager(pl.plajer.villagedefense3.handlers.ShopManager) ConfigurationManager(pl.plajer.villagedefense3.handlers.ConfigurationManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 Player (org.bukkit.entity.Player)1 BreakFenceListener (pl.plajer.villagedefense3.creatures.BreakFenceListener)1 FileStats (pl.plajer.villagedefense3.database.FileStats)1 MySQLDatabase (pl.plajer.villagedefense3.database.MySQLDatabase)1 ConfigurationManager (pl.plajer.villagedefense3.handlers.ConfigurationManager)1 ShopManager (pl.plajer.villagedefense3.handlers.ShopManager)1 SignManager (pl.plajer.villagedefense3.handlers.SignManager)1