Search in sources :

Example 81 with PlayerData

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

the class EnduranceAbilities method antiHunger.

@EventHandler(priority = EventPriority.HIGH)
public void antiHunger(FoodLevelChangeEvent event) {
    if (blockDisabled(Ability.ANTI_HUNGER))
        return;
    if (!event.isCancelled()) {
        if (event.getEntity() instanceof Player) {
            Player player = (Player) event.getEntity();
            if (blockAbility(player))
                return;
            // Checks if food level would be decreased
            if (player.getFoodLevel() > event.getFoodLevel()) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData == null)
                    return;
                double chance = getValue(Ability.ANTI_HUNGER, playerData) / 100;
                if (r.nextDouble() < chance) {
                    event.setFoodLevel(player.getFoodLevel());
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 82 with PlayerData

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

the class Luck method onBlockBreak.

@EventHandler(priority = EventPriority.HIGHEST)
@SuppressWarnings("deprecation")
public void onBlockBreak(BlockBreakEvent event) {
    if (OptionL.getBoolean(Option.LUCK_DOUBLE_DROP_ENABLED) && !event.isCancelled()) {
        Player player = event.getPlayer();
        Block block = event.getBlock();
        // Checks if in blocked or disabled world
        if (plugin.getWorldManager().isInBlockedWorld(block.getLocation())) {
            return;
        }
        // Checks if in blocked region
        if (plugin.isWorldGuardEnabled()) {
            if (plugin.getWorldGuardSupport().isInBlockedRegion(block.getLocation())) {
                return;
            } else // Check if blocked by flags
            if (plugin.getWorldGuardSupport().blockedByFlag(block.getLocation(), player, WorldGuardFlags.FlagKey.XP_GAIN)) {
                return;
            }
        }
        if (!event.isDropItems()) {
            return;
        }
        if (player.getGameMode().equals(GameMode.SURVIVAL)) {
            if (plugin.getRegionManager().isPlacedBlock(block))
                return;
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData == null)
                return;
            Material mat = block.getType();
            if (mat.equals(Material.STONE) || mat.equals(Material.COBBLESTONE) || mat.equals(Material.SAND) || mat.equals(Material.GRAVEL) || mat.equals(Material.DIRT) || mat.equals(XMaterial.GRASS_BLOCK.parseMaterial()) || mat.equals(XMaterial.ANDESITE.parseMaterial()) || mat.equals(XMaterial.DIORITE.parseMaterial()) || mat.equals(XMaterial.GRANITE.parseMaterial())) {
                // Calculate chance
                double chance = playerData.getStatLevel(Stats.LUCK) * OptionL.getDouble(Option.LUCK_DOUBLE_DROP_MODIFIER);
                if (chance * 100 > OptionL.getDouble(Option.LUCK_DOUBLE_DROP_PERCENT_MAX)) {
                    chance = OptionL.getDouble(Option.LUCK_DOUBLE_DROP_PERCENT_MAX);
                }
                if (r.nextDouble() < chance) {
                    ItemStack tool = player.getInventory().getItemInMainHand();
                    for (ItemStack item : block.getDrops(tool)) {
                        // If silk touch
                        if (tool.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0) {
                            if (mat.equals(Material.STONE)) {
                                if (!XMaterial.isNewVersion()) {
                                    if (block.getData() == 0) {
                                        PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(Material.STONE), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
                                        Bukkit.getPluginManager().callEvent(dropEvent);
                                        if (!event.isCancelled()) {
                                            block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
                                        }
                                    }
                                } else {
                                    PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(Material.STONE), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
                                    Bukkit.getPluginManager().callEvent(dropEvent);
                                    if (!event.isCancelled()) {
                                        block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
                                    }
                                }
                            } else if (mat.equals(XMaterial.GRASS_BLOCK.parseMaterial())) {
                                Material grassBlock = XMaterial.GRASS_BLOCK.parseMaterial();
                                PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, new ItemStack(grassBlock), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
                                Bukkit.getPluginManager().callEvent(dropEvent);
                                if (!event.isCancelled()) {
                                    block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
                                }
                            }
                        } else // Drop regular item if not silk touch
                        {
                            PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCK_DOUBLE_DROP);
                            Bukkit.getPluginManager().callEvent(dropEvent);
                            if (!event.isCancelled()) {
                                block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerLootDropEvent(com.archyx.aureliumskills.api.event.PlayerLootDropEvent) Block(org.bukkit.block.Block) Material(org.bukkit.Material) XMaterial(com.cryptomorin.xseries.XMaterial) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 83 with PlayerData

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

the class Luck method setLuck.

private void setLuck(Player player) {
    AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_LUCK);
    if (attribute != null) {
        boolean hasModifier = false;
        // Removes existing modifiers of the same name
        for (AttributeModifier am : attribute.getModifiers()) {
            if (am.getName().equals("AureliumSkills-Luck")) {
                attribute.removeModifier(am);
                hasModifier = true;
            }
        }
        if (!hasModifier) {
            attribute.setBaseValue(0.0);
        }
        if (plugin.getWorldManager().isInDisabledWorld(player.getLocation())) {
            return;
        }
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData != null) {
            double luck = playerData.getStatLevel(Stats.LUCK) * OptionL.getDouble(Option.LUCK_MODIFIER);
            attribute.addModifier(new AttributeModifier("AureliumSkills-Luck", luck, AttributeModifier.Operation.ADD_NUMBER));
        }
    }
}
Also used : AttributeInstance(org.bukkit.attribute.AttributeInstance) AttributeModifier(org.bukkit.attribute.AttributeModifier) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 84 with PlayerData

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

the class Regeneration method startSaturationRegen.

public void startSaturationRegen() {
    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()) {
                            if (player.getSaturation() > 0 && player.getFoodLevel() >= 20) {
                                AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
                                if (attribute != null) {
                                    double amountGained = Math.min(OptionL.getDouble(Option.REGENERATION_BASE_REGEN) + playerData.getStatLevel(Stats.REGENERATION) * OptionL.getDouble(Option.REGENERATION_SATURATED_MODIFIER), attribute.getValue() - player.getHealth());
                                    CustomRegenEvent event = new CustomRegenEvent(player, amountGained, RegenReason.SATURATED);
                                    Bukkit.getPluginManager().callEvent(event);
                                    if (!event.isCancelled()) {
                                        player.setHealth(player.getHealth() + amountGained);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }, 0L, OptionL.getInt(Option.REGENERATION_SATURATED_DELAY));
}
Also used : Player(org.bukkit.entity.Player) AttributeInstance(org.bukkit.attribute.AttributeInstance) CustomRegenEvent(com.archyx.aureliumskills.api.event.CustomRegenEvent) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 85 with PlayerData

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

the class FarmingAbilities method bountifulHarvest.

public void bountifulHarvest(Player player, Block block) {
    if (OptionL.isEnabled(Skills.FARMING)) {
        if (plugin.getAbilityManager().isEnabled(Ability.BOUNTIFUL_HARVEST)) {
            if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData == null)
                    return;
                if (playerData.getAbilityLevel(Ability.BOUNTIFUL_HARVEST) > 0) {
                    if (r.nextDouble() < (getValue(Ability.BOUNTIFUL_HARVEST, playerData)) / 100) {
                        for (ItemStack item : block.getDrops()) {
                            checkMelonSilkTouch(player, block, item);
                            PlayerLootDropEvent event = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.BOUNTIFUL_HARVEST);
                            Bukkit.getPluginManager().callEvent(event);
                            if (!event.isCancelled()) {
                                block.getWorld().dropItem(event.getLocation(), event.getItemStack());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : PlayerLootDropEvent(com.archyx.aureliumskills.api.event.PlayerLootDropEvent) ItemStack(org.bukkit.inventory.ItemStack) 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