Search in sources :

Example 56 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project BetonQuest by BetonQuest.

the class AureliumSkillsExperienceEvent method execute.

@Override
protected Void execute(final String playerID) throws QuestRuntimeException {
    final Player player = PlayerConverter.getPlayer(playerID);
    final PlayerData playerData = aureliumSkills.getPlayerManager().getPlayerData(player);
    if (playerData == null) {
        return null;
    }
    final int amount = amountVar.getInt(playerID);
    if (isLevel) {
        final int currentLevel = playerData.getSkillLevel(skill);
        for (int i = 1; i <= amount; i++) {
            final double requiredXP = aureliumSkills.getLeveler().getXpRequirements().getXpRequired(skill, currentLevel + i);
            AureliumAPI.addXpRaw(player, skill, requiredXP);
        }
    } else {
        AureliumAPI.addXpRaw(player, skill, amount);
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 57 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class AureliumSkills method registerCommands.

private void registerCommands() {
    commandManager.enableUnstableAPI("help");
    commandManager.usePerIssuerLocale(true, false);
    commandManager.getCommandContexts().registerContext(Stat.class, c -> {
        String input = c.popFirstArg();
        Stat stat = statRegistry.getStat(input);
        if (stat != null) {
            return stat;
        } else {
            throw new InvalidCommandArgument("Stat " + input + " not found!");
        }
    });
    commandManager.getCommandContexts().registerContext(Skill.class, c -> {
        String input = c.popFirstArg();
        Skill skill = skillRegistry.getSkill(input);
        if (skill != null) {
            return skill;
        } else {
            throw new InvalidCommandArgument("Skill " + input + " not found!");
        }
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("skills", c -> {
        List<String> values = new ArrayList<>();
        for (Skill skill : skillRegistry.getSkills()) {
            if (OptionL.isEnabled(skill)) {
                values.add(skill.toString().toLowerCase(Locale.ENGLISH));
            }
        }
        return values;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("skills_global", c -> {
        List<String> values = new ArrayList<>();
        values.add("global");
        for (Skill skill : skillRegistry.getSkills()) {
            if (OptionL.isEnabled(skill)) {
                values.add(skill.toString().toLowerCase(Locale.ENGLISH));
            }
        }
        return values;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("skillTop", c -> {
        List<String> values = new ArrayList<>();
        for (Skill skill : skillRegistry.getSkills()) {
            if (OptionL.isEnabled(skill)) {
                values.add(skill.toString().toLowerCase(Locale.ENGLISH));
            }
        }
        values.add("average");
        return values;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("stats", c -> {
        List<String> values = new ArrayList<>();
        for (Stat stat : statRegistry.getStats()) {
            values.add(stat.toString().toLowerCase(Locale.ENGLISH));
        }
        return values;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("lang", c -> Lang.getDefinedLanguagesSet());
    commandManager.getCommandCompletions().registerAsyncCompletion("modifiers", c -> {
        Player player = c.getPlayer();
        PlayerData playerData = getPlayerManager().getPlayerData(player);
        if (playerData != null) {
            return playerData.getStatModifiers().keySet();
        }
        return null;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("item_keys", c -> itemRegistry.getKeys());
    commandManager.registerCommand(new SkillsCommand(this));
    commandManager.registerCommand(new StatsCommand(this));
    commandManager.registerCommand(new ManaCommand(this));
    if (OptionL.getBoolean(Option.ENABLE_SKILL_COMMANDS)) {
        if (OptionL.isEnabled(Skills.FARMING)) {
            commandManager.registerCommand(new SkillCommands.FarmingCommand(this));
        }
        if (OptionL.isEnabled(Skills.FORAGING)) {
            commandManager.registerCommand(new SkillCommands.ForagingCommand(this));
        }
        if (OptionL.isEnabled(Skills.MINING)) {
            commandManager.registerCommand(new SkillCommands.MiningCommand(this));
        }
        if (OptionL.isEnabled(Skills.FISHING)) {
            commandManager.registerCommand(new SkillCommands.FishingCommand(this));
        }
        if (OptionL.isEnabled(Skills.EXCAVATION)) {
            commandManager.registerCommand(new SkillCommands.ExcavationCommand(this));
        }
        if (OptionL.isEnabled(Skills.ARCHERY)) {
            commandManager.registerCommand(new SkillCommands.ArcheryCommand(this));
        }
        if (OptionL.isEnabled(Skills.DEFENSE)) {
            commandManager.registerCommand(new SkillCommands.DefenseCommand(this));
        }
        if (OptionL.isEnabled(Skills.FIGHTING)) {
            commandManager.registerCommand(new SkillCommands.FightingCommand(this));
        }
        if (OptionL.isEnabled(Skills.ENDURANCE)) {
            commandManager.registerCommand(new SkillCommands.EnduranceCommand(this));
        }
        if (OptionL.isEnabled(Skills.AGILITY)) {
            commandManager.registerCommand(new SkillCommands.AgilityCommand(this));
        }
        if (OptionL.isEnabled(Skills.ALCHEMY)) {
            commandManager.registerCommand(new SkillCommands.AlchemyCommand(this));
        }
        if (OptionL.isEnabled(Skills.ENCHANTING)) {
            commandManager.registerCommand(new SkillCommands.EnchantingCommand(this));
        }
        if (OptionL.isEnabled(Skills.SORCERY)) {
            commandManager.registerCommand(new SkillCommands.SorceryCommand(this));
        }
        if (OptionL.isEnabled(Skills.HEALING)) {
            commandManager.registerCommand(new SkillCommands.HealingCommand(this));
        }
        if (OptionL.isEnabled(Skills.FORGING)) {
            commandManager.registerCommand(new SkillCommands.ForgingCommand(this));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SkillCommands(com.archyx.aureliumskills.commands.SkillCommands) ManaCommand(com.archyx.aureliumskills.commands.ManaCommand) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) StatsCommand(com.archyx.aureliumskills.commands.StatsCommand) SkillsCommand(com.archyx.aureliumskills.commands.SkillsCommand) Player(org.bukkit.entity.Player) Skill(com.archyx.aureliumskills.skills.Skill) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 58 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class AureliumSkills method onDisable.

public void onDisable() {
    for (PlayerData playerData : playerManager.getPlayerDataMap().values()) {
        storageProvider.save(playerData.getPlayer(), false);
    }
    playerManager.getPlayerDataMap().clear();
    File file = new File(this.getDataFolder(), "config.yml");
    if (file.exists()) {
        // Reloads config
        reloadConfig();
        // Save config
        saveConfig();
    }
    regionManager.saveAllRegions(false, true);
    regionManager.clearRegionMap();
    backupAutomatically();
    itemRegistry.saveToFile();
    // Remove fleeting
    AgilityAbilities agilityAbilities = new AgilityAbilities(this);
    for (Player player : Bukkit.getOnlinePlayers()) {
        agilityAbilities.removeFleetingQuit(player);
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerData(com.archyx.aureliumskills.data.PlayerData) File(java.io.File) AgilityAbilities(com.archyx.aureliumskills.skills.agility.AgilityAbilities)

Example 59 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class YamlStorageProvider method save.

@Override
public void save(Player player, boolean removeFromMemory) {
    PlayerData playerData = playerManager.getPlayerData(player);
    if (playerData == null)
        return;
    if (playerData.shouldNotSave())
        return;
    // Save lock
    if (playerData.isSaving())
        return;
    playerData.setSaving(true);
    // Load file
    File file = new File(plugin.getDataFolder() + "/playerdata/" + player.getUniqueId() + ".yml");
    FileConfiguration config = YamlConfiguration.loadConfiguration(file);
    try {
        config.set("uuid", player.getUniqueId().toString());
        // Save skill data
        for (Skill skill : Skills.values()) {
            String path = "skills." + skill.toString().toLowerCase(Locale.ROOT) + ".";
            config.set(path + "level", playerData.getSkillLevel(skill));
            config.set(path + "xp", playerData.getSkillXp(skill));
        }
        // Clear existing modifiers
        config.set("stat_modifiers", null);
        // Save stat modifiers
        int count = 0;
        for (StatModifier modifier : playerData.getStatModifiers().values()) {
            String path = "stat_modifiers." + count + ".";
            config.set(path + "name", modifier.getName());
            config.set(path + "stat", modifier.getStat().toString().toLowerCase(Locale.ROOT));
            config.set(path + "value", modifier.getValue());
            count++;
        }
        // Save mana
        config.set("mana", playerData.getMana());
        // Save locale
        Locale locale = playerData.getLocale();
        if (locale != null) {
            config.set("locale", locale.toString());
        }
        // Save ability data
        for (AbilityData abilityData : playerData.getAbilityDataMap().values()) {
            String path = "ability_data." + abilityData.getAbility().toString().toLowerCase(Locale.ROOT) + ".";
            for (Map.Entry<String, Object> entry : abilityData.getDataMap().entrySet()) {
                config.set(path + entry.getKey(), entry.getValue());
            }
        }
        // Save unclaimed items
        List<KeyIntPair> unclaimedItems = playerData.getUnclaimedItems();
        config.set("unclaimed_items", null);
        if (unclaimedItems != null && unclaimedItems.size() > 0) {
            List<String> stringList = new ArrayList<>();
            for (KeyIntPair unclaimedItem : unclaimedItems) {
                stringList.add(unclaimedItem.getKey() + " " + unclaimedItem.getValue());
            }
            config.set("unclaimed_items", stringList);
        }
        config.save(file);
        if (removeFromMemory) {
            // Remove from memory
            playerManager.removePlayerData(player.getUniqueId());
        }
    } catch (Exception e) {
        Bukkit.getLogger().warning("There was an error saving player data for player " + player.getName() + " with UUID " + player.getUniqueId() + ", see below for details.");
        e.printStackTrace();
    }
    // Unlock
    playerData.setSaving(false);
}
Also used : IOException(java.io.IOException) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) StatModifier(com.archyx.aureliumskills.modifier.StatModifier) Skill(com.archyx.aureliumskills.skills.Skill) KeyIntPair(com.archyx.aureliumskills.util.misc.KeyIntPair) PlayerData(com.archyx.aureliumskills.data.PlayerData) File(java.io.File) AbilityData(com.archyx.aureliumskills.data.AbilityData)

Example 60 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class ManaCommand method onMana.

@Default
@CommandPermission("aureliumskills.mana")
@Description("Display your or another player's current and max mana")
public void onMana(CommandSender sender, @Flags("other") @CommandPermission("aureliumskills.mana.other") @Optional Player player) {
    if (sender instanceof Player && player == null) {
        Player target = (Player) sender;
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(target);
        if (playerData == null)
            return;
        Locale locale = playerData.getLocale();
        sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.MANA_DISPLAY, locale), "{current}", NumberUtil.format1(playerData.getMana()), "{max}", NumberUtil.format1(playerData.getMaxMana())));
    } else if (player != null) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData == null)
            return;
        Locale locale = playerData.getLocale();
        sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.MANA_DISPLAY_OTHER, locale), "{player}", player.getName(), "{current}", NumberUtil.format1(playerData.getMana()), "{max}", NumberUtil.format1(playerData.getMaxMana())));
    } else {
        sender.sendMessage(AureliumSkills.getPrefix(Lang.getDefaultLanguage()) + Lang.getMessage(CommandMessage.MANA_CONSOLE_SPECIFY_PLAYER, Lang.getDefaultLanguage()));
    }
}
Also used : Locale(java.util.Locale) Player(org.bukkit.entity.Player) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Aggregations

PlayerData (com.archyx.aureliumskills.data.PlayerData)111 Player (org.bukkit.entity.Player)54 EventHandler (org.bukkit.event.EventHandler)43 Locale (java.util.Locale)27 ItemStack (org.bukkit.inventory.ItemStack)25 Skill (com.archyx.aureliumskills.skills.Skill)15 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)10 Stat (com.archyx.aureliumskills.stats.Stat)9 AttributeInstance (org.bukkit.attribute.AttributeInstance)8 PlayerLootDropEvent (com.archyx.aureliumskills.api.event.PlayerLootDropEvent)7 StatModifier (com.archyx.aureliumskills.modifier.StatModifier)7 Material (org.bukkit.Material)7 LivingEntity (org.bukkit.entity.LivingEntity)7 KeyIntPair (com.archyx.aureliumskills.util.misc.KeyIntPair)6 AureliumSkills (com.archyx.aureliumskills.AureliumSkills)5 OptionL (com.archyx.aureliumskills.configuration.OptionL)5 AbilityData (com.archyx.aureliumskills.data.AbilityData)5 File (java.io.File)5 IOException (java.io.IOException)5 PlayerDataLoadEvent (com.archyx.aureliumskills.data.PlayerDataLoadEvent)4