Search in sources :

Example 76 with PlayerData

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

the class FishingAbilities method luckyCatch.

@EventHandler
public void luckyCatch(PlayerFishEvent event) {
    if (blockDisabled(Ability.LUCKY_CATCH))
        return;
    Player player = event.getPlayer();
    if (blockAbility(player))
        return;
    if (event.getCaught() instanceof Item) {
        if (event.getExpToDrop() > 0) {
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                if (r.nextDouble() < (getValue(Ability.LUCKY_CATCH, playerData) / 100)) {
                    Item item = (Item) event.getCaught();
                    ItemStack drop = item.getItemStack();
                    if (drop.getMaxStackSize() > 1) {
                        drop.setAmount(drop.getAmount() * 2);
                        PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, drop, item.getLocation(), LootDropCause.LUCKY_CATCH);
                        Bukkit.getPluginManager().callEvent(dropEvent);
                        if (!event.isCancelled()) {
                            item.setItemStack(dropEvent.getItemStack());
                        }
                    }
                }
            }
        }
    }
}
Also used : Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) PlayerLootDropEvent(com.archyx.aureliumskills.api.event.PlayerLootDropEvent) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 77 with PlayerData

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

the class FishingLootHandler method onFish.

@EventHandler(priority = EventPriority.HIGH)
public void onFish(PlayerFishEvent event) {
    if (!OptionL.isEnabled(Skills.FISHING))
        return;
    Player player = event.getPlayer();
    if (blockAbility(player))
        return;
    if (plugin.getWorldManager().isInBlockedWorld(player.getLocation())) {
        return;
    }
    if (plugin.isWorldGuardEnabled()) {
        if (plugin.getWorldGuardSupport().isInBlockedRegion(player.getLocation())) {
            return;
        } else // Check if blocked by flags
        if (plugin.getWorldGuardSupport().blockedByFlag(player.getLocation(), player, WorldGuardFlags.FlagKey.XP_GAIN)) {
            return;
        }
    }
    if (!(event.getCaught() instanceof Item))
        return;
    if (!event.getState().equals(PlayerFishEvent.State.CAUGHT_FISH))
        return;
    if (event.getExpToDrop() == 0)
        return;
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    ItemStack originalItem = ((Item) event.getCaught()).getItemStack();
    FishingSource originalSource = FishingSource.valueOf(originalItem);
    LootTable table = plugin.getLootTableManager().getLootTable(Skills.FISHING);
    if (table == null)
        return;
    for (LootPool pool : table.getPools()) {
        // Calculate chance for pool
        Source source;
        double chance = getCommonChance(pool, playerData);
        LootDropCause cause = LootDropCause.FISHING_OTHER_LOOT;
        if (pool.getName().equals("rare") && plugin.getAbilityManager().isEnabled(Ability.TREASURE_HUNTER)) {
            chance += (getValue(Ability.TREASURE_HUNTER, playerData) / 100);
            source = FishingSource.RARE;
            cause = LootDropCause.TREASURE_HUNTER;
        } else if (pool.getName().equals("epic") && plugin.getAbilityManager().isEnabled(Ability.EPIC_CATCH)) {
            chance += (getValue(Ability.EPIC_CATCH, playerData) / 100);
            source = FishingSource.EPIC;
            cause = LootDropCause.EPIC_CATCH;
        } else {
            source = originalSource;
        }
        if (random.nextDouble() < chance) {
            // Pool is selected
            Loot selectedLoot = selectLoot(pool, originalSource);
            // Give loot
            if (selectedLoot != null) {
                if (selectedLoot instanceof ItemLoot) {
                    ItemLoot itemLoot = (ItemLoot) selectedLoot;
                    giveFishingItemLoot(player, itemLoot, event, source, cause);
                } else if (selectedLoot instanceof CommandLoot) {
                    CommandLoot commandLoot = (CommandLoot) selectedLoot;
                    giveCommandLoot(player, commandLoot, source);
                }
                break;
            }
        }
    }
}
Also used : LootTable(com.archyx.aureliumskills.loot.LootTable) Player(org.bukkit.entity.Player) Loot(com.archyx.aureliumskills.loot.Loot) CommandLoot(com.archyx.aureliumskills.loot.type.CommandLoot) ItemLoot(com.archyx.aureliumskills.loot.type.ItemLoot) Source(com.archyx.aureliumskills.source.Source) Item(org.bukkit.entity.Item) LootDropCause(com.archyx.aureliumskills.api.event.LootDropCause) LootPool(com.archyx.aureliumskills.loot.LootPool) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) ItemLoot(com.archyx.aureliumskills.loot.type.ItemLoot) CommandLoot(com.archyx.aureliumskills.loot.type.CommandLoot) EventHandler(org.bukkit.event.EventHandler)

Example 78 with PlayerData

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

the class EnchantingAbilities method xpConvert.

@EventHandler(priority = EventPriority.MONITOR)
public void xpConvert(XpGainEvent event) {
    if (event.isCancelled())
        return;
    if (blockDisabled(Ability.XP_CONVERT))
        return;
    Player player = event.getPlayer();
    if (blockAbility(player))
        return;
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData != null) {
        if (playerData.getAbilityLevel(Ability.XP_CONVERT) > 0 && event.getAmount() > 0) {
            double totalXp = playerData.getAbilityData(Ability.XP_CONVERT).getDouble("xp") + event.getAmount();
            double value = getValue(Ability.XP_CONVERT, playerData);
            if (value > 0) {
                int added = (int) (totalXp / value);
                double remainder = totalXp - added * value;
                player.giveExp(added);
                playerData.getAbilityData(Ability.XP_CONVERT).setData("xp", remainder);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 79 with PlayerData

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

the class EnduranceAbilities method goldenHealAndRecovery.

@EventHandler(priority = EventPriority.HIGH)
public void goldenHealAndRecovery(EntityRegainHealthEvent event) {
    if (OptionL.isEnabled(Skills.ENDURANCE)) {
        if (!event.isCancelled()) {
            if (event.getEntity() instanceof Player) {
                Player player = (Player) event.getEntity();
                if (blockAbility(player))
                    return;
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData == null)
                    return;
                // Golden Heal
                if (event.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.MAGIC_REGEN)) {
                    if (isEnabled(Ability.GOLDEN_HEAL)) {
                        // Applies modifier
                        double modifier = getValue(Ability.GOLDEN_HEAL, playerData) / 100;
                        event.setAmount(event.getAmount() * (1 + modifier));
                    }
                } else // Recovery
                if (event.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.SATIATED)) {
                    if (isEnabled(Ability.RECOVERY)) {
                        // Gets health
                        AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
                        if (attribute != null) {
                            double currentHealth = player.getHealth();
                            double maxHealth = attribute.getValue();
                            // Checks if health is less than half of max
                            if (currentHealth < (maxHealth / 2)) {
                                // Applies modifier
                                double modifier = getValue(Ability.RECOVERY, playerData) / 100;
                                event.setAmount(event.getAmount() * (1 + modifier));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) AttributeInstance(org.bukkit.attribute.AttributeInstance) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 80 with PlayerData

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

the class EnduranceAbilities method recoveryCustom.

@EventHandler(priority = EventPriority.LOWEST)
public void recoveryCustom(CustomRegenEvent event) {
    if (!event.isCancelled()) {
        if (isEnabled(Ability.RECOVERY)) {
            Player player = event.getPlayer();
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData == null)
                return;
            // Gets health
            AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
            if (attribute != null) {
                double currentHealth = player.getHealth();
                double maxHealth = attribute.getValue();
                // Checks if health is less than half of max
                if (currentHealth < (maxHealth / 2)) {
                    // Applies modifier
                    double modifier = getValue(Ability.RECOVERY, playerData) / 100;
                    event.setAmount(event.getAmount() * (1 + modifier));
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) AttributeInstance(org.bukkit.attribute.AttributeInstance) 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