use of com.archyx.aureliumskills.rewards.Reward in project AureliumSkills by Archy-X.
the class Leveler method levelUpSkill.
private void levelUpSkill(PlayerData playerData, Skill skill) {
Player player = playerData.getPlayer();
Locale locale = playerData.getLocale();
double currentXp = playerData.getSkillXp(skill);
int level = playerData.getSkillLevel(skill) + 1;
playerData.setSkillXp(skill, currentXp - xpRequirements.getXpRequired(skill, level));
playerData.setSkillLevel(skill, level);
// Give custom rewards
List<Reward> rewards = plugin.getRewardManager().getRewardTable(skill).getRewards(level);
for (Reward reward : rewards) {
reward.giveReward(player, skill, level);
}
// Adds money rewards if enabled
if (plugin.isVaultEnabled()) {
if (OptionL.getBoolean(Option.SKILL_MONEY_REWARDS_ENABLED)) {
Economy economy = plugin.getEconomy();
double base = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_BASE);
double multiplier = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_MULTIPLIER);
economy.depositPlayer(player, base + (multiplier * level * level));
}
}
// Reload items and armor to check for newly met requirements
plugin.getModifierManager().reloadPlayer(player);
// Calls event
SkillLevelUpEvent event = new SkillLevelUpEvent(player, skill, level);
Bukkit.getPluginManager().callEvent(event);
// Sends messages
if (OptionL.getBoolean(Option.LEVELER_TITLE_ENABLED)) {
sendTitle(player, locale, skill, level);
}
if (OptionL.getBoolean(Option.LEVELER_SOUND_ENABLED)) {
playSound(player);
}
player.sendMessage(getLevelUpMessage(player, playerData, skill, level, locale, rewards));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> checkLevelUp(player, skill), OptionL.getInt(Option.LEVELER_DOUBLE_CHECK_DELAY));
}
use of com.archyx.aureliumskills.rewards.Reward in project AureliumSkills by Archy-X.
the class ProgressLevelItem method getRewardsLore.
public String getRewardsLore(Skill skill, int level, Player player, Locale locale) {
ImmutableList<Reward> rewards = plugin.getRewardManager().getRewardTable(skill).getRewards(level);
StringBuilder message = new StringBuilder();
double totalMoney = 0;
for (Reward reward : rewards) {
message.append(reward.getMenuMessage(player, locale, skill, level));
if (reward instanceof MoneyReward) {
totalMoney += ((MoneyReward) reward).getAmount();
}
}
// Legacy money rewards
if (plugin.isVaultEnabled()) {
if (OptionL.getBoolean(Option.SKILL_MONEY_REWARDS_ENABLED)) {
double base = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_BASE);
double multiplier = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_MULTIPLIER);
totalMoney += base + (multiplier * level * level);
}
}
if (totalMoney > 0) {
message.append(TextUtil.replace(Lang.getMessage(MenuMessage.MONEY_REWARD, locale), "{amount}", NumberUtil.format2(totalMoney)));
}
return TextUtil.replace(Lang.getMessage(MenuMessage.REWARDS, locale), "{rewards}", message.toString());
}
use of com.archyx.aureliumskills.rewards.Reward in project AureliumSkills by Archy-X.
the class Leveler method getLevelUpMessage.
private String getLevelUpMessage(Player player, PlayerData playerData, Skill skill, int newLevel, Locale locale, List<Reward> rewards) {
String message = TextUtil.replace(Lang.getMessage(LevelerMessage.LEVEL_UP, locale), "{skill}", skill.getDisplayName(locale), "{old}", RomanNumber.toRoman(newLevel - 1), "{new}", RomanNumber.toRoman(newLevel));
if (plugin.isPlaceholderAPIEnabled()) {
message = PlaceholderAPI.setPlaceholders(player, message);
}
StringBuilder rewardMessage = new StringBuilder();
for (Reward reward : rewards) {
rewardMessage.append(reward.getChatMessage(player, locale, skill, newLevel));
}
// Ability unlocks and level ups
StringBuilder abilityUnlockMessage = new StringBuilder();
StringBuilder abilityLevelUpMessage = new StringBuilder();
for (Ability ability : plugin.getAbilityManager().getAbilities(skill, newLevel)) {
if (plugin.getAbilityManager().isEnabled(ability)) {
if (plugin.getAbilityManager().getUnlock(ability) == newLevel) {
abilityUnlockMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.ABILITY_UNLOCK, locale), "{ability}", ability.getDisplayName(locale)));
} else {
abilityLevelUpMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.ABILITY_LEVEL_UP, locale), "{ability}", ability.getDisplayName(locale), "{level}", RomanNumber.toRoman(playerData.getAbilityLevel(ability))));
}
}
}
message = TextUtil.replace(message, "{stat_level}", rewardMessage.toString(), "{ability_unlock}", abilityUnlockMessage.toString(), "{ability_level_up}", abilityLevelUpMessage.toString());
// Mana ability unlocks and level ups
StringBuilder manaAbilityUnlockMessage = new StringBuilder();
StringBuilder manaAbilityLevelUpMessage = new StringBuilder();
MAbility mAbility = plugin.getManaAbilityManager().getManaAbility(skill, newLevel);
if (mAbility != null) {
if (plugin.getAbilityManager().isEnabled(mAbility)) {
if (plugin.getManaAbilityManager().getUnlock(mAbility) == newLevel) {
manaAbilityUnlockMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.MANA_ABILITY_UNLOCK, locale), "{mana_ability}", mAbility.getDisplayName(locale)));
} else {
manaAbilityLevelUpMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.MANA_ABILITY_LEVEL_UP, locale), "{mana_ability}", mAbility.getDisplayName(locale), "{level}", RomanNumber.toRoman(playerData.getManaAbilityLevel(mAbility))));
}
}
}
message = TextUtil.replace(message, "{mana_ability_unlock}", manaAbilityUnlockMessage.toString(), "{mana_ability_level_up}", manaAbilityLevelUpMessage.toString());
// Build money rewards
StringBuilder moneyRewardMessage = new StringBuilder();
double totalMoney = 0;
// Legacy system
if (plugin.isVaultEnabled()) {
if (OptionL.getBoolean(Option.SKILL_MONEY_REWARDS_ENABLED)) {
double base = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_BASE);
double multiplier = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_MULTIPLIER);
totalMoney += base + (multiplier * newLevel * newLevel);
}
}
// New rewards
for (MoneyReward reward : plugin.getRewardManager().getRewardTable(skill).searchRewards(MoneyReward.class, newLevel)) {
totalMoney += reward.getAmount();
}
if (totalMoney > 0) {
NumberFormat nf = new DecimalFormat("#.##");
moneyRewardMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.MONEY_REWARD, locale), "{amount}", nf.format(totalMoney)));
}
message = TextUtil.replace(message, "{money_reward}", moneyRewardMessage.toString());
return message.replaceAll("(\\u005C\\u006E)|(\\n)", "\n");
}
Aggregations