Search in sources :

Example 31 with PlayerData

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

the class SkillsMenu method init.

public void init(Player player, InventoryContents contents) {
    // Fill item
    if (options.isFillEnabled()) {
        contents.fill(ClickableItem.empty(options.getFillItem()));
    }
    // Close item
    CloseItem closeItem = (CloseItem) options.getItem(ItemType.CLOSE);
    contents.set(closeItem.getPos(), ClickableItem.of(closeItem.getItem(player, locale), e -> player.closeInventory()));
    // Your skills item
    YourSkillsItem yourSkillsItem = (YourSkillsItem) options.getItem(ItemType.YOUR_SKILLS);
    contents.set(yourSkillsItem.getPos(), ClickableItem.empty(yourSkillsItem.getItem(player, locale)));
    // Skill items
    SkillTemplate skillTemplate = (SkillTemplate) options.getTemplate(TemplateType.SKILL);
    if (OptionL.isEnabled(Skills.FARMING)) {
        contents.set(skillTemplate.getPosition(Skills.FARMING), ClickableItem.of(skillTemplate.getItem(Skills.FARMING, playerData, player, locale), e -> open(player, playerData, Skills.FARMING)));
    }
    if (OptionL.isEnabled(Skills.FORAGING)) {
        contents.set(skillTemplate.getPosition(Skills.FORAGING), ClickableItem.of(skillTemplate.getItem(Skills.FORAGING, playerData, player, locale), e -> open(player, playerData, Skills.FORAGING)));
    }
    if (OptionL.isEnabled(Skills.MINING)) {
        contents.set(skillTemplate.getPosition(Skills.MINING), ClickableItem.of(skillTemplate.getItem(Skills.MINING, playerData, player, locale), e -> open(player, playerData, Skills.MINING)));
    }
    if (OptionL.isEnabled(Skills.FISHING)) {
        contents.set(skillTemplate.getPosition(Skills.FISHING), ClickableItem.of(skillTemplate.getItem(Skills.FISHING, playerData, player, locale), e -> open(player, playerData, Skills.FISHING)));
    }
    if (OptionL.isEnabled(Skills.EXCAVATION)) {
        contents.set(skillTemplate.getPosition(Skills.EXCAVATION), ClickableItem.of(skillTemplate.getItem(Skills.EXCAVATION, playerData, player, locale), e -> open(player, playerData, Skills.EXCAVATION)));
    }
    // Combat Skills
    if (OptionL.isEnabled(Skills.ARCHERY)) {
        contents.set(skillTemplate.getPosition(Skills.ARCHERY), ClickableItem.of(skillTemplate.getItem(Skills.ARCHERY, playerData, player, locale), e -> open(player, playerData, Skills.ARCHERY)));
    }
    if (OptionL.isEnabled(Skills.DEFENSE)) {
        contents.set(skillTemplate.getPosition(Skills.DEFENSE), ClickableItem.of(skillTemplate.getItem(Skills.DEFENSE, playerData, player, locale), e -> open(player, playerData, Skills.DEFENSE)));
    }
    if (OptionL.isEnabled(Skills.FIGHTING)) {
        contents.set(skillTemplate.getPosition(Skills.FIGHTING), ClickableItem.of(skillTemplate.getItem(Skills.FIGHTING, playerData, player, locale), e -> open(player, playerData, Skills.FIGHTING)));
    }
    if (OptionL.isEnabled(Skills.ENDURANCE)) {
        contents.set(skillTemplate.getPosition(Skills.ENDURANCE), ClickableItem.of(skillTemplate.getItem(Skills.ENDURANCE, playerData, player, locale), e -> open(player, playerData, Skills.ENDURANCE)));
    }
    if (OptionL.isEnabled(Skills.AGILITY)) {
        contents.set(skillTemplate.getPosition(Skills.AGILITY), ClickableItem.of(skillTemplate.getItem(Skills.AGILITY, playerData, player, locale), e -> open(player, playerData, Skills.AGILITY)));
    }
    // Magic Skills
    if (OptionL.isEnabled(Skills.ALCHEMY)) {
        contents.set(skillTemplate.getPosition(Skills.ALCHEMY), ClickableItem.of(skillTemplate.getItem(Skills.ALCHEMY, playerData, player, locale), e -> open(player, playerData, Skills.ALCHEMY)));
    }
    if (OptionL.isEnabled(Skills.ENCHANTING)) {
        contents.set(skillTemplate.getPosition(Skills.ENCHANTING), ClickableItem.of(skillTemplate.getItem(Skills.ENCHANTING, playerData, player, locale), e -> open(player, playerData, Skills.ENCHANTING)));
    }
    if (OptionL.isEnabled(Skills.SORCERY)) {
        contents.set(skillTemplate.getPosition(Skills.SORCERY), ClickableItem.of(skillTemplate.getItem(Skills.SORCERY, playerData, player, locale), e -> open(player, playerData, Skills.SORCERY)));
    }
    if (OptionL.isEnabled(Skills.HEALING)) {
        contents.set(skillTemplate.getPosition(Skills.HEALING), ClickableItem.of(skillTemplate.getItem(Skills.HEALING, playerData, player, locale), e -> open(player, playerData, Skills.HEALING)));
    }
    if (OptionL.isEnabled(Skills.FORGING)) {
        contents.set(skillTemplate.getPosition(Skills.FORGING), ClickableItem.of(skillTemplate.getItem(Skills.FORGING, playerData, player, locale), e -> open(player, playerData, Skills.FORGING)));
    }
}
Also used : CloseItem(com.archyx.aureliumskills.menu.items.CloseItem) TemplateType(com.archyx.aureliumskills.menu.templates.TemplateType) MenuMessage(com.archyx.aureliumskills.lang.MenuMessage) SmartInventory(fr.minuskube.inv.SmartInventory) OptionL(com.archyx.aureliumskills.configuration.OptionL) Player(org.bukkit.entity.Player) Nullable(org.jetbrains.annotations.Nullable) SkillTemplate(com.archyx.aureliumskills.menu.templates.SkillTemplate) AureliumSkills(com.archyx.aureliumskills.AureliumSkills) Lang(com.archyx.aureliumskills.lang.Lang) CloseItem(com.archyx.aureliumskills.menu.items.CloseItem) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) Locale(java.util.Locale) PlayerData(com.archyx.aureliumskills.data.PlayerData) Skill(com.archyx.aureliumskills.skills.Skill) ItemType(com.archyx.aureliumskills.menu.items.ItemType) YourSkillsItem(com.archyx.aureliumskills.menu.items.YourSkillsItem) Skills(com.archyx.aureliumskills.skills.Skills) ClickableItem(fr.minuskube.inv.ClickableItem) SkillTemplate(com.archyx.aureliumskills.menu.templates.SkillTemplate) YourSkillsItem(com.archyx.aureliumskills.menu.items.YourSkillsItem)

Example 32 with PlayerData

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

the class StatReward method giveReward.

@Override
public void giveReward(Player player, Skill skill, int level) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    playerData.addStatLevel(stat, value);
    new StatLeveler(plugin).reloadStat(player, stat);
}
Also used : StatLeveler(com.archyx.aureliumskills.stats.StatLeveler) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 33 with PlayerData

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

the class ActionBar method sendXpActionBar.

public void sendXpActionBar(Player player, Skill skill, double xpAmount) {
    if (OptionL.getBoolean(Option.ACTION_BAR_ENABLED)) {
        // If action bar enabled
        if (!actionBarDisabled.contains(player.getUniqueId())) {
            // If the player's action bar is enabled
            // Get player skill data
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                Locale locale = playerData.getLocale();
                // Check enabled/disabled for max
                boolean notMaxed = plugin.getLeveler().getXpRequirements().getListSize(skill) > playerData.getSkillLevel(skill) - 1 && playerData.getSkillLevel(skill) < OptionL.getMaxLevel(skill);
                if (notMaxed && !OptionL.getBoolean(Option.ACTION_BAR_XP)) {
                    return;
                }
                if (!notMaxed && !OptionL.getBoolean(Option.ACTION_BAR_MAXED)) {
                    return;
                }
                if (isPaused.contains(player))
                    return;
                // Set timer and is gaining xp
                isGainingXp.add(player);
                timer.put(player, 20);
                // Put current action if not present
                if (!currentAction.containsKey(player)) {
                    currentAction.put(player, 0);
                }
                // Add to current action
                currentAction.put(player, currentAction.get(player) + 1);
                int thisAction = this.currentAction.get(player);
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        // If is gaining xp
                        if (isGainingXp.contains(player)) {
                            // If latest action
                            Integer actionBarCurrentAction = currentAction.get(player);
                            if (actionBarCurrentAction != null) {
                                if (thisAction == actionBarCurrentAction) {
                                    boolean notMaxed = plugin.getLeveler().getXpRequirements().getListSize(skill) > playerData.getSkillLevel(skill) - 1 && playerData.getSkillLevel(skill) < OptionL.getMaxLevel(skill);
                                    // Not maxed
                                    if (notMaxed) {
                                        if (OptionL.getBoolean(Option.ACTION_BAR_XP)) {
                                            // Xp gained
                                            if (xpAmount >= 0) {
                                                if (!OptionL.getBoolean(Option.ACTION_BAR_ROUND_XP)) {
                                                    sendActionBar(player, TextUtil.replace(TextUtil.replace(Lang.getMessage(ActionBarMessage.XP, locale), "{hp}", getHp(player), "{max_hp}", getMaxHp(player), "{xp_gained}", NumberUtil.format1(xpAmount), "{skill}", skill.getDisplayName(locale), "{current_xp}", NumberUtil.format1(playerData.getSkillXp(skill))), "{level_xp}", BigNumber.withSuffix(plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1)), "{mana}", getMana(playerData), "{max_mana}", getMaxMana(playerData)));
                                                } else {
                                                    sendActionBar(player, TextUtil.replace(TextUtil.replace(Lang.getMessage(ActionBarMessage.XP, locale), "{hp}", getHp(player), "{max_hp}", getMaxHp(player), "{xp_gained}", NumberUtil.format1(xpAmount), "{skill}", skill.getDisplayName(locale), "{current_xp}", String.valueOf((int) playerData.getSkillXp(skill))), "{level_xp}", BigNumber.withSuffix(plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1)), "{mana}", getMana(playerData), "{max_mana}", getMaxMana(playerData)));
                                                }
                                            } else // Xp removed
                                            {
                                                if (!OptionL.getBoolean(Option.ACTION_BAR_ROUND_XP)) {
                                                    sendActionBar(player, TextUtil.replace(TextUtil.replace(Lang.getMessage(ActionBarMessage.XP_REMOVED, locale), "{hp}", getHp(player), "{max_hp}", getMaxHp(player), "{xp_removed}", NumberUtil.format1(xpAmount), "{skill}", skill.getDisplayName(locale), "{current_xp}", NumberUtil.format1(playerData.getSkillXp(skill))), "{level_xp}", BigNumber.withSuffix(plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1)), "{mana}", getMana(playerData), "{max_mana}", getMaxMana(playerData)));
                                                } else {
                                                    sendActionBar(player, TextUtil.replace(TextUtil.replace(Lang.getMessage(ActionBarMessage.XP, locale), "{hp}", getHp(player), "{max_hp}", getMaxHp(player), "{xp_gained}", NumberUtil.format1(xpAmount), "{skill}", skill.getDisplayName(locale), "{current_xp}", String.valueOf((int) playerData.getSkillXp(skill))), "{level_xp}", BigNumber.withSuffix(plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1)), "{mana}", getMana(playerData), "{max_mana}", getMaxMana(playerData)));
                                                }
                                            }
                                        }
                                    } else // Maxed
                                    {
                                        if (OptionL.getBoolean(Option.ACTION_BAR_MAXED)) {
                                            // Xp gained
                                            if (xpAmount >= 0) {
                                                sendActionBar(player, TextUtil.replace(Lang.getMessage(ActionBarMessage.MAXED, locale), "{hp}", getHp(player), "{max_hp}", getMaxHp(player), "{xp_gained}", NumberUtil.format1(xpAmount), "{skill}", skill.getDisplayName(locale), "{mana}", getMana(playerData), "{max_mana}", getMaxMana(playerData)));
                                            } else // Xp removed
                                            {
                                                sendActionBar(player, TextUtil.replace(Lang.getMessage(ActionBarMessage.MAXED_REMOVED, locale), "{hp}", getHp(player), "{max_hp}", getMaxHp(player), "{xp_removed}", NumberUtil.format1(xpAmount), "{skill}", skill.getDisplayName(locale), "{mana}", getMana(playerData), "{max_mana}", getMaxMana(playerData)));
                                            }
                                        }
                                    }
                                } else {
                                    cancel();
                                }
                            } else {
                                cancel();
                            }
                        } else {
                            cancel();
                        }
                    }
                }.runTaskTimer(plugin, 0L, OptionL.getInt(Option.ACTION_BAR_UPDATE_PERIOD));
                // Schedule stop gaining xp
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        Integer timerNum = timer.get(player);
                        if (timerNum != null) {
                            if (timerNum.equals(0)) {
                                isGainingXp.remove(player);
                            }
                        }
                    }
                }.runTaskLater(plugin, 41L);
            }
        }
    }
}
Also used : Locale(java.util.Locale) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 34 with PlayerData

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

the class Health method setHealth.

private void setHealth(Player player) {
    // Calculates the amount of health to add
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    double modifier = (playerData.getStatLevel(Stats.HEALTH)) * OptionL.getDouble(Option.HEALTH_MODIFIER);
    AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
    if (attribute == null)
        return;
    double originalMaxHealth = attribute.getValue();
    boolean hasChange = true;
    // Removes existing modifiers of the same name and check for change
    for (AttributeModifier am : attribute.getModifiers()) {
        if (am.getName().equals("skillsHealth")) {
            // Check for any changes, if not, return
            if (Math.abs(originalMaxHealth - (originalMaxHealth - am.getAmount() + modifier)) <= threshold) {
                hasChange = false;
            }
            // Removes if has change
            if (hasChange) {
                attribute.removeModifier(am);
            }
        }
    }
    // Disable health if in disable world
    if (plugin.getWorldManager().isInDisabledWorld(player.getLocation())) {
        player.setHealthScaled(false);
        for (AttributeModifier am : attribute.getModifiers()) {
            if (am.getName().equals("skillsHealth")) {
                attribute.removeModifier(am);
            }
        }
        return;
    }
    // Force base health if enabled
    if (OptionL.getBoolean(Option.HEALTH_FORCE_BASE_HEALTH)) {
        attribute.setBaseValue(20.0);
    }
    // Return if no change
    if (hasChange) {
        // Applies modifier
        attribute.addModifier(new AttributeModifier("skillsHealth", modifier, Operation.ADD_NUMBER));
        // Sets health to max if over max
        if (player.getHealth() > attribute.getValue()) {
            player.setHealth(attribute.getValue());
        }
        if (OptionL.getBoolean(Option.HEALTH_KEEP_FULL_ON_INCREASE) && attribute.getValue() > originalMaxHealth) {
            // Heals player to full health if had full health before modifier
            if (player.getHealth() >= originalMaxHealth) {
                player.setHealth(attribute.getValue());
            }
        }
    }
    applyScaling(player);
}
Also used : AttributeInstance(org.bukkit.attribute.AttributeInstance) AttributeModifier(org.bukkit.attribute.AttributeModifier) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 35 with PlayerData

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

the class Regeneration method startRegen.

public void startRegen() {
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
        if (OptionL.getBoolean(Option.REGENERATION_CUSTOM_REGEN_MECHANICS)) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData != null) {
                    // Check for disabled world
                    if (!plugin.getWorldManager().isInDisabledWorld(player.getLocation())) {
                        if (!player.isDead()) {
                            AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
                            if (attribute != null) {
                                if (player.getHealth() < attribute.getValue()) {
                                    if (player.getFoodLevel() >= 14 && player.getFoodLevel() < 20) {
                                        double amountGained = Math.min(OptionL.getDouble(Option.REGENERATION_BASE_REGEN) + playerData.getStatLevel(Stats.REGENERATION) * OptionL.getDouble(Option.REGENERATION_HUNGER_ALMOST_FULL_MODIFIER), attribute.getValue() - player.getHealth());
                                        CustomRegenEvent event = new CustomRegenEvent(player, amountGained, RegenReason.HUNGER_FULL);
                                        Bukkit.getPluginManager().callEvent(event);
                                        if (!event.isCancelled()) {
                                            player.setHealth(player.getHealth() + amountGained);
                                            if (player.getFoodLevel() - 1 >= 0) {
                                                player.setFoodLevel(player.getFoodLevel() - 1);
                                            }
                                        }
                                    } else if (player.getFoodLevel() == 20 && player.getSaturation() == 0) {
                                        double amountGained = Math.min(OptionL.getDouble(Option.REGENERATION_BASE_REGEN) + playerData.getStatLevel(Stats.REGENERATION) * OptionL.getDouble(Option.REGENERATION_HUNGER_FULL_MODIFIER), attribute.getValue() - player.getHealth());
                                        CustomRegenEvent event = new CustomRegenEvent(player, amountGained, RegenReason.HUNGER_ALMOST_FULL);
                                        Bukkit.getPluginManager().callEvent(event);
                                        if (!event.isCancelled()) {
                                            player.setHealth(player.getHealth() + amountGained);
                                            if (player.getFoodLevel() - 1 >= 0) {
                                                player.setFoodLevel(player.getFoodLevel() - 1);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }, 0L, OptionL.getInt(Option.REGENERATION_HUNGER_DELAY));
}
Also used : Player(org.bukkit.entity.Player) AttributeInstance(org.bukkit.attribute.AttributeInstance) CustomRegenEvent(com.archyx.aureliumskills.api.event.CustomRegenEvent) 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