Search in sources :

Example 71 with PlayerData

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

the class ActionBar method sendAbilityActionBar.

public void sendAbilityActionBar(Player player, String message) {
    if (!actionBarDisabled.contains(player.getUniqueId())) {
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData == null)
            return;
        sendActionBar(player, TextUtil.replace(Lang.getMessage(ActionBarMessage.ABILITY, playerData.getLocale()), "{hp}", getHp(player), "{max_hp}", getMaxHp(player), "{mana}", getMana(playerData), "{max_mana}", getMaxMana(playerData), "{message}", message));
        setPaused(player, 40);
    }
}
Also used : PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 72 with PlayerData

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

the class ForgingAbilities method getHighestPlayer.

@Nullable
private Player getHighestPlayer(List<HumanEntity> viewers) {
    int highestLevel = 0;
    Player highestPlayer = null;
    for (HumanEntity entity : viewers) {
        if (entity instanceof Player) {
            Player player = (Player) entity;
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                int level = playerData.getSkillLevel(Skills.FORGING);
                if (level > highestLevel) {
                    highestLevel = level;
                    highestPlayer = player;
                }
            }
        }
    }
    return highestPlayer;
}
Also used : Player(org.bukkit.entity.Player) HumanEntity(org.bukkit.entity.HumanEntity) PlayerData(com.archyx.aureliumskills.data.PlayerData) Nullable(org.jetbrains.annotations.Nullable)

Example 73 with PlayerData

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

the class ForgingAbilities method repairing.

@EventHandler(priority = EventPriority.MONITOR)
@SuppressWarnings("deprecation")
public void repairing(PrepareAnvilEvent event) {
    if (blockDisabled(Ability.REPAIRING))
        return;
    Player player = getHighestPlayer(event.getViewers());
    if (player == null)
        return;
    if (blockAbility(player))
        return;
    AnvilInventory inventory = event.getInventory();
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    if (playerData.getAbilityLevel(Ability.REPAIRING) == 0)
        return;
    ItemStack first = inventory.getItem(0);
    ItemStack second = inventory.getItem(1);
    ItemStack result = event.getResult();
    if (first == null || second == null || result == null)
        return;
    // Check if the seconds slot is a raw material for repair
    XMaterial rawMaterial = getRawMaterial(first.getType());
    if (rawMaterial == null)
        return;
    if (second.getType() == rawMaterial.parseMaterial()) {
        if (XMaterial.isNewVersion()) {
            ItemMeta meta = first.getItemMeta();
            if (meta == null)
                return;
            if (meta instanceof Damageable) {
                Damageable damageable = (Damageable) meta;
                short max = first.getType().getMaxDurability();
                // Calculate durability to add, vanilla by default adds 20% of the max durability
                long addedLong = second.getAmount() * (Math.round(0.25 * max) + Math.round(max * 0.25 * (getValue(Ability.REPAIRING, playerData) / 100)));
                short added;
                if (addedLong > Short.MAX_VALUE) {
                    added = (short) damageable.getDamage();
                } else if (addedLong < Short.MIN_VALUE) {
                    added = 0;
                } else {
                    added = (short) addedLong;
                }
                damageable.setDamage(Math.max(damageable.getDamage() - added, 0));
                result.setItemMeta(damageable);
            }
        } else {
            // For old versions
            short max = result.getType().getMaxDurability();
            long addedLong = second.getAmount() * (Math.round(0.25 * max) + Math.round(max * 0.25 * (getValue(Ability.REPAIRING, playerData) / 100)));
            short added;
            if (addedLong > Short.MAX_VALUE) {
                added = first.getDurability();
            } else if (addedLong < Short.MIN_VALUE) {
                added = 0;
            } else {
                added = (short) addedLong;
            }
            result.setDurability((short) Math.max(first.getDurability() - added, 0));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Damageable(org.bukkit.inventory.meta.Damageable) AnvilInventory(org.bukkit.inventory.AnvilInventory) ItemStack(org.bukkit.inventory.ItemStack) XMaterial(com.cryptomorin.xseries.XMaterial) PlayerData(com.archyx.aureliumskills.data.PlayerData) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Example 74 with PlayerData

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

the class HealingAbilities method revivalLeave.

@EventHandler(priority = EventPriority.LOW)
public void revivalLeave(PlayerQuitEvent event) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(event.getPlayer());
    if (playerData == null) {
        return;
    }
    playerData.removeStatModifier("AureliumSkills.Ability.Revival.Health");
    playerData.removeStatModifier("AureliumSkills.Ability.Revival.Regeneration");
}
Also used : PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 75 with PlayerData

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

the class HealingAbilities method lifeEssence.

@EventHandler
public void lifeEssence(EntityRegainHealthEvent event) {
    if (blockDisabled(Ability.LIFE_ESSENCE))
        return;
    if (event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        if (blockAbility(player))
            return;
        if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.MAGIC) {
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData == null)
                return;
            if (playerData.getAbilityLevel(Ability.LIFE_ESSENCE) > 0) {
                double multiplier = 1 + getValue(Ability.LIFE_ESSENCE, playerData) / 100;
                event.setAmount(event.getAmount() * multiplier);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

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