Search in sources :

Example 41 with ItemStack

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

the class Key method execute.

@Override
public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if (commandContext.getOne("type").isPresent()) {
        String type = commandContext.<String>getOne("type").get();
        Optional<Player> player = commandContext.getOne("player");
        VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
        int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
        if (virtualCrate == null) {
            commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
            return CommandResult.empty();
        }
        if (!player.isPresent()) {
            commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
            return CommandResult.empty();
        }
        ItemStack keyItemStack = virtualCrate.getCrateKey(quantity);
        InventoryTransactionResult.Type mainInventory = player.get().getInventory().offer(keyItemStack.copy()).getType();
        if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
            InventoryTransactionResult.Type enderInventory = player.get().getEnderChestInventory().offer(keyItemStack.copy()).getType();
            if (!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
                commandSource.sendMessage(Text.of("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest"));
                HuskyCrates.instance.logger.info("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest");
            } else {
                if (player.isPresent()) {
                    player.get().sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
                } else {
                    commandSource.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
                }
            }
        }
    } else {
        commandSource.sendMessage(Text.of("Usage: /crate key <id> [player] [count]"));
    }
    return CommandResult.success();
}
Also used : VirtualCrate(pw.codehusky.huskycrates.crate.VirtualCrate) Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) InventoryTransactionResult(org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)

Example 42 with ItemStack

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

the class CatacombsListener method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<CatacombsInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    CatacombsInstance inst = optInst.get();
    if (inst.hasUsedPhantomClock()) {
        return;
    }
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    ItemStack held = optHeldItem.get();
    if (held.getItem() != CustomItemTypes.PHANTOM_CLOCK) {
        return;
    }
    Task.builder().execute(() -> {
        tf(player).inventory.decrStackSize(tf(player).inventory.currentItem, 1);
        inst.setUsedPhantomClock(true);
        inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.GOLD, "A Phantom Clock has been used to increase wave speed!"));
    }).delayTicks(1).submit(SkreePlugin.inst());
    event.setUseBlockResult(Tristate.FALSE);
}
Also used : ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 43 with ItemStack

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

the class TheForgeInstance method getProduce.

private List<ItemStack> getProduce() {
    Map<ItemStack, Integer> results = state.getResults();
    int quantityToProduce = getQuantityToProduce();
    List<ItemStack> produce = new ArrayList<>();
    while (!results.isEmpty() && quantityToProduce > 0) {
        ItemStack stackToMake = Probability.pickOneOf(results.keySet());
        int supply = results.get(stackToMake);
        if (supply >= quantityToProduce) {
            results.put(stackToMake, supply - quantityToProduce);
            for (int i = 0; i < quantityToProduce; ++i) {
                produce.add(newItemStack(stackToMake));
            }
            quantityToProduce = 0;
        } else {
            results.remove(stackToMake);
            for (int i = 0; i < supply; ++i) {
                produce.add(newItemStack(stackToMake));
            }
            quantityToProduce = quantityToProduce - supply;
        }
    }
    return produce;
}
Also used : ArrayList(java.util.ArrayList) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 44 with ItemStack

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

the class InventoryCurse method accept.

@Override
public void accept(Player player) {
    ItemStack stack = newItemStack(targetType, Probability.getRandom(targetAmt));
    Optional<ItemStack> optHeld = player.getItemInHand(HandTypes.MAIN_HAND);
    if (optHeld.isPresent() && !isSimilar(optHeld.get(), stack)) {
        new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(optHeld.get()), SpawnTypes.DROPPED_ITEM);
    }
    player.setItemInHand(HandTypes.MAIN_HAND, stack);
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 45 with ItemStack

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

the class TempleOfFateInstance method rewardPlayer.

public void rewardPlayer(Player player) {
    boolean participated = participants.contains(player);
    remove(player);
    if (!participated) {
        return;
    }
    for (ItemStack stack : dropTable.getDrops(1)) {
        player.getInventory().offer(stack);
    }
}
Also used : ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

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