Search in sources :

Example 1 with PlayerLootDropEvent

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

the class FarmingAbilities method tripleHarvest.

public void tripleHarvest(Player player, Block block) {
    if (OptionL.isEnabled(Skills.FARMING)) {
        if (plugin.getAbilityManager().isEnabled(Ability.TRIPLE_HARVEST)) {
            if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData == null)
                    return;
                if (playerData.getAbilityLevel(Ability.TRIPLE_HARVEST) > 0) {
                    if (r.nextDouble() < (getValue(Ability.TRIPLE_HARVEST, playerData)) / 100) {
                        for (ItemStack item : block.getDrops()) {
                            checkMelonSilkTouch(player, block, item);
                            ItemStack droppedItem = item.clone();
                            droppedItem.setAmount(2);
                            PlayerLootDropEvent event = new PlayerLootDropEvent(player, droppedItem, block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.TRIPLE_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 2 with PlayerLootDropEvent

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

the class ForagingAbilities method lumberjack.

public void lumberjack(Player player, Block block) {
    if (OptionL.isEnabled(Skills.FORAGING)) {
        if (plugin.getAbilityManager().isEnabled(Ability.LUMBERJACK)) {
            if (player.getGameMode().equals(GameMode.SURVIVAL)) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData == null)
                    return;
                if (playerData.getAbilityLevel(Ability.LUMBERJACK) > 0) {
                    if (r.nextDouble() < ((getValue(Ability.LUMBERJACK, playerData)) / 100)) {
                        for (ItemStack item : block.getDrops(player.getInventory().getItemInMainHand())) {
                            PlayerLootDropEvent event = new PlayerLootDropEvent(player, item.clone(), block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.LUMBERJACK);
                            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 3 with PlayerLootDropEvent

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

the class ExcavationAbilities method biggerScoop.

@SuppressWarnings("deprecation")
public void biggerScoop(ExcavationSource source, Block block, Player player) {
    if (!plugin.getAbilityManager().isEnabled(Ability.BIGGER_SCOOP))
        return;
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    if (player.getGameMode() != GameMode.SURVIVAL)
        return;
    if (r.nextDouble() < (getValue(Ability.BIGGER_SCOOP, playerData) / 100)) {
        ItemStack tool = player.getInventory().getItemInMainHand();
        Material mat = block.getType();
        for (ItemStack item : block.getDrops(tool)) {
            // If silk touch
            if (tool.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0) {
                PlayerLootDropEvent event;
                Location loc = block.getLocation().add(0.5, 0.5, 0.5);
                if (source.getLegacyData() == -1) {
                    event = new PlayerLootDropEvent(player, new ItemStack(mat, 2), loc, LootDropCause.BIGGER_SCOOP);
                } else {
                    if (VersionUtils.isAtLeastVersion(13)) {
                        event = new PlayerLootDropEvent(player, new ItemStack(mat, 2), loc, LootDropCause.BIGGER_SCOOP);
                    } else {
                        event = new PlayerLootDropEvent(player, new ItemStack(mat, 2, source.getLegacyData()), loc, LootDropCause.BIGGER_SCOOP);
                    }
                }
                Bukkit.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    block.getWorld().dropItem(event.getLocation(), event.getItemStack());
                }
            } else // Drop regular item if not silk touch
            {
                ItemStack drop = item.clone();
                drop.setAmount(2);
                PlayerLootDropEvent event = new PlayerLootDropEvent(player, drop, block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.BIGGER_SCOOP);
                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) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) Location(org.bukkit.Location)

Example 4 with PlayerLootDropEvent

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

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

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