Search in sources :

Example 31 with ItemStack

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

the class WaveDropInstruction method apply.

@Override
public Optional<Instruction<UnbindCondition, Boss<Zombie, CatacombsBossDetail>>> apply(UnbindCondition condition, Boss<Zombie, CatacombsBossDetail> boss) {
    int wave = boss.getDetail().getWave();
    Collection<ItemStack> drops = dropTable.getDrops(wave, wave * .5 * modifier);
    drops.addAll(foodDropTable.getDrops(1, .5 * modifier));
    Optional<Zombie> optEnt = boss.getTargetEntity();
    if (optEnt.isPresent()) {
        Task.builder().execute(() -> {
            new ItemDropper(optEnt.get().getLocation()).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
        }).delayTicks(1).submit(SkreePlugin.inst());
    }
    return Optional.empty();
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) Zombie(org.spongepowered.api.entity.living.monster.Zombie) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 32 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 33 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project HuskyCrates-Sponge by codeHusky.

the class VirtualCrate method getCrateItem.

/***
     * Retrieve the crate chest.
     * @since 0.10.2
     * @param quantity the quantity of chests you want.
     * @return the ItemStack with the chest.
     */
public ItemStack getCrateItem(int quantity) {
    ItemStack stacky = ItemStack.builder().itemType(crateBlockItemType).quantity(quantity).add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName)).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A placeable ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, " crate."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    stacky.offer(Keys.ITEM_LORE, itemLore);
    return ItemStack.builder().fromContainer(stacky.toContainer().set(DataQuery.of("UnsafeData", "crateID"), id)).build();
}
Also used : ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 34 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project HuskyCrates-Sponge by codeHusky.

the class CrateRewardHolderParser method fromConfig.

public static CrateRewardHolder fromConfig(ConfigurationNode holderNode, VirtualCrate vc) {
    ItemStack dispItem = itemFromNode(holderNode);
    CrateReward reward = new CrateReward(null, "CODE ERROR, CONTACT DEVELOPER", false);
    boolean dispAwardSimilar = false;
    String name;
    boolean single = false;
    SharedLangData langData = HuskyCrates.instance.langData;
    if (!holderNode.getNode("huskydata", "lang").isVirtual()) {
        langData = new SharedLangData(vc.langData, holderNode.getNode("huskydata", "lang"));
    }
    //System.out.println(dispItem.get(Keys.DISPLAY_NAME));
    if (holderNode.getNode("huskydata", "reward").getNode("overrideRewardName").isVirtual()) {
        //System.out.println("Virtual");
        if (dispItem.get(Keys.DISPLAY_NAME).isPresent()) {
            name = dispItem.get(Keys.DISPLAY_NAME).get().toPlain();
        } else {
            name = dispItem.getItem().getName();
        }
    } else {
        //System.out.println("Real");
        name = holderNode.getNode("huskydata", "reward").getNode("overrideRewardName").getString("strings, please.");
    }
    if (!holderNode.getNode("huskydata", "reward").getNode("treatAsSingle").isVirtual()) {
        single = holderNode.getNode("huskydata", "reward").getNode("treatAsSingle").getBoolean();
    }
    if (holderNode.getNode("huskydata", "reward", "type").getString().equalsIgnoreCase("item")) {
        ItemStack rewardItem;
        if (holderNode.getNode("huskydata", "reward").getNode("overrideItem").isVirtual()) {
            ItemStack rr = dispItem.copy();
            if (!holderNode.getNode("huskydata", "reward").getNode("overrideCount").isVirtual()) {
                rr.setQuantity(holderNode.getNode("huskydata", "reward").getNode("overrideCount").getInt());
            }
            reward = new CrateReward(rr, name, single);
            dispAwardSimilar = true;
        } else {
            reward = new CrateReward(itemFromNode(holderNode.getNode("huskydata", "reward", "overrideItem")), name, single);
        }
    } else if (holderNode.getNode("huskydata", "reward", "type").getString().equalsIgnoreCase("command")) {
        reward = new CrateReward(holderNode.getNode("huskydata", "reward", "command").getString("/say You didn't set a command or something..."), name, single);
    } else {
        System.out.println("?! Invalid Reward Type !? " + holderNode.getNode("huskydata", "reward", "type").getString());
    }
    return new CrateRewardHolder(dispItem, reward, holderNode.getNode("huskydata", "weight").getDouble(1), dispAwardSimilar, langData);
}
Also used : SharedLangData(pw.codehusky.huskycrates.lang.SharedLangData) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 35 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project HuskyCrates-Sponge by codeHusky.

the class NullCrateView method getInventory.

@Override
public Inventory getInventory() {
    Inventory woop = Inventory.builder().property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9, 1)).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(TextColors.DARK_RED, "INVALID CRATE TYPE!"))).listener(ClickInventoryEvent.class, evt -> evt.setCancelled(true)).build(plugin);
    woop.offer(ItemStack.of(ItemTypes.BARRIER, 256 * 2 + 64));
    for (Inventory e : woop.slots()) {
        ItemStack b = e.peek().get();
        b.setQuantity(1);
        e.set(b);
    }
    return woop;
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) VirtualCrate(pw.codehusky.huskycrates.crate.VirtualCrate) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) HuskyCrates(pw.codehusky.huskycrates.HuskyCrates) ItemTypes(org.spongepowered.api.item.ItemTypes) InventoryDimension(org.spongepowered.api.item.inventory.property.InventoryDimension) Player(org.spongepowered.api.entity.living.player.Player) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) TextColors(org.spongepowered.api.text.format.TextColors) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

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