Search in sources :

Example 1 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project TotalEconomy by Erigitic.

the class TEJobManager method onPlayerFish.

/**
     * Used for the catch option in jobs. Will check if the job has the catch node and if it does it will check if the
     * item that was caught is present in the config of the player's job. If it is, it will grab the job exp reward as
     * well as the pay.
     *
     * @param event FishingEvent.Stop
     */
@Listener
public void onPlayerFish(FishingEvent.Stop event) {
    if (event.getCause().first(Player.class).isPresent()) {
        // no transaction, so execution can stop
        if (event.getItemStackTransaction().size() == 0) {
            return;
        }
        Transaction<ItemStackSnapshot> itemTransaction = event.getItemStackTransaction().get(0);
        ItemStack itemStack = itemTransaction.getFinal().createStack();
        Player player = event.getCause().first(Player.class).get();
        UUID playerUUID = player.getUniqueId();
        String playerJob = getPlayerJob(player);
        Optional<TEJob> optPlayerJob = getJob(playerJob, true);
        if (optPlayerJob.isPresent()) {
            if (itemStack.get(FishData.class).isPresent()) {
                FishData fishData = itemStack.get(FishData.class).get();
                String fishName = fishData.type().get().getName();
                Optional<TEActionReward> reward = Optional.empty();
                List<String> sets = optPlayerJob.get().getSets();
                for (String s : sets) {
                    Optional<TEJobSet> optSet = getJobSet(s);
                    if (!optSet.isPresent()) {
                        logger.warn("[TE] Job " + getPlayerJob(player) + " has nonexistent set \"" + s + "\"");
                        continue;
                    }
                    reward = optSet.get().getRewardFor("catch", fishName);
                }
                if (reward.isPresent()) {
                    int expAmount = reward.get().getExpReward();
                    BigDecimal payAmount = reward.get().getMoneyReward();
                    boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean();
                    TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
                    if (notify) {
                        notifyPlayer(player, payAmount);
                    }
                    addExp(player, expAmount);
                    playerAccount.deposit(totalEconomy.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
                    checkForLevel(player);
                }
            }
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) TEAccount(com.erigitic.config.TEAccount) BigDecimal(java.math.BigDecimal) FishData(org.spongepowered.api.data.manipulator.mutable.item.FishData) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 2 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class ScrollOfSummation method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    ItemStack held = optHeldItem.get();
    if (held.getItem() != this) {
        return;
    }
    net.minecraft.item.ItemStack[] pInv = tf(player).inventory.mainInventory;
    Optional<ItemStack[]> optCompacted = new ItemCompactor(ImmutableList.of(CoalValueMap.inst(), IronValueMap.inst(), GoldValueMap.inst(), RedstoneValueMap.inst(), LapisValueMap.inst(), DiamondValueMap.inst(), EmeraldValueMap.inst(), CofferValueMap.inst())).execute((ItemStack[]) (Object[]) pInv);
    if (optCompacted.isPresent()) {
        Task.builder().execute(() -> {
            ItemStack[] nInv = optCompacted.get();
            for (int i = 0; i < pInv.length; ++i) {
                pInv[i] = tf(nInv[i]);
            }
            tf(player).inventoryContainer.detectAndSendChanges();
            tf(player).inventory.decrStackSize(tf(player).inventory.currentItem, 1);
            player.sendMessage(Text.of(TextColors.GOLD, "The scroll glows brightly before turning to dust..."));
        }).delayTicks(1).submit(SkreePlugin.inst());
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : ItemCompactor(com.skelril.nitro.item.ItemCompactor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 3 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class SkullOfTheFallen method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    if (this != optHeldItem.get().getItem()) {
        return;
    }
    Location<World> pLoc = player.getLocation();
    Optional<WorldService> optWorldService = Sponge.getServiceManager().provide(WorldService.class);
    if (optWorldService.isPresent()) {
        WorldService worldService = optWorldService.get();
        WildernessWorldWrapper wrapper = worldService.getEffectWrapper(WildernessWorldWrapper.class).get();
        Optional<Integer> optLevel = wrapper.getLevel(pLoc);
        if (optLevel.isPresent()) {
            int level = optLevel.get();
            DecimalFormat df = new DecimalFormat("#,###.##");
            player.sendMessages(Text.of(TextColors.YELLOW, "Wilderness level: " + level), Text.of(TextColors.YELLOW, "PvP Enabled: " + (wrapper.allowsPvP(level) ? "Yes" : "No")), Text.of(TextColors.YELLOW, "Mob damage: +" + df.format(wrapper.getDamageMod(level))), Text.of(TextColors.YELLOW, "Mob health: x" + df.format(wrapper.getHealthMod(level))), Text.of(TextColors.YELLOW, "Ore modifier: x" + df.format(wrapper.getOreMod(wrapper.getDropTier(level)))), Text.of(TextColors.YELLOW, "Drop modifier: x" + df.format(level * wrapper.getDropMod(wrapper.getDropTier(level)))));
        } else {
            player.sendMessage(Text.of(TextColors.RED, "You're not in a Wilderness world!"));
        }
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) WildernessWorldWrapper(com.skelril.skree.content.world.wilderness.WildernessWorldWrapper) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) World(org.spongepowered.api.world.World) WorldService(com.skelril.skree.service.WorldService) Listener(org.spongepowered.api.event.Listener)

Example 4 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class MagicBlockStateHelper method dropItems.

protected static void dropItems(Location<World> loc, Cause cause) {
    ItemStack ladder = ItemStackFactory.newItemStack((BlockType) CustomBlockTypes.MAGIC_LADDER);
    ItemStack platform = ItemStackFactory.newItemStack((BlockType) CustomBlockTypes.MAGIC_PLATFORM);
    Collection<ItemStack> drops = new ArrayList<>();
    drops.addAll(newItemStackCollection(ladder, foundLadder));
    drops.addAll(newItemStackCollection(platform, foundPlatform));
    new ItemDropper(loc).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
    resetCounts();
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ArrayList(java.util.ArrayList) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 5 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class RedFeather method getHighestPoweredFeather.

public Optional<Clause<Integer, Clause<ItemStack, Clause<Integer, Long>>>> getHighestPoweredFeather(EntityPlayer player) {
    net.minecraft.item.ItemStack[] itemStacks = player.inventory.mainInventory;
    int index = -1;
    ItemStack stack = null;
    Clause<Integer, Long> details = new Clause<>(0, 0L);
    for (int i = 0; i < itemStacks.length; ++i) {
        ItemStack curStack = tf(itemStacks[i]);
        Clause<Integer, Long> powerCooldown = getFeatherPower(curStack);
        if (powerCooldown.getValue() > System.currentTimeMillis()) {
            return Optional.empty();
        }
        if (powerCooldown.getKey() > details.getKey()) {
            index = i;
            details = powerCooldown;
            stack = curStack;
        }
    }
    return index != -1 ? Optional.of(new Clause<>(index, new Clause<>(stack, details))) : Optional.empty();
}
Also used : Clause(com.skelril.nitro.Clause) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

ItemStack (org.spongepowered.api.item.inventory.ItemStack)76 Player (org.spongepowered.api.entity.living.player.Player)30 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)29 Listener (org.spongepowered.api.event.Listener)17 ArrayList (java.util.ArrayList)12 Text (org.spongepowered.api.text.Text)10 ItemDropper (com.skelril.nitro.item.ItemDropper)9 MarketService (com.skelril.skree.service.MarketService)9 World (org.spongepowered.api.world.World)9 VirtualCrate (pw.codehusky.huskycrates.crate.VirtualCrate)9 BigDecimal (java.math.BigDecimal)8 Entity (org.spongepowered.api.entity.Entity)8 Vector3d (com.flowpowered.math.vector.Vector3d)5 Clause (com.skelril.nitro.Clause)5 InventoryTransactionResult (org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)5 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)4 Inventory (org.spongepowered.api.item.inventory.Inventory)4 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)3