Search in sources :

Example 66 with PlayerData

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

the class SkillsCommand method onItemGive.

@Subcommand("item give")
@CommandPermission("aureliumskills.item.give")
@CommandCompletion("@players @item_keys")
public void onItemGive(CommandSender sender, @Flags("other") Player player, String key, @Default("-1") int amount) {
    ItemStack item = plugin.getItemRegistry().getItem(key);
    Locale locale = plugin.getLang().getLocale(sender);
    if (item != null) {
        if (amount != -1) {
            item.setAmount(amount);
        }
        ItemStack leftoverItem = ItemUtils.addItemToInventory(player, item);
        sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.ITEM_GIVE_SENDER, locale), "{amount}", String.valueOf(item.getAmount()), "{key}", key, "{player}", player.getName()));
        if (!sender.equals(player)) {
            player.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.ITEM_GIVE_RECEIVER, locale), "{amount}", String.valueOf(item.getAmount()), "{key}", key));
        }
        // Add to unclaimed items if leftover
        if (leftoverItem != null) {
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                playerData.getUnclaimedItems().add(new KeyIntPair(key, leftoverItem.getAmount()));
                player.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(LevelerMessage.UNCLAIMED_ITEM, locale));
            }
        }
    } else {
        sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.ITEM_UNREGISTER_NOT_REGISTERED, locale), "{key}", key));
    }
}
Also used : Locale(java.util.Locale) ItemStack(org.bukkit.inventory.ItemStack) KeyIntPair(com.archyx.aureliumskills.util.misc.KeyIntPair) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 67 with PlayerData

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

the class AureliumAPI method addXpRaw.

/**
 * Adds Skill XP to a player for a certain skill, without multipliers
 */
public static void addXpRaw(Player player, Skill skill, double amount) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData != null) {
        playerData.addSkillXp(skill, amount);
        plugin.getLeveler().checkLevelUp(player, skill);
    }
}
Also used : PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 68 with PlayerData

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

the class ManaCommand method onManaAdd.

@Subcommand("add")
@CommandPermission("aureliumskills.mana.add")
@CommandCompletion("@players @nothing false|true")
@Description("Adds mana to a player")
public void onManaAdd(CommandSender sender, @Flags("other") Player player, double amount, @Default("true") boolean allowOverMax, @Default("false") boolean silent) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    Locale locale = playerData.getLocale();
    if (amount >= 0) {
        if (allowOverMax && OptionL.getBoolean(Option.WISDOM_ALLOW_OVER_MAX_MANA)) {
            playerData.setMana(playerData.getMana() + amount);
            if (!silent) {
                sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.MANA_ADD, locale), "{amount}", NumberUtil.format2(amount), "{player}", player.getName()));
            }
        } else {
            if (playerData.getMana() + amount <= playerData.getMaxMana()) {
                playerData.setMana(playerData.getMana() + amount);
                if (!silent) {
                    sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.MANA_ADD, locale), "{amount}", NumberUtil.format2(amount), "{player}", player.getName()));
                }
            } else {
                double added = playerData.getMaxMana() - playerData.getMana();
                if (added >= 0) {
                    playerData.setMana(playerData.getMaxMana());
                    if (!silent) {
                        sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.MANA_ADD, locale), "{amount}", NumberUtil.format2(added), "{player}", player.getName()));
                    }
                } else {
                    if (!silent) {
                        sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.MANA_ADD, locale), "{amount}", String.valueOf(0), "{player}", player.getName()));
                    }
                }
            }
        }
    } else {
        if (!silent) {
            sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.MANA_AT_LEAST_ZERO, locale));
        }
    }
}
Also used : Locale(java.util.Locale) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 69 with PlayerData

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

the class PlaceholderSupport method onPlaceholderRequest.

@Override
public String onPlaceholderRequest(Player player, String identifier) {
    if (player == null) {
        return "";
    }
    // Gets total combined skill level
    if (identifier.equals("power")) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData != null) {
            return String.valueOf(playerData.getPowerLevel());
        }
    }
    // Gets HP with scaling as an integer
    if (identifier.equals("hp")) {
        return String.valueOf(Math.round(player.getHealth() * OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING)));
    }
    // Gets HP with scaling with 1 decimal
    if (identifier.equals("hp_1")) {
        return NumberUtil.format1(player.getHealth() * OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING));
    }
    // Gets max hp
    if (identifier.equals("hp_max")) {
        AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
        if (attribute != null) {
            return String.valueOf(Math.round(attribute.getValue() * OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING)));
        } else {
            return "";
        }
    }
    // Gets HP with scaling with 2 decimal
    if (identifier.equals("hp_2")) {
        return NumberUtil.format2(player.getHealth() * OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING));
    }
    // Gets HP Percent as an integer
    if (identifier.equals("hp_percent")) {
        AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
        if (attribute != null) {
            return String.valueOf(Math.round(player.getHealth() / attribute.getValue()));
        } else {
            return "";
        }
    }
    // Gets mana
    if (identifier.equals("mana")) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData != null) {
            return String.valueOf(playerData.getMana());
        }
    }
    // Gets mana rounded to an integer
    if (identifier.equals("mana_int")) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData != null) {
            return String.valueOf(Math.round(playerData.getMana()));
        }
    }
    // Gets max mana
    if (identifier.equals("mana_max")) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData != null) {
            return String.valueOf(playerData.getMaxMana());
        }
    }
    // Gets max mana rounded to an integer
    if (identifier.equals("mana_max_int")) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData != null) {
            return String.valueOf(Math.round(playerData.getMaxMana()));
        }
    }
    // Gets stat values
    for (Stat stat : plugin.getStatRegistry().getStats()) {
        if (identifier.equals(stat.name().toLowerCase(Locale.ENGLISH))) {
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                return String.valueOf(playerData.getStatLevel(stat));
            }
        } else if (identifier.equals(stat.name().toLowerCase(Locale.ROOT) + "_int")) {
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                return String.valueOf(Math.round(playerData.getStatLevel(stat)));
            }
        }
    }
    // Gets skill levels
    for (Skill skill : plugin.getSkillRegistry().getSkills()) {
        if (identifier.equals(skill.name().toLowerCase(Locale.ENGLISH))) {
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                return String.valueOf(playerData.getSkillLevel(skill));
            }
        } else if (identifier.equals(skill.name().toLowerCase(Locale.ENGLISH) + "_roman")) {
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                return RomanNumber.toRoman(playerData.getSkillLevel(skill));
            }
        }
    }
    if (identifier.startsWith("lb_")) {
        String leaderboardType = TextUtil.replace(identifier, "lb_", "");
        if (leaderboardType.startsWith("power_")) {
            int place = NumberUtils.toInt(TextUtil.replace(leaderboardType, "power_", ""));
            if (place > 0) {
                List<SkillValue> list = plugin.getLeaderboardManager().getPowerLeaderboard(place, 1);
                if (list.size() > 0) {
                    SkillValue skillValue = list.get(0);
                    String name = Bukkit.getOfflinePlayer(skillValue.getId()).getName();
                    return (name != null ? name : "?") + " - " + skillValue.getLevel();
                } else
                    return "";
            } else {
                if (identifier.endsWith("name")) {
                    int namePlace = NumberUtils.toInt(TextUtil.replace(leaderboardType, "power_", "", "_name", ""));
                    if (namePlace > 0) {
                        List<SkillValue> list = plugin.getLeaderboardManager().getPowerLeaderboard(namePlace, 1);
                        if (list.size() > 0) {
                            SkillValue skillValue = list.get(0);
                            String name = Bukkit.getOfflinePlayer(skillValue.getId()).getName();
                            return name != null ? name : "?";
                        } else
                            return "";
                    }
                } else if (identifier.endsWith("value")) {
                    int valuePlace = NumberUtils.toInt(TextUtil.replace(leaderboardType, "power_", "", "_value", ""));
                    if (valuePlace > 0) {
                        List<SkillValue> list = plugin.getLeaderboardManager().getPowerLeaderboard(valuePlace, 1);
                        if (list.size() > 0) {
                            SkillValue playerSkill = list.get(0);
                            return String.valueOf(playerSkill.getLevel());
                        } else
                            return "";
                    }
                }
            }
        } else {
            for (Skill skill : plugin.getSkillRegistry().getSkills()) {
                if (leaderboardType.startsWith(skill.name().toLowerCase(Locale.ENGLISH) + "_")) {
                    int place = NumberUtils.toInt(TextUtil.replace(leaderboardType, skill.name().toLowerCase(Locale.ENGLISH) + "_", ""));
                    if (place > 0) {
                        List<SkillValue> list = plugin.getLeaderboardManager().getLeaderboard(skill, 1, 1);
                        if (list.size() > 0) {
                            SkillValue skillValue = list.get(0);
                            String name = Bukkit.getOfflinePlayer(skillValue.getId()).getName();
                            return (name != null ? name : "?") + " - " + skillValue.getLevel();
                        } else
                            return "";
                    } else {
                        if (identifier.endsWith("name")) {
                            int namePlace = NumberUtils.toInt(TextUtil.replace(leaderboardType, skill.name().toLowerCase(Locale.ENGLISH) + "_", "", "_name", ""));
                            if (namePlace > 0) {
                                List<SkillValue> list = plugin.getLeaderboardManager().getLeaderboard(skill, namePlace, 1);
                                if (list.size() > 0) {
                                    SkillValue skillValue = list.get(0);
                                    String name = Bukkit.getOfflinePlayer(skillValue.getId()).getName();
                                    return name != null ? name : "?";
                                } else
                                    return "";
                            }
                        } else if (identifier.endsWith("value")) {
                            int valuePlace = NumberUtils.toInt(TextUtil.replace(leaderboardType, skill.name().toLowerCase(Locale.ENGLISH) + "_", "", "_value", ""));
                            if (valuePlace > 0) {
                                List<SkillValue> list = plugin.getLeaderboardManager().getLeaderboard(skill, valuePlace, 1);
                                if (list.size() > 0) {
                                    SkillValue skillValue = list.get(0);
                                    return String.valueOf(skillValue.getLevel());
                                } else
                                    return "";
                            }
                        }
                    }
                }
            }
        }
    }
    if (identifier.equals("rank")) {
        return String.valueOf(plugin.getLeaderboardManager().getPowerRank(player.getUniqueId()));
    }
    if (identifier.startsWith("rank_")) {
        String skillName = TextUtil.replace(identifier, "rank_", "");
        Skill skill = plugin.getSkillRegistry().getSkill(skillName);
        if (skill != null) {
            return String.valueOf(plugin.getLeaderboardManager().getSkillRank(skill, player.getUniqueId()));
        }
    }
    for (String id : xpIdentifiers) {
        if (identifier.startsWith(id)) {
            String skillName = TextUtil.replace(identifier, id, "");
            Skill skill = plugin.getSkillRegistry().getSkill(skillName);
            if (skill != null) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData != null) {
                    switch(id) {
                        case "xp_required_formatted_":
                            return BigNumber.withSuffix(plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1));
                        case "xp_required_":
                            return String.valueOf(plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1));
                        case "xp_progress_int_":
                            return String.valueOf(Math.round(playerData.getSkillXp(skill) / (double) (plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1)) * 100));
                        case "xp_progress_1_":
                            return NumberUtil.format1(playerData.getSkillXp(skill) / (double) (plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1)) * 100);
                        case "xp_progress_":
                            return String.valueOf(playerData.getSkillXp(skill) / (double) (plugin.getLeveler().getXpRequirements().getXpRequired(skill, playerData.getSkillLevel(skill) + 1)) * 100);
                        case "xp_int_":
                            return String.valueOf(Math.round(playerData.getSkillXp(skill)));
                        case "xp_formatted_":
                            return BigNumber.withSuffix(Math.round(playerData.getSkillXp(skill)));
                        case "xp_":
                            return String.valueOf(playerData.getSkillXp(skill));
                    }
                }
            }
        }
    }
    if (identifier.startsWith("multiplier")) {
        if (identifier.equals("multiplier")) {
            return NumberUtil.format2(plugin.getLeveler().getMultiplier(player));
        }
        String skillName = TextUtil.replace(identifier, "multiplier_", "");
        Skill skill = plugin.getSkillRegistry().getSkill(skillName);
        if (skill != null) {
            return NumberUtil.format2(plugin.getLeveler().getMultiplier(player, skill));
        }
    }
    if (identifier.startsWith("multiplier_percent")) {
        if (identifier.equals("multiplier_percent")) {
            return String.valueOf(Math.round((plugin.getLeveler().getMultiplier(player) - 1) * 100));
        }
        String skillName = TextUtil.replace(identifier, "multiplier_percent_", "");
        Skill skill = plugin.getSkillRegistry().getSkill(skillName);
        if (skill != null) {
            return String.valueOf(Math.round((plugin.getLeveler().getMultiplier(player, skill) - 1) * 100));
        }
    }
    return null;
}
Also used : Skill(com.archyx.aureliumskills.skills.Skill) Stat(com.archyx.aureliumskills.stats.Stat) AttributeInstance(org.bukkit.attribute.AttributeInstance) List(java.util.List) SkillValue(com.archyx.aureliumskills.leaderboard.SkillValue) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 70 with PlayerData

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

the class ActionBar method startUpdateActionBar.

public void startUpdateActionBar() {
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
        if (OptionL.getBoolean(Option.ACTION_BAR_ENABLED) && OptionL.getBoolean(Option.ACTION_BAR_IDLE)) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                // Check disabled worlds
                if (!actionBarDisabled.contains(player.getUniqueId())) {
                    if (!plugin.getWorldManager().isDisabledWorld(player.getWorld())) {
                        if (!currentAction.containsKey(player)) {
                            currentAction.put(player, 0);
                        }
                        if (!isGainingXp.contains(player) && !isPaused.contains(player)) {
                            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                            if (playerData != null) {
                                Locale locale = playerData.getLocale();
                                sendActionBar(player, TextUtil.replace(Lang.getMessage(ActionBarMessage.IDLE, locale), "{hp}", getHp(player), "{max_hp}", getMaxHp(player), "{mana}", getMana(playerData), "{max_mana}", getMaxMana(playerData)));
                            }
                        }
                    }
                }
            }
        }
    }, 0L, OptionL.getInt(Option.ACTION_BAR_UPDATE_PERIOD));
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
        if (OptionL.getBoolean(Option.ACTION_BAR_ENABLED)) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                Integer time = timer.get(player);
                if (time != null) {
                    if (time != 0) {
                        timer.put(player, time - 1);
                    }
                } else {
                    timer.put(player, 0);
                }
            }
        }
    }, 0L, 2L);
}
Also used : Locale(java.util.Locale) 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