Search in sources :

Example 21 with ItemType

use of org.spongepowered.api.item.ItemType in project Nucleus by NucleusPowered.

the class PowertoolListener method onUserInteract.

@Listener
@Exclude(InteractBlockEvent.class)
public void onUserInteract(final InteractEvent event, @Root Player player) {
    // No item in hand or no permission -> no powertool.
    if (!permissionRegistry.testBase(player) || !player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
        return;
    }
    // Get the item and the user.
    ItemType item = player.getItemInHand(HandTypes.MAIN_HAND).get().getType();
    PowertoolUserDataModule user;
    try {
        user = Nucleus.getNucleus().getUserDataManager().getUnchecked(player).get(PowertoolUserDataModule.class);
    } catch (Exception e) {
        Nucleus.getNucleus().printStackTraceIfDebugMode(e);
        return;
    }
    // If the powertools are toggled on.
    if (user.isPowertoolToggled()) {
        // Execute all powertools if they exist.
        user.getPowertoolForItem(item).ifPresent(x -> {
            // Cancel the interaction.
            event.setCancelled(true);
            final Player interacting;
            if (event instanceof InteractEntityEvent && ((InteractEntityEvent) event).getTargetEntity() instanceof Player) {
                interacting = (Player) ((InteractEntityEvent) event).getTargetEntity();
            } else {
                interacting = null;
            }
            // Run each command.
            if (interacting == null && x.stream().allMatch(i -> i.contains("{{subject}}"))) {
                player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("powertool.playeronly"));
                return;
            }
            x.forEach(s -> {
                if (s.contains("{{subject}}")) {
                    if (interacting != null) {
                        s = s.replace("{{subject}}", interacting.getName());
                    } else {
                        // Don't execute when no subject is in the way.
                        return;
                    }
                }
                Sponge.getCommandManager().process(player, s);
            });
        });
    }
}
Also used : CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) PowertoolCommand(io.github.nucleuspowered.nucleus.modules.powertool.commands.PowertoolCommand) Sponge(org.spongepowered.api.Sponge) PowertoolUserDataModule(io.github.nucleuspowered.nucleus.modules.powertool.datamodules.PowertoolUserDataModule) Root(org.spongepowered.api.event.filter.cause.Root) HandTypes(org.spongepowered.api.data.type.HandTypes) ListenerBase(io.github.nucleuspowered.nucleus.internal.ListenerBase) InteractEvent(org.spongepowered.api.event.action.InteractEvent) Player(org.spongepowered.api.entity.living.player.Player) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) Exclude(org.spongepowered.api.event.filter.type.Exclude) Listener(org.spongepowered.api.event.Listener) ItemType(org.spongepowered.api.item.ItemType) Player(org.spongepowered.api.entity.living.player.Player) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) ItemType(org.spongepowered.api.item.ItemType) PowertoolUserDataModule(io.github.nucleuspowered.nucleus.modules.powertool.datamodules.PowertoolUserDataModule) Listener(org.spongepowered.api.event.Listener) Exclude(org.spongepowered.api.event.filter.type.Exclude)

Example 22 with ItemType

use of org.spongepowered.api.item.ItemType in project Almura by AlmuraDev.

the class MixinBlockTallGrass method getDrops.

/**
 * @author Zidane - Chris Sanders
 * @reason Add in content seeds to drop list for Tall Grass
 */
@Overwrite(remap = false)
public void getDrops(final NonNullList<ItemStack> drops, final IBlockAccess access, final BlockPos pos, final IBlockState state, final int fortune) {
    World world;
    if (access instanceof ChunkCache) {
        world = ((ChunkCache) access).world;
    } else if (access instanceof World) {
        world = (World) access;
    } else {
        return;
    }
    final Random random = world.rand;
    // Roll 1 is Vanilla's 1/8 chance to drop a seed
    final int roll1 = random.nextInt(8);
    if (roll1 == 0) {
        // Forge Start - Lookup seed each time and then do random check. Almura handles its own chance code
        final ItemStack modSeed = net.minecraftforge.common.ForgeHooks.getGrassSeed(random, fortune);
        if (!modSeed.isEmpty()) {
            drops.add(modSeed);
            // Don't double up with Vanilla/mod drops
            return;
        }
        final Biome biome = world.getBiome(pos);
        // Roll 2 is shuffling Almura seeds and picking the first one after shuffling
        registry.getAllOf(ItemType.class).stream().filter(itemType -> itemType instanceof SeedItem && ((SeedItem) itemType).getGrass() != null).collect(Collectors.collectingAndThen(Collectors.toList(), collected -> {
            Collections.shuffle(collected);
            return collected.stream();
        })).findFirst().ifPresent((itemType) -> {
            final SeedItem seed = (SeedItem) itemType;
            final IntRange amountRange = seed.getGrass().getOrLoadAmountRequiredRangeForBiome(biome);
            if (amountRange != null) {
                final int stackSize = amountRange.random(random);
                final DoubleRange chanceRange = seed.getGrass().getOrLoadChanceRangeForBiome(biome);
                if (chanceRange != null) {
                    final double chance = chanceRange.random(random);
                    // Roll 3 is allowing the seed configuration to determine the chance for the drop
                    if (random.nextDouble() <= (chance / 100)) {
                        drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
                    }
                } else {
                    drops.add((ItemStack) (Object) org.spongepowered.api.item.inventory.ItemStack.of(itemType, stackSize));
                }
            }
        });
    }
// Almura End
}
Also used : ChunkCache(net.minecraft.world.ChunkCache) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Random(java.util.Random) Overwrite(org.spongepowered.asm.mixin.Overwrite) SeedItem(com.almuradev.content.type.item.type.seed.SeedItem) BlockTallGrass(net.minecraft.block.BlockTallGrass) Collectors(java.util.stream.Collectors) GameRegistry(org.spongepowered.api.GameRegistry) Inject(javax.inject.Inject) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) Mixin(org.spongepowered.asm.mixin.Mixin) MixinBlock(com.almuradev.content.type.block.mixin.impl.MixinBlock) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) NonNullList(net.minecraft.util.NonNullList) ItemType(org.spongepowered.api.item.ItemType) Collections(java.util.Collections) IntRange(com.almuradev.toolbox.util.math.IntRange) IBlockAccess(net.minecraft.world.IBlockAccess) Biome(net.minecraft.world.biome.Biome) ChunkCache(net.minecraft.world.ChunkCache) ItemType(org.spongepowered.api.item.ItemType) IntRange(com.almuradev.toolbox.util.math.IntRange) World(net.minecraft.world.World) SeedItem(com.almuradev.content.type.item.type.seed.SeedItem) DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Biome(net.minecraft.world.biome.Biome) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 23 with ItemType

use of org.spongepowered.api.item.ItemType in project SpongeCommon by SpongePowered.

the class SpongeItemStackSnapshotDataBuilder method buildContent.

@Override
protected Optional<ItemStackSnapshot> buildContent(DataView container) throws InvalidDataException {
    if (container.contains(Constants.ItemStack.TYPE, Constants.ItemStack.COUNT)) {
        final ItemType itemType = container.getRegistryValue(Constants.ItemStack.TYPE, RegistryTypes.ITEM_TYPE, Sponge.game()).get();
        if (itemType == ItemTypes.AIR.get()) {
            return Optional.of(ItemStackSnapshot.empty());
        }
        final int count = container.getInt(Constants.ItemStack.COUNT).get();
        @Nullable final CompoundTag compound;
        if (container.contains(Constants.Sponge.UNSAFE_NBT)) {
            compound = NBTTranslator.INSTANCE.translate(container.getView(Constants.Sponge.UNSAFE_NBT).get());
            SpongeItemStack.BuilderImpl.fixEnchantmentData(itemType, compound);
        } else {
            compound = null;
        }
        final ImmutableList<DataManipulator.Immutable> manipulators;
        if (container.contains(Constants.Sponge.DATA_MANIPULATORS)) {
            final List<DataView> views = container.getViewList(Constants.Sponge.DATA_MANIPULATORS).get();
            // TODO manipulators = DataUtil.deserializeImmutableManipulatorList(container.getViewList(Constants.Sponge.DATA_MANIPULATORS).get());
            manipulators = ImmutableList.of();
        } else {
            manipulators = ImmutableList.of();
        }
        return Optional.of(new SpongeItemStackSnapshot(itemType, count, manipulators, compound));
    }
    return Optional.empty();
}
Also used : SpongeItemStackSnapshot(org.spongepowered.common.item.SpongeItemStackSnapshot) DataView(org.spongepowered.api.data.persistence.DataView) ItemType(org.spongepowered.api.item.ItemType) Nullable(org.checkerframework.checker.nullness.qual.Nullable) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 24 with ItemType

use of org.spongepowered.api.item.ItemType in project SpongeCommon by SpongePowered.

the class ItemStackData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(ItemStack.class).create(Keys.APPLICABLE_POTION_EFFECTS).get(h -> {
        if (h.isEdible()) {
            final List<Pair<MobEffectInstance, Float>> itemEffects = h.getItem().getFoodProperties().getEffects();
            final WeightedTable<PotionEffect> effects = new WeightedTable<>();
            final ChanceTable<PotionEffect> chance = new ChanceTable<>();
            for (final Pair<MobEffectInstance, Float> effect : itemEffects) {
                chance.add((PotionEffect) effect.getFirst(), effect.getSecond());
            }
            effects.add(new NestedTableEntry<>(1, chance));
            return effects;
        }
        return null;
    }).create(Keys.BURN_TIME).get(h -> {
        final Integer burnTime = AbstractFurnaceBlockEntity.getFuel().get(h.getItem());
        if (burnTime != null && burnTime > 0) {
            return burnTime;
        }
        return null;
    }).create(Keys.CAN_HARVEST).get(h -> {
        final Item item = h.getItem();
        if (item instanceof DiggerItemAccessor && !(item instanceof PickaxeItem)) {
            final Set<Block> blocks = ((DiggerItemAccessor) item).accessor$blocks();
            return ImmutableSet.copyOf((Set<BlockType>) (Object) blocks);
        }
        final Set<BlockType> blockTypes = Registry.BLOCK.stream().filter(b -> item.isCorrectToolForDrops(b.defaultBlockState())).map(BlockType.class::cast).collect(ImmutableSet.toImmutableSet());
        return blockTypes.isEmpty() ? null : blockTypes;
    }).create(Keys.CONTAINER_ITEM).get(h -> (ItemType) h.getItem().getCraftingRemainingItem()).create(Keys.DISPLAY_NAME).get(h -> SpongeAdventure.asAdventure(h.getDisplayName())).create(Keys.CUSTOM_MODEL_DATA).get(h -> {
        final CompoundTag tag = h.getTag();
        if (tag == null || !tag.contains(Constants.Item.CUSTOM_MODEL_DATA, Constants.NBT.TAG_INT)) {
            return null;
        }
        return tag.getInt(Constants.Item.CUSTOM_MODEL_DATA);
    }).set((h, v) -> {
        final CompoundTag tag = h.getOrCreateTag();
        tag.putInt(Constants.Item.CUSTOM_MODEL_DATA, v);
    }).delete(h -> {
        final CompoundTag tag = h.getTag();
        if (tag != null) {
            tag.remove(Constants.Item.CUSTOM_MODEL_DATA);
        }
    }).create(Keys.CUSTOM_NAME).get(h -> {
        if (h.hasCustomHoverName()) {
            return SpongeAdventure.asAdventure(h.getHoverName());
        }
        if (h.getItem() == Items.WRITTEN_BOOK) {
            // When no custom name is set on a written book fallback to its title
            // The custom name has a higher priority than the title so no setter is needed.
            final CompoundTag tag = h.getTag();
            if (tag != null) {
                final String title = tag.getString(Constants.Item.Book.ITEM_BOOK_TITLE);
                return LegacyComponentSerializer.legacySection().deserialize(title);
            }
        }
        return null;
    }).set((h, v) -> h.setHoverName(SpongeAdventure.asVanilla(v))).delete(ItemStack::resetHoverName).create(Keys.IS_UNBREAKABLE).get(h -> {
        final CompoundTag tag = h.getTag();
        if (tag == null || !tag.contains(Constants.Item.ITEM_UNBREAKABLE, Constants.NBT.TAG_BYTE)) {
            return false;
        }
        return tag.getBoolean(Constants.Item.ITEM_UNBREAKABLE);
    }).set(ItemStackData::setIsUnbrekable).delete(h -> ItemStackData.setIsUnbrekable(h, false)).create(Keys.LORE).get(h -> {
        final CompoundTag tag = h.getTag();
        if (tag == null || !tag.contains(Constants.Item.ITEM_DISPLAY)) {
            return null;
        }
        final CompoundTag displayCompound = tag.getCompound(Constants.Item.ITEM_DISPLAY);
        final ListTag list = displayCompound.getList(Constants.Item.ITEM_LORE, Constants.NBT.TAG_STRING);
        return list.isEmpty() ? null : SpongeAdventure.json(list.stream().collect(NBTCollectors.toStringList()));
    }).set((h, v) -> {
        if (v.isEmpty()) {
            ItemStackData.deleteLore(h);
            return;
        }
        final ListTag list = SpongeAdventure.listTagJson(v);
        h.getOrCreateTagElement(Constants.Item.ITEM_DISPLAY).put(Constants.Item.ITEM_LORE, list);
    }).delete(ItemStackData::deleteLore).create(Keys.MAX_DURABILITY).get(h -> h.getItem().canBeDepleted() ? h.getItem().getMaxDamage() : null).supports(h -> h.getItem().canBeDepleted()).create(Keys.ITEM_DURABILITY).get(stack -> stack.getMaxDamage() - stack.getDamageValue()).set((stack, durability) -> stack.setDamageValue(stack.getMaxDamage() - durability)).supports(h -> h.getItem().canBeDepleted()).create(Keys.ITEM_RARITY).get(stack -> (ItemRarity) (Object) stack.getRarity()).create(Keys.REPLENISHED_FOOD).get(h -> {
        if (h.getItem().isEdible()) {
            final FoodProperties food = h.getItem().getFoodProperties();
            return food == null ? null : food.getNutrition();
        }
        return null;
    }).supports(h -> h.getItem().isEdible()).create(Keys.REPLENISHED_SATURATION).get(h -> {
        if (h.getItem().isEdible()) {
            final FoodProperties food = h.getItem().getFoodProperties();
            if (food != null) {
                // Translate's Minecraft's weird internal value to the actual saturation value
                return food.getSaturationModifier() * food.getNutrition() * 2.0;
            }
        }
        return null;
    }).supports(h -> h.getItem().isEdible());
}
Also used : Items(net.minecraft.world.item.Items) DiggerItemAccessor(org.spongepowered.common.accessor.world.item.DiggerItemAccessor) Constants(org.spongepowered.common.util.Constants) StringTag(net.minecraft.nbt.StringTag) Item(net.minecraft.world.item.Item) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) PickaxeItem(net.minecraft.world.item.PickaxeItem) NestedTableEntry(org.spongepowered.api.util.weighted.NestedTableEntry) Registry(net.minecraft.core.Registry) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) FoodProperties(net.minecraft.world.food.FoodProperties) ImmutableSet(com.google.common.collect.ImmutableSet) ChanceTable(org.spongepowered.api.util.weighted.ChanceTable) Set(java.util.Set) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) SpongeCommon(org.spongepowered.common.SpongeCommon) Pair(com.mojang.datafixers.util.Pair) AbstractFurnaceBlockEntity(net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity) Keys(org.spongepowered.api.data.Keys) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ItemRarity(org.spongepowered.api.item.ItemRarity) NBTCollectors(org.spongepowered.common.util.NBTCollectors) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) BlockType(org.spongepowered.api.block.BlockType) WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) Block(net.minecraft.world.level.block.Block) ItemStack(net.minecraft.world.item.ItemStack) ItemType(org.spongepowered.api.item.ItemType) ListTag(net.minecraft.nbt.ListTag) PickaxeItem(net.minecraft.world.item.PickaxeItem) DiggerItemAccessor(org.spongepowered.common.accessor.world.item.DiggerItemAccessor) WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ItemType(org.spongepowered.api.item.ItemType) Item(net.minecraft.world.item.Item) PickaxeItem(net.minecraft.world.item.PickaxeItem) ChanceTable(org.spongepowered.api.util.weighted.ChanceTable) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) Pair(com.mojang.datafixers.util.Pair) NestedTableEntry(org.spongepowered.api.util.weighted.NestedTableEntry) FoodProperties(net.minecraft.world.food.FoodProperties) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ListTag(net.minecraft.nbt.ListTag) BlockType(org.spongepowered.api.block.BlockType) ItemStack(net.minecraft.world.item.ItemStack)

Example 25 with ItemType

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

the class CursedMineInstance method ghost.

public void ghost(final Player player, BlockType blockID) {
    if (Probability.getChance(player.getLocation().getBlockY())) {
        if (Probability.getChance(2)) {
            switch(Probability.getRandom(6)) {
                case 1:
                    player.sendMessage(Text.of(TextColors.YELLOW, "Caspher the friendly ghost drops some bread."));
                    new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.BREAD, Probability.getRandom(16))));
                    break;
                case 2:
                    player.sendMessage(Text.of(TextColors.YELLOW, "COOKIE gives you a cookie."));
                    new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.COOKIE)));
                    break;
                case 3:
                    player.sendMessage(Text.of(TextColors.YELLOW, "Caspher the friendly ghost appears."));
                    List<ItemStack> caspherLoot = new ArrayList<>();
                    for (int i = 0; i < 8; i++) {
                        caspherLoot.add(newItemStack(ItemTypes.IRON_INGOT, Probability.getRandom(64)));
                        caspherLoot.add(newItemStack(ItemTypes.GOLD_INGOT, Probability.getRandom(64)));
                        caspherLoot.add(newItemStack(ItemTypes.DIAMOND, Probability.getRandom(64)));
                    }
                    new ItemDropper(player.getLocation()).dropStacks(caspherLoot);
                    break;
                case 4:
                    player.sendMessage(Text.of(TextColors.YELLOW, "John gives you a new jacket."));
                    new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.LEATHER_CHESTPLATE)));
                    break;
                case 5:
                    player.sendMessage(Text.of(TextColors.YELLOW, "Tim teleports items to you."));
                    getContained(Item.class).forEach(i -> i.setLocation(player.getLocation()));
                    // Add in some extra drops just in case the loot wasn't very juicy
                    List<ItemStack> teleportLootExtras = Lists.newArrayList(newItemStack(ItemTypes.IRON_INGOT, Probability.getRandom(64)), newItemStack(ItemTypes.GOLD_INGOT, Probability.getRandom(64)), newItemStack(ItemTypes.DIAMOND, Probability.getRandom(64)));
                    new ItemDropper(player.getLocation()).dropStacks(teleportLootExtras);
                    break;
                case 6:
                    player.sendMessage(Text.of(TextColors.YELLOW, "Dan gives you a sparkling touch."));
                    ItemType sparkingType;
                    switch(Probability.getRandom(3)) {
                        case 1:
                            sparkingType = ItemTypes.IRON_INGOT;
                            break;
                        case 2:
                            sparkingType = ItemTypes.GOLD_INGOT;
                            break;
                        case 3:
                            sparkingType = ItemTypes.DIAMOND;
                            break;
                        default:
                            sparkingType = ItemTypes.REDSTONE;
                            break;
                    }
                    TimedRunnable inventoryFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new InventoryCurse(sparkingType, 64).accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 10);
                    inventoryFX.setTask(Task.builder().execute(inventoryFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(inventoryFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                default:
                    break;
            }
        } else {
            switch(Probability.getRandom(11)) {
                case 1:
                    if (Probability.getChance(4)) {
                        if (blockID == BlockTypes.DIAMOND_ORE) {
                            hitList.addPlayer(player);
                            player.sendMessage(Text.of(TextColors.RED, "You ignite fumes in the air!"));
                            EditSession ess = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new WorldResolver(getRegion().getExtent()).getWorldEditWorld(), -1);
                            try {
                                Vector3d pos = player.getLocation().getPosition();
                                ess.fillXZ(new Vector(pos.getX(), pos.getY(), pos.getZ()), WorldEdit.getInstance().getBaseBlockFactory().getBaseBlock(BlockID.FIRE), 20, 20, true);
                            } catch (MaxChangedBlocksException ignored) {
                            }
                            for (int i = Probability.getRandom(24) + 20; i > 0; --i) {
                                final boolean untele = i == 11;
                                Task.builder().execute(() -> {
                                    if (untele) {
                                        recordSystem.revertByPlayer(player.getUniqueId());
                                        hitList.remPlayer(player);
                                    }
                                    if (!contains(player)) {
                                        return;
                                    }
                                    Vector3i pos = new PositionRandomizer(3).createPosition3i(player.getLocation().getPosition());
                                    player.getLocation().getExtent().triggerExplosion(Explosion.builder().radius(3).location(player.getLocation().setPosition(pos.toDouble().add(.5, .5, .5))).shouldDamageEntities(true).canCauseFire(true).build());
                                }).delayTicks(12 * i).submit(SkreePlugin.inst());
                            }
                        } else {
                            hitList.addPlayer(player);
                            // player.chat("Who's a good ghost?!?!");
                            Task.builder().execute(() -> {
                                // player.chat("Don't hurt me!!!");
                                Task.builder().execute(() -> {
                                    // player.chat("Nooooooooooo!!!");
                                    TimedRunnable cannonFX = new TimedRunnable<>(new IntegratedRunnable() {

                                        @Override
                                        public boolean run(int times) {
                                            new CannonCurse().accept(player);
                                            return true;
                                        }

                                        @Override
                                        public void end() {
                                        }
                                    }, 120);
                                    cannonFX.setTask(Task.builder().execute(cannonFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                                    activeTask.merge(player, Lists.newArrayList(cannonFX.getTask()), (a, b) -> {
                                        a.addAll(b);
                                        return a;
                                    });
                                }).delay(1, TimeUnit.SECONDS).submit(SkreePlugin.inst());
                            }).delay(1, TimeUnit.SECONDS).submit(SkreePlugin.inst());
                        }
                        break;
                    }
                case 2:
                    player.sendMessage(Text.of(TextColors.RED, "Dave attaches to your soul..."));
                    for (int i = 20; i > 0; --i) {
                        Task.builder().execute(() -> {
                            if (!contains(player)) {
                                return;
                            }
                            player.offer(Keys.HEALTH, Probability.getRandom(Probability.getRandom(player.get(Keys.MAX_HEALTH).get())) - 1);
                        }).delayTicks(12 * i).submit(SkreePlugin.inst());
                    }
                    break;
                case 3:
                    player.sendMessage(Text.of(TextColors.RED, "George plays with fire, sadly too close to you."));
                    TimedRunnable fireFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new FireCurse().accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 90);
                    fireFX.setTask(Task.builder().execute(fireFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(fireFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                case 4:
                    player.sendMessage(Text.of(TextColors.RED, "Simon says pick up sticks."));
                    List<ItemStack> sticks = new ArrayList<>();
                    for (int i = 0; i < player.getInventory().size() * 1.5; i++) {
                        sticks.add(newItemStack(ItemTypes.STICK, 64));
                    }
                    new ItemDropper(player.getLocation()).dropStacks(sticks);
                    break;
                case 5:
                    player.sendMessage(Text.of(TextColors.RED, "Ben dumps out your backpack."));
                    TimedRunnable butterFingerFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new ButterFingersCurse().accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 20);
                    butterFingerFX.setTask(Task.builder().execute(butterFingerFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(butterFingerFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                case 6:
                    player.sendMessage(Text.of(TextColors.RED, "Merlin attacks with a mighty rage!"));
                    TimedRunnable merlinFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new MerlinCurse().accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 40);
                    merlinFX.setTask(Task.builder().execute(merlinFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(merlinFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                case 7:
                    player.sendMessage(Text.of(TextColors.RED, "Dave tells everyone that your mining!"));
                    MessageChannel.TO_PLAYERS.send(Text.of(TextColors.GOLD, player.getName() + " is mining in the cursed mine!!!"));
                    break;
                case 8:
                    player.sendMessage(Text.of(TextColors.RED, "Dave likes your food."));
                    hitList.addPlayer(player);
                    TimedRunnable starvationFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new StarvationCurse().accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 40);
                    starvationFX.setTask(Task.builder().execute(starvationFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(starvationFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                case 9:
                    player.sendMessage(Text.of(TextColors.RED, "Hallow declares war on YOU!"));
                    for (int i = 0; i < Probability.getRangedRandom(10, 30); i++) {
                        Blaze blaze = (Blaze) getRegion().getExtent().createEntity(EntityTypes.BLAZE, player.getLocation().getPosition());
                        blaze.setTarget(player);
                        getRegion().getExtent().spawnEntity(blaze);
                    }
                    break;
                case 10:
                    player.sendMessage(Text.of(TextColors.RED, "A legion of hell hounds appears!"));
                    for (int i = 0; i < Probability.getRangedRandom(10, 30); i++) {
                        Wolf wolf = (Wolf) getRegion().getExtent().createEntity(EntityTypes.WOLF, player.getLocation().getPosition());
                        wolf.setTarget(player);
                        getRegion().getExtent().spawnEntity(wolf);
                    }
                    break;
                case 11:
                    if (blockID == BlockTypes.EMERALD_ORE) {
                        player.sendMessage(Text.of(TextColors.RED, "Dave got a chemistry set!"));
                        hitList.addPlayer(player);
                        TimedRunnable deadlyPotionFX = new TimedRunnable<>(new IntegratedRunnable() {

                            @Override
                            public boolean run(int times) {
                                new DeadlyPotionCurse().accept(player);
                                return true;
                            }

                            @Override
                            public void end() {
                            }
                        }, 2 * 60 * 30);
                        deadlyPotionFX.setTask(Task.builder().execute(deadlyPotionFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                        activeTask.merge(player, Lists.newArrayList(deadlyPotionFX.getTask()), (a, b) -> {
                            a.addAll(b);
                            return a;
                        });
                    } else {
                        player.sendMessage(Text.of(TextColors.RED, "Dave says hi, that's not good."));
                        hitList.addPlayer(player);
                        TimedRunnable attackOfDaveFX = new TimedRunnable<>(new IntegratedRunnable() {

                            @Override
                            public boolean run(int times) {
                                new AttackOfDaveCurse().accept(player);
                                return true;
                            }

                            @Override
                            public void end() {
                            }
                        }, 2 * 60 * 30);
                        attackOfDaveFX.setTask(Task.builder().execute(attackOfDaveFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                        activeTask.merge(player, Lists.newArrayList(attackOfDaveFX.getTask()), (a, b) -> {
                            a.addAll(b);
                            return a;
                        });
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : PositionRandomizer(com.skelril.nitro.position.PositionRandomizer) ItemDropper(com.skelril.nitro.item.ItemDropper) WorldResolver(com.skelril.skree.service.internal.zone.WorldResolver) ItemType(org.spongepowered.api.item.ItemType) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) Item(org.spongepowered.api.entity.Item) Wolf(org.spongepowered.api.entity.living.animal.Wolf) Vector(com.sk89q.worldedit.Vector) TimedRunnable(com.skelril.nitro.time.TimedRunnable) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) Vector3d(com.flowpowered.math.vector.Vector3d) Blaze(org.spongepowered.api.entity.living.monster.Blaze) Vector3i(com.flowpowered.math.vector.Vector3i) EditSession(com.sk89q.worldedit.EditSession) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Aggregations

ItemType (org.spongepowered.api.item.ItemType)53 ItemStack (org.spongepowered.api.item.inventory.ItemStack)19 BlockState (org.spongepowered.api.block.BlockState)12 Listener (org.spongepowered.api.event.Listener)12 World (org.spongepowered.api.world.World)11 Optional (java.util.Optional)9 Text (org.spongepowered.api.text.Text)8 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)7 ArrayList (java.util.ArrayList)7 Sponge (org.spongepowered.api.Sponge)7 BlockType (org.spongepowered.api.block.BlockType)7 List (java.util.List)6 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)6 Player (org.spongepowered.api.entity.living.player.Player)6 Vector3d (com.flowpowered.math.vector.Vector3d)5 CommandResult (org.spongepowered.api.command.CommandResult)5 Collectors (java.util.stream.Collectors)4 IBlockState (net.minecraft.block.state.IBlockState)4 Inventory (org.spongepowered.api.item.inventory.Inventory)4 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)4