Search in sources :

Example 1 with LeaderboardManager

use of com.archyx.aureliumskills.leaderboard.LeaderboardManager in project AureliumSkills by Archy-X.

the class StorageProvider method sortLeaderboards.

protected void sortLeaderboards(Map<Skill, List<SkillValue>> leaderboards, List<SkillValue> powerLeaderboard, List<SkillValue> averageLeaderboard) {
    LeaderboardManager manager = plugin.getLeaderboardManager();
    LeaderboardSorter sorter = new LeaderboardSorter();
    for (Skill skill : Skills.values()) {
        leaderboards.get(skill).sort(sorter);
    }
    powerLeaderboard.sort(sorter);
    AverageSorter averageSorter = new AverageSorter();
    averageLeaderboard.sort(averageSorter);
    // Add skill leaderboards to map
    for (Skill skill : Skills.values()) {
        manager.setLeaderboard(skill, leaderboards.get(skill));
    }
    manager.setPowerLeaderboard(powerLeaderboard);
    manager.setAverageLeaderboard(averageLeaderboard);
    manager.setSorting(false);
}
Also used : LeaderboardSorter(com.archyx.aureliumskills.leaderboard.LeaderboardSorter) Skill(com.archyx.aureliumskills.skills.Skill) LeaderboardManager(com.archyx.aureliumskills.leaderboard.LeaderboardManager) AverageSorter(com.archyx.aureliumskills.leaderboard.AverageSorter)

Example 2 with LeaderboardManager

use of com.archyx.aureliumskills.leaderboard.LeaderboardManager in project AureliumSkills by Archy-X.

the class AureliumSkills method onEnable.

public void onEnable() {
    // Registries
    statRegistry = new StatRegistry();
    registerStats();
    skillRegistry = new SkillRegistry();
    registerSkills();
    sourceRegistry = new SourceRegistry();
    itemRegistry = new ItemRegistry(this);
    inventoryManager = new InventoryManager(this);
    inventoryManager.init();
    AureliumAPI.setPlugin(this);
    // Checks for world guard
    if (getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
        if (WorldGuardPlugin.inst().getDescription().getVersion().contains("7.0")) {
            worldGuardEnabled = true;
            worldGuardSupport = new WorldGuardSupport(this);
            worldGuardSupport.loadRegions();
        }
    } else {
        worldGuardEnabled = false;
    }
    // Checks for PlaceholderAPI
    if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
        new PlaceholderSupport(this).register();
        placeholderAPIEnabled = true;
        getLogger().info("PlaceholderAPI Support Enabled!");
    } else {
        placeholderAPIEnabled = false;
    }
    // Checks for Vault
    if (setupEconomy()) {
        vaultEnabled = true;
        getLogger().info("Vault Support Enabled!");
    } else {
        vaultEnabled = false;
    }
    // Check for protocol lib
    protocolLibEnabled = Bukkit.getPluginManager().isPluginEnabled("ProtocolLib");
    // Check towny
    townyEnabled = Bukkit.getPluginManager().isPluginEnabled("Towny");
    townySupport = new TownySupport(this);
    // Check for LuckPerms
    luckPermsEnabled = Bukkit.getPluginManager().isPluginEnabled("LuckPerms");
    if (luckPermsEnabled) {
        luckPermsSupport = new LuckPermsSupport();
    }
    // Check for Slimefun
    slimefunEnabled = Bukkit.getPluginManager().isPluginEnabled("Slimefun");
    if (slimefunEnabled) {
        getServer().getPluginManager().registerEvents(new SlimefunSupport(this), this);
        getLogger().info("Slimefun Support Enabled!");
    }
    // Load health
    Health health = new Health(this);
    this.health = health;
    getServer().getPluginManager().registerEvents(health, this);
    // Load config
    loadConfig();
    this.requirementManager = new RequirementManager(this);
    optionLoader = new OptionL(this);
    optionLoader.loadOptions();
    requirementManager.load();
    this.modifierManager = new ModifierManager(this);
    // Load sources
    sourceManager = new SourceManager(this);
    sourceManager.loadSources();
    // Load boss bar
    bossBar = new SkillBossBar(this);
    bossBar.loadOptions();
    // Checks for holographic displays
    if (Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
        holographicDisplaysEnabled = true;
        getServer().getPluginManager().registerEvents(new HologramSupport(this), this);
        getLogger().info("HolographicDisplays Support Enabled!");
    } else {
        holographicDisplaysEnabled = false;
    }
    commandManager = new PaperCommandManager(this);
    // Load	 items
    itemRegistry.loadFromFile();
    // Load languages
    lang = new Lang(this);
    getServer().getPluginManager().registerEvents(lang, this);
    lang.init();
    lang.loadEmbeddedMessages(commandManager);
    lang.loadLanguages(commandManager);
    // Load rewards
    rewardManager = new RewardManager(this);
    rewardManager.loadRewards();
    // Registers Commands
    registerCommands();
    // Load menu
    menuLoader = new MenuLoader(this);
    try {
        menuLoader.load();
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
        e.printStackTrace();
        getLogger().warning("Error loading menus!");
    }
    // Region manager
    this.regionManager = new RegionManager(this);
    // Registers events
    registerEvents();
    // Load ability manager
    manaAbilityManager = new ManaAbilityManager(this);
    getServer().getPluginManager().registerEvents(manaAbilityManager, this);
    manaAbilityManager.init();
    // Load ability options
    abilityManager = new AbilityManager(this);
    abilityManager.loadOptions();
    // Load stats
    Regeneration regeneration = new Regeneration(this);
    getServer().getPluginManager().registerEvents(regeneration, this);
    regeneration.startRegen();
    regeneration.startSaturationRegen();
    // Load Action Bar
    if (protocolLibEnabled) {
        protocolLibSupport = new ProtocolLibSupport();
        new ActionBarCompatHandler(this).registerListeners();
    }
    actionBar.startUpdateActionBar();
    // Initialize storage
    this.playerManager = new PlayerManager(this);
    this.leaderboardManager = new LeaderboardManager();
    // Set proper storage provider
    if (OptionL.getBoolean(Option.MYSQL_ENABLED)) {
        MySqlStorageProvider mySqlStorageProvider = new MySqlStorageProvider(this);
        mySqlStorageProvider.init();
        MysqlBackup mysqlBackup = new MysqlBackup(this, mySqlStorageProvider);
        if (!mySqlStorageProvider.localeColumnExists()) {
            mysqlBackup.saveBackup(Bukkit.getConsoleSender(), false);
        }
        new LegacyMysqlToMysqlConverter(this, mySqlStorageProvider).convert();
        setStorageProvider(mySqlStorageProvider);
        this.backupProvider = mysqlBackup;
    } else {
        // Try to backup and convert legacy files
        new LegacyFileBackup(this).saveBackup(Bukkit.getConsoleSender(), false);
        new LegacyFileToYamlConverter(this).convert();
        setStorageProvider(new YamlStorageProvider(this));
        this.backupProvider = new YamlBackup(this);
    }
    // Initialize leaderboards
    new BukkitRunnable() {

        @Override
        public void run() {
            if (leaderboardManager.isNotSorting()) {
                storageProvider.updateLeaderboards();
            }
        }
    }.runTaskTimerAsynchronously(this, 0, 12000);
    // Load leveler
    leveler = new Leveler(this);
    leveler.loadLevelRequirements();
    // Load loot tables
    lootTableManager = new LootTableManager(this);
    // Load world manager
    worldManager = new WorldManager(this);
    worldManager.loadWorlds();
    // B-stats
    int pluginId = 8629;
    new Metrics(this, pluginId);
    getLogger().info("Aurelium Skills has been enabled");
    if (System.currentTimeMillis() > ReleaseData.RELEASE_TIME + 21600000L) {
        checkUpdates();
    }
    MinecraftVersion.disableUpdateCheck();
    // Check if NBT API is supported for the version
    if (MinecraftVersion.getVersion() == MinecraftVersion.UNKNOWN) {
        getLogger().warning("NBT API is not yet supported for your Minecraft version, item modifier, requirement, and some other functionality is disabled!");
        nbtAPIEnabled = false;
    } else {
        nbtAPIEnabled = true;
    }
}
Also used : PaperCommandManager(co.aikar.commands.PaperCommandManager) SourceRegistry(com.archyx.aureliumskills.source.SourceRegistry) LeaderboardManager(com.archyx.aureliumskills.leaderboard.LeaderboardManager) WorldManager(com.archyx.aureliumskills.util.world.WorldManager) ItemRegistry(com.archyx.aureliumskills.item.ItemRegistry) ModifierManager(com.archyx.aureliumskills.modifier.ModifierManager) LegacyFileBackup(com.archyx.aureliumskills.data.backup.LegacyFileBackup) MySqlStorageProvider(com.archyx.aureliumskills.data.storage.MySqlStorageProvider) MysqlBackup(com.archyx.aureliumskills.data.backup.MysqlBackup) SkillBossBar(com.archyx.aureliumskills.ui.SkillBossBar) RequirementManager(com.archyx.aureliumskills.requirement.RequirementManager) InventoryManager(fr.minuskube.inv.InventoryManager) Metrics(org.bstats.bukkit.Metrics) SkillRegistry(com.archyx.aureliumskills.skills.SkillRegistry) LegacyMysqlToMysqlConverter(com.archyx.aureliumskills.data.converter.LegacyMysqlToMysqlConverter) RegionManager(com.archyx.aureliumskills.region.RegionManager) ManaAbilityManager(com.archyx.aureliumskills.mana.ManaAbilityManager) AbilityManager(com.archyx.aureliumskills.ability.AbilityManager) ManaAbilityManager(com.archyx.aureliumskills.mana.ManaAbilityManager) LegacyFileToYamlConverter(com.archyx.aureliumskills.data.converter.LegacyFileToYamlConverter) PlayerManager(com.archyx.aureliumskills.data.PlayerManager) YamlStorageProvider(com.archyx.aureliumskills.data.storage.YamlStorageProvider) LootTableManager(com.archyx.aureliumskills.loot.LootTableManager) OptionL(com.archyx.aureliumskills.configuration.OptionL) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Lang(com.archyx.aureliumskills.lang.Lang) ActionBarCompatHandler(com.archyx.aureliumskills.ui.ActionBarCompatHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException) FarmingHarvestLeveler(com.archyx.aureliumskills.skills.farming.FarmingHarvestLeveler) MiningLeveler(com.archyx.aureliumskills.skills.mining.MiningLeveler) ExcavationLeveler(com.archyx.aureliumskills.skills.excavation.ExcavationLeveler) EnduranceLeveler(com.archyx.aureliumskills.skills.endurance.EnduranceLeveler) ForagingLeveler(com.archyx.aureliumskills.skills.foraging.ForagingLeveler) AlchemyLeveler(com.archyx.aureliumskills.skills.alchemy.AlchemyLeveler) HealingLeveler(com.archyx.aureliumskills.skills.healing.HealingLeveler) FishingLeveler(com.archyx.aureliumskills.skills.fishing.FishingLeveler) DefenseLeveler(com.archyx.aureliumskills.skills.defense.DefenseLeveler) EnchantingLeveler(com.archyx.aureliumskills.skills.enchanting.EnchantingLeveler) FarmingLeveler(com.archyx.aureliumskills.skills.farming.FarmingLeveler) AgilityLeveler(com.archyx.aureliumskills.skills.agility.AgilityLeveler) FarmingInteractLeveler(com.archyx.aureliumskills.skills.farming.FarmingInteractLeveler) SorceryLeveler(com.archyx.aureliumskills.skills.sorcery.SorceryLeveler) Leveler(com.archyx.aureliumskills.leveler.Leveler) FightingLeveler(com.archyx.aureliumskills.skills.fighting.FightingLeveler) ArcheryLeveler(com.archyx.aureliumskills.skills.archery.ArcheryLeveler) ForgingLeveler(com.archyx.aureliumskills.skills.forging.ForgingLeveler) YamlBackup(com.archyx.aureliumskills.data.backup.YamlBackup) SourceManager(com.archyx.aureliumskills.source.SourceManager) MenuLoader(com.archyx.aureliumskills.menu.MenuLoader) RewardManager(com.archyx.aureliumskills.rewards.RewardManager)

Example 3 with LeaderboardManager

use of com.archyx.aureliumskills.leaderboard.LeaderboardManager in project AureliumSkills by Archy-X.

the class MySqlStorageProvider method updateLeaderboards.

@Override
public void updateLeaderboards() {
    LeaderboardManager manager = plugin.getLeaderboardManager();
    manager.setSorting(true);
    // Initialize lists
    Map<Skill, List<SkillValue>> leaderboards = new HashMap<>();
    for (Skill skill : Skills.values()) {
        leaderboards.put(skill, new ArrayList<>());
    }
    List<SkillValue> powerLeaderboard = new ArrayList<>();
    List<SkillValue> averageLeaderboard = new ArrayList<>();
    // Add players already in memory
    Set<UUID> loadedFromMemory = addLoadedPlayersToLeaderboards(leaderboards, powerLeaderboard, averageLeaderboard);
    try {
        try (Statement statement = connection.createStatement()) {
            String query = "SELECT * FROM SkillData;";
            try (ResultSet result = statement.executeQuery(query)) {
                while (result.next()) {
                    try {
                        UUID id = UUID.fromString(result.getString("ID"));
                        if (!loadedFromMemory.contains(id)) {
                            int powerLevel = 0;
                            double powerXp = 0;
                            int numEnabled = 0;
                            for (Skill skill : Skills.values()) {
                                // Load from database
                                int level = result.getInt(skill.toString().toUpperCase(Locale.ROOT) + "_LEVEL");
                                if (level == 0) {
                                    level = 1;
                                }
                                double xp = result.getDouble(skill.toString().toUpperCase(Locale.ROOT) + "_XP");
                                // Add to lists
                                SkillValue skillLevel = new SkillValue(id, level, xp);
                                leaderboards.get(skill).add(skillLevel);
                                if (OptionL.isEnabled(skill)) {
                                    powerLevel += level;
                                    powerXp += xp;
                                    numEnabled++;
                                }
                            }
                            // Add power and average
                            SkillValue powerValue = new SkillValue(id, powerLevel, powerXp);
                            powerLeaderboard.add(powerValue);
                            double averageLevel = (double) powerLevel / numEnabled;
                            SkillValue averageValue = new SkillValue(id, 0, averageLevel);
                            averageLeaderboard.add(averageValue);
                        }
                    } catch (Exception e) {
                        Bukkit.getLogger().warning("[AureliumSkills] Error reading player with uuid " + result.getString("ID") + " from the database!");
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception e) {
        Bukkit.getLogger().warning("Error while updating leaderboards:");
        e.printStackTrace();
    }
    sortLeaderboards(leaderboards, powerLeaderboard, averageLeaderboard);
}
Also used : LeaderboardManager(com.archyx.aureliumskills.leaderboard.LeaderboardManager) IOException(java.io.IOException) Skill(com.archyx.aureliumskills.skills.Skill) SkillValue(com.archyx.aureliumskills.leaderboard.SkillValue)

Example 4 with LeaderboardManager

use of com.archyx.aureliumskills.leaderboard.LeaderboardManager in project AureliumSkills by Archy-X.

the class YamlStorageProvider method updateLeaderboards.

@Override
public void updateLeaderboards() {
    LeaderboardManager manager = plugin.getLeaderboardManager();
    manager.setSorting(true);
    // Initialize lists
    Map<Skill, List<SkillValue>> leaderboards = new HashMap<>();
    for (Skill skill : Skills.values()) {
        leaderboards.put(skill, new ArrayList<>());
    }
    List<SkillValue> powerLeaderboard = new ArrayList<>();
    List<SkillValue> averageLeaderboard = new ArrayList<>();
    // Add players already in memory
    Set<UUID> loadedFromMemory = addLoadedPlayersToLeaderboards(leaderboards, powerLeaderboard, averageLeaderboard);
    File playerDataFolder = new File(plugin.getDataFolder() + "/playerdata");
    // Load data from files
    if (playerDataFolder.exists() && playerDataFolder.isDirectory()) {
        File[] files = playerDataFolder.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.getName().endsWith(".yml")) {
                    UUID id = UUID.fromString(file.getName().substring(0, file.getName().lastIndexOf('.')));
                    if (!loadedFromMemory.contains(id)) {
                        FileConfiguration config = YamlConfiguration.loadConfiguration(file);
                        try {
                            int powerLevel = 0;
                            double powerXp = 0;
                            int numEnabled = 0;
                            for (Skill skill : Skills.values()) {
                                // Load from config
                                String path = "skills." + skill.toString().toLowerCase(Locale.ROOT) + ".";
                                int level = config.getInt(path + "level", 1);
                                double xp = config.getDouble(path + "xp");
                                // Add to lists
                                SkillValue skillLevel = new SkillValue(id, level, xp);
                                leaderboards.get(skill).add(skillLevel);
                                if (OptionL.isEnabled(skill)) {
                                    powerLevel += level;
                                    powerXp += xp;
                                    numEnabled++;
                                }
                            }
                            // Add power and average
                            SkillValue powerValue = new SkillValue(id, powerLevel, powerXp);
                            powerLeaderboard.add(powerValue);
                            double averageLevel = (double) powerLevel / numEnabled;
                            SkillValue averageValue = new SkillValue(id, 0, averageLevel);
                            averageLeaderboard.add(averageValue);
                        } catch (Exception e) {
                            Bukkit.getLogger().warning("[AureliumSkills] Error reading playerdata file " + file.getName() + ", see error below for details:");
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
    sortLeaderboards(leaderboards, powerLeaderboard, averageLeaderboard);
}
Also used : LeaderboardManager(com.archyx.aureliumskills.leaderboard.LeaderboardManager) IOException(java.io.IOException) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Skill(com.archyx.aureliumskills.skills.Skill) SkillValue(com.archyx.aureliumskills.leaderboard.SkillValue) File(java.io.File)

Aggregations

LeaderboardManager (com.archyx.aureliumskills.leaderboard.LeaderboardManager)4 Skill (com.archyx.aureliumskills.skills.Skill)3 SkillValue (com.archyx.aureliumskills.leaderboard.SkillValue)2 IOException (java.io.IOException)2 PaperCommandManager (co.aikar.commands.PaperCommandManager)1 AbilityManager (com.archyx.aureliumskills.ability.AbilityManager)1 OptionL (com.archyx.aureliumskills.configuration.OptionL)1 PlayerManager (com.archyx.aureliumskills.data.PlayerManager)1 LegacyFileBackup (com.archyx.aureliumskills.data.backup.LegacyFileBackup)1 MysqlBackup (com.archyx.aureliumskills.data.backup.MysqlBackup)1 YamlBackup (com.archyx.aureliumskills.data.backup.YamlBackup)1 LegacyFileToYamlConverter (com.archyx.aureliumskills.data.converter.LegacyFileToYamlConverter)1 LegacyMysqlToMysqlConverter (com.archyx.aureliumskills.data.converter.LegacyMysqlToMysqlConverter)1 MySqlStorageProvider (com.archyx.aureliumskills.data.storage.MySqlStorageProvider)1 YamlStorageProvider (com.archyx.aureliumskills.data.storage.YamlStorageProvider)1 ItemRegistry (com.archyx.aureliumskills.item.ItemRegistry)1 Lang (com.archyx.aureliumskills.lang.Lang)1 AverageSorter (com.archyx.aureliumskills.leaderboard.AverageSorter)1 LeaderboardSorter (com.archyx.aureliumskills.leaderboard.LeaderboardSorter)1 Leveler (com.archyx.aureliumskills.leveler.Leveler)1