Search in sources :

Example 1 with ItemLoot

use of com.archyx.aureliumskills.loot.type.ItemLoot 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 2 with ItemLoot

use of com.archyx.aureliumskills.loot.type.ItemLoot in project AureliumSkills by Archy-X.

the class BlockLootHandler method selectBlockLoot.

private boolean selectBlockLoot(LootPool pool, Player player, double chance, Source originalSource, BlockBreakEvent event, LootDropCause cause) {
    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;
                giveBlockItemLoot(player, itemLoot, event, originalSource, cause);
            } else if (selectedLoot instanceof CommandLoot) {
                CommandLoot commandLoot = (CommandLoot) selectedLoot;
                giveCommandLoot(player, commandLoot, originalSource);
            }
            // Override vanilla loot if enabled
            if (pool.overridesVanillaLoot()) {
                event.setDropItems(false);
            }
            return true;
        }
    }
    return false;
}
Also used : Loot(com.archyx.aureliumskills.loot.Loot) CommandLoot(com.archyx.aureliumskills.loot.type.CommandLoot) ItemLoot(com.archyx.aureliumskills.loot.type.ItemLoot) ItemLoot(com.archyx.aureliumskills.loot.type.ItemLoot) CommandLoot(com.archyx.aureliumskills.loot.type.CommandLoot)

Aggregations

Loot (com.archyx.aureliumskills.loot.Loot)2 CommandLoot (com.archyx.aureliumskills.loot.type.CommandLoot)2 ItemLoot (com.archyx.aureliumskills.loot.type.ItemLoot)2 LootDropCause (com.archyx.aureliumskills.api.event.LootDropCause)1 PlayerData (com.archyx.aureliumskills.data.PlayerData)1 LootPool (com.archyx.aureliumskills.loot.LootPool)1 LootTable (com.archyx.aureliumskills.loot.LootTable)1 Source (com.archyx.aureliumskills.source.Source)1 Item (org.bukkit.entity.Item)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1