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)));
}
}
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);
}
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);
}
}
}
}
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);
}
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));
}
Aggregations