Search in sources :

Example 1 with ItemStackSnapshot

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

the class CursedMineListener method onItemDrop.

@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause, @Named(NamedCause.NOTIFIER) Player player) {
    if (!Probability.getChance(4)) {
        return;
    }
    BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
    Optional<Location<World>> optLocation = blockSnapshot.getLocation();
    if (!optLocation.isPresent()) {
        return;
    }
    Location<World> loc = optLocation.get();
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(loc);
    if (!optInst.isPresent()) {
        return;
    }
    CursedMineInstance inst = optInst.get();
    if (!inst.hasrecordForPlayerAt(player, loc)) {
        return;
    }
    List<ItemStackSnapshot> itemStacks = new ArrayList<>();
    Iterator<Entity> entityIterator = event.getEntities().iterator();
    while (entityIterator.hasNext()) {
        Entity entity = entityIterator.next();
        if (entity instanceof Item) {
            ItemStackSnapshot snapshot = ((Item) entity).item().get();
            itemStacks.add(snapshot);
            entityIterator.remove();
        }
    }
    int times = 1;
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (optService.isPresent()) {
        ModifierService service = optService.get();
        if (service.isActive(Modifiers.DOUBLE_CURSED_ORES)) {
            times *= 2;
        }
    }
    for (ItemStackSnapshot stackSnapshot : itemStacks) {
        int quantity = Math.min(stackSnapshot.getCount() * Probability.getRangedRandom(4, 8), stackSnapshot.getType().getMaxStackQuantity());
        for (int i = 0; i < times; ++i) {
            ItemStack stack = stackSnapshot.createStack();
            stack.setQuantity(quantity);
            player.getInventory().offer(stack);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) Item(org.spongepowered.api.entity.Item) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 2 with ItemStackSnapshot

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

the class MarketImplUtil method giveItems.

public static Clause<Boolean, List<Clause<ItemStack, Integer>>> giveItems(Player player, Collection<ItemStack> stacks, Cause cause) {
    List<Clause<ItemStack, Integer>> transactions = new ArrayList<>(stacks.size());
    List<ItemStackSnapshot> itemBuffer = new ArrayList<>();
    itemBuffer.addAll(stacks.stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));
    PlayerInventory playerInventory = player.getInventory().query(PlayerInventory.class);
    List<Inventory> inventories = new ArrayList<>();
    inventories.add(playerInventory.getHotbar());
    inventories.add(playerInventory.getMain());
    // Loop through replacing empty space with the requested items
    for (Inventory inventory : inventories) {
        List<ItemStackSnapshot> newBuffer = new ArrayList<>();
        for (ItemStackSnapshot snapshot : itemBuffer) {
            ItemStack stack = snapshot.createStack();
            InventoryTransactionResult result = inventory.offer(stack);
            newBuffer.addAll(result.getRejectedItems());
            transactions.add(new Clause<>(stack, stack.getQuantity()));
        }
        itemBuffer = newBuffer;
    }
    // Drop remaining items
    new ItemDropper(player.getLocation()).dropStackSnapshots(itemBuffer, SpawnTypes.PLUGIN);
    return new Clause<>(true, transactions);
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Clause(com.skelril.nitro.Clause) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) InventoryTransactionResult(org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)

Example 3 with ItemStackSnapshot

use of org.spongepowered.api.item.inventory.ItemStackSnapshot 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 4 with ItemStackSnapshot

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

the class WildernessWorldWrapper method onItemDrop.

@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
    BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
    Optional<Location<World>> optLocation = blockSnapshot.getLocation();
    if (!optLocation.isPresent()) {
        return;
    }
    Location<World> loc = optLocation.get();
    if (!markedOrePoints.remove(loc)) {
        return;
    }
    Optional<Integer> optLevel = getLevel(loc);
    if (!optLevel.isPresent()) {
        return;
    }
    List<ItemStackSnapshot> itemStacks = new ArrayList<>();
    event.getEntities().forEach((entity -> {
        if (entity instanceof Item) {
            ItemStackSnapshot snapshot = ((Item) entity).item().get();
            itemStacks.add(getPoolItemDrop(snapshot));
        }
    }));
    addPool(loc, () -> itemStacks);
}
Also used : WorldService(com.skelril.skree.service.WorldService) StormBringer(com.skelril.skree.content.world.wilderness.wanderer.StormBringer) Value(org.spongepowered.api.data.value.mutable.Value) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) ModifierService(com.skelril.skree.service.ModifierService) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SkreePlugin(com.skelril.skree.SkreePlugin) TextColor(org.spongepowered.api.text.format.TextColor) org.spongepowered.api.entity(org.spongepowered.api.entity) TypeCollections.ore(com.skelril.skree.content.registry.TypeCollections.ore) Living(org.spongepowered.api.entity.living.Living) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) ItemDropper(com.skelril.nitro.item.ItemDropper) Location(org.spongepowered.api.world.Location) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Extent(org.spongepowered.api.world.extent.Extent) BlockTypes(org.spongepowered.api.block.BlockTypes) CustomItemTypes(com.skelril.skree.content.registry.item.CustomItemTypes) BlockState(org.spongepowered.api.block.BlockState) HealthData(org.spongepowered.api.data.manipulator.mutable.entity.HealthData) Egg(org.spongepowered.api.entity.projectile.Egg) Cancellable(org.spongepowered.api.event.Cancellable) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) World(org.spongepowered.api.world.World) HandTypes(org.spongepowered.api.data.type.HandTypes) NamedCause(org.spongepowered.api.event.cause.NamedCause) Player(org.spongepowered.api.entity.living.player.Player) RespawnPlayerEvent(org.spongepowered.api.event.entity.living.humanoid.player.RespawnPlayerEvent) EntityHealthPrinter(com.skelril.nitro.entity.EntityHealthPrinter) PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) java.util(java.util) DestructEntityEvent(org.spongepowered.api.event.entity.DestructEntityEvent) Vector3d(com.flowpowered.math.vector.Vector3d) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) Supplier(java.util.function.Supplier) GraveDigger(com.skelril.skree.content.world.wilderness.wanderer.GraveDigger) Lists(com.google.common.collect.Lists) MathExt(com.skelril.nitro.numeric.MathExt) Text(org.spongepowered.api.text.Text) DropTableEntryImpl(com.skelril.nitro.droptable.DropTableEntryImpl) TextColors(org.spongepowered.api.text.format.TextColors) DimensionTypes(org.spongepowered.api.world.DimensionTypes) Nullable(javax.annotation.Nullable) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Enchantments(org.spongepowered.api.item.Enchantments) DropTable(com.skelril.nitro.droptable.DropTable) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) Validate(org.apache.commons.lang3.Validate) MasterDropTable(com.skelril.nitro.droptable.MasterDropTable) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) QuantityBoundedItemStackConfig(com.skelril.nitro.registry.dynamic.QuantityBoundedItemStackConfig) CombinedText(com.skelril.nitro.text.CombinedText) Wither(org.spongepowered.api.entity.living.monster.Wither) SimpleDropResolver(com.skelril.nitro.droptable.resolver.SimpleDropResolver) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) EnchantmentUtil(com.skelril.nitro.data.util.EnchantmentUtil) TimedRunnable(com.skelril.nitro.time.TimedRunnable) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) Fangz(com.skelril.skree.content.world.wilderness.wanderer.Fangz) ParticleTypes(org.spongepowered.api.effect.particle.ParticleTypes) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Title(org.spongepowered.api.text.title.Title) CollideEntityEvent(org.spongepowered.api.event.entity.CollideEntityEvent) Transaction(org.spongepowered.api.data.Transaction) BlockSpawnCause(org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause) TextStyles(org.spongepowered.api.text.format.TextStyles) Sponge(org.spongepowered.api.Sponge) Tuple(org.spongepowered.api.util.Tuple) PvPService(com.skelril.skree.service.PvPService) Cause(org.spongepowered.api.event.cause.Cause) Explosion(org.spongepowered.api.world.explosion.Explosion) Named(org.spongepowered.api.event.filter.cause.Named) BlockType(org.spongepowered.api.block.BlockType) First(org.spongepowered.api.event.filter.cause.First) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) Keys(org.spongepowered.api.data.key.Keys) MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) WanderingBoss(com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss) WorldEffectWrapperImpl(com.skelril.skree.service.internal.world.WorldEffectWrapperImpl) GRAVE_STONE(com.skelril.skree.content.registry.block.CustomBlockTypes.GRAVE_STONE) CofferResolver(com.skelril.skree.content.droptable.CofferResolver) Function(java.util.function.Function) SlipperySingleHitDiceRoller(com.skelril.nitro.droptable.roller.SlipperySingleHitDiceRoller) Boss(org.spongepowered.api.entity.living.monster.Boss) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) BlockChangeFlag(org.spongepowered.api.world.BlockChangeFlag) Task(org.spongepowered.api.scheduler.Task) Probability(com.skelril.nitro.probability.Probability) Fireball(org.spongepowered.api.entity.projectile.explosive.fireball.Fireball) PlaceHolderText(com.skelril.nitro.text.PlaceHolderText) Creeper(org.spongepowered.api.entity.living.monster.Creeper) ItemStackConfig(com.skelril.nitro.registry.dynamic.ItemStackConfig) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Modifiers(com.skelril.skree.content.modifier.Modifiers) Monster(org.spongepowered.api.entity.living.monster.Monster) TimeUnit(java.util.concurrent.TimeUnit) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) DropTableImpl(com.skelril.nitro.droptable.DropTableImpl) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Projectile(org.spongepowered.api.entity.projectile.Projectile) Listener(org.spongepowered.api.event.Listener) ItemType(org.spongepowered.api.item.ItemType) SECONDS(java.util.concurrent.TimeUnit.SECONDS) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 5 with ItemStackSnapshot

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

the class CursedMineInstance method sweepFloor.

public void sweepFloor() {
    for (Item item : getContained(Item.class)) {
        if (!contains(item))
            continue;
        ItemType id = item.getItemType();
        for (ItemType aItem : items) {
            if (aItem == id) {
                ItemStackSnapshot snapshot = item.get(Keys.REPRESENTED_ITEM).get();
                int newAmt = (int) (snapshot.getCount() * .8);
                if (newAmt < 1) {
                    item.remove();
                } else {
                    ItemStack newStack = snapshot.createStack();
                    newStack.setQuantity(newAmt);
                    item.offer(Keys.REPRESENTED_ITEM, newStack.createSnapshot());
                }
                break;
            }
        }
    }
}
Also used : Item(org.spongepowered.api.entity.Item) ItemType(org.spongepowered.api.item.ItemType) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Aggregations

ItemStack (org.spongepowered.api.item.inventory.ItemStack)5 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)5 ItemDropper (com.skelril.nitro.item.ItemDropper)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)2 ModifierService (com.skelril.skree.service.ModifierService)2 Listener (org.spongepowered.api.event.Listener)2 ItemType (org.spongepowered.api.item.ItemType)2 TEAccount (com.erigitic.config.TEAccount)1 Vector3d (com.flowpowered.math.vector.Vector3d)1 Lists (com.google.common.collect.Lists)1 Clause (com.skelril.nitro.Clause)1 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)1 EnchantmentUtil (com.skelril.nitro.data.util.EnchantmentUtil)1 DropTable (com.skelril.nitro.droptable.DropTable)1 DropTableEntryImpl (com.skelril.nitro.droptable.DropTableEntryImpl)1 DropTableImpl (com.skelril.nitro.droptable.DropTableImpl)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 SimpleDropResolver (com.skelril.nitro.droptable.resolver.SimpleDropResolver)1 SlipperySingleHitDiceRoller (com.skelril.nitro.droptable.roller.SlipperySingleHitDiceRoller)1 EntityHealthPrinter (com.skelril.nitro.entity.EntityHealthPrinter)1