Search in sources :

Example 6 with PlayerLootDropEvent

use of com.archyx.aureliumskills.api.event.PlayerLootDropEvent 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)

Example 7 with PlayerLootDropEvent

use of com.archyx.aureliumskills.api.event.PlayerLootDropEvent in project AureliumSkills by Archy-X.

the class MiningAbilities method luckyMiner.

public void luckyMiner(Player player, Block block, MiningSource source) {
    if (OptionL.isEnabled(Skills.MINING)) {
        if (plugin.getAbilityManager().isEnabled(Ability.LUCKY_MINER)) {
            if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData == null)
                    return;
                if (playerData.getAbilityLevel(Ability.LUCKY_MINER) > 0) {
                    if (r.nextDouble() < (getValue(Ability.LUCKY_MINER, playerData) / 100)) {
                        ItemStack tool = player.getInventory().getItemInMainHand();
                        Material mat = block.getType();
                        if (tool.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0) {
                            if (mat.equals(Material.DIAMOND_ORE) || mat.equals(Material.LAPIS_ORE) || mat.equals(Material.REDSTONE_ORE) || mat.name().equals("GLOWING_REDSTONE_ORE") || mat.equals(Material.EMERALD_ORE) || mat.equals(Material.COAL_ORE) || mat.equals(XMaterial.NETHER_QUARTZ_ORE.parseMaterial()) || mat.equals(XMaterial.NETHER_GOLD_ORE.parseMaterial())) {
                                return;
                            }
                            if (VersionUtils.isAtLeastVersion(17)) {
                                if (mat == Material.IRON_ORE || mat == Material.GOLD_ORE || mat == Material.COPPER_ORE || source.toString().contains("DEEPSLATE_")) {
                                    return;
                                }
                            }
                        }
                        Collection<ItemStack> drops = block.getDrops(tool);
                        for (ItemStack item : drops) {
                            PlayerLootDropEvent event = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUCKY_MINER);
                            Bukkit.getPluginManager().callEvent(event);
                            if (!event.isCancelled()) {
                                block.getWorld().dropItem(event.getLocation(), event.getItemStack());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : PlayerLootDropEvent(com.archyx.aureliumskills.api.event.PlayerLootDropEvent) Material(org.bukkit.Material) XMaterial(com.cryptomorin.xseries.XMaterial) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 8 with PlayerLootDropEvent

use of com.archyx.aureliumskills.api.event.PlayerLootDropEvent in project AureliumSkills by Archy-X.

the class LootHandler method giveBlockItemLoot.

protected void giveBlockItemLoot(Player player, ItemLoot loot, BlockBreakEvent event, @Nullable Source source, LootDropCause cause) {
    Block block = event.getBlock();
    ItemStack drop = loot.getItem().clone();
    drop.setAmount(generateAmount(loot.getMinAmount(), loot.getMaxAmount()));
    Location location = block.getLocation().add(0.5, 0.5, 0.5);
    // Call event
    PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, drop, location, cause);
    if (cause != null) {
        Bukkit.getPluginManager().callEvent(dropEvent);
        if (dropEvent.isCancelled())
            return;
    }
    if (dropEvent.getItemStack().getType() == Material.AIR)
        return;
    block.getWorld().dropItem(dropEvent.getLocation(), dropEvent.getItemStack());
    attemptSendMessage(player, loot);
    giveXp(player, loot, source);
}
Also used : PlayerLootDropEvent(com.archyx.aureliumskills.api.event.PlayerLootDropEvent) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 9 with PlayerLootDropEvent

use of com.archyx.aureliumskills.api.event.PlayerLootDropEvent in project AureliumSkills by Archy-X.

the class LootHandler method giveFishingItemLoot.

protected void giveFishingItemLoot(Player player, ItemLoot loot, PlayerFishEvent event, @Nullable Source source, LootDropCause cause) {
    if (!(event.getCaught() instanceof Item))
        return;
    Item itemEntity = (Item) event.getCaught();
    int amount = generateAmount(loot.getMinAmount(), loot.getMaxAmount());
    if (amount == 0)
        return;
    ItemStack drop = loot.getItem().clone();
    drop.setAmount(amount);
    Location location = event.getCaught().getLocation();
    // Call event
    PlayerLootDropEvent dropEvent = new PlayerLootDropEvent(player, drop, location, cause);
    if (cause != null) {
        Bukkit.getPluginManager().callEvent(dropEvent);
        if (dropEvent.isCancelled())
            return;
    }
    itemEntity.setItemStack(drop);
    attemptSendMessage(player, loot);
    giveXp(player, loot, source);
}
Also used : Item(org.bukkit.entity.Item) PlayerLootDropEvent(com.archyx.aureliumskills.api.event.PlayerLootDropEvent) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Aggregations

PlayerLootDropEvent (com.archyx.aureliumskills.api.event.PlayerLootDropEvent)9 ItemStack (org.bukkit.inventory.ItemStack)9 PlayerData (com.archyx.aureliumskills.data.PlayerData)7 Location (org.bukkit.Location)3 Material (org.bukkit.Material)3 XMaterial (com.cryptomorin.xseries.XMaterial)2 Block (org.bukkit.block.Block)2 Item (org.bukkit.entity.Item)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2