Search in sources :

Example 1 with ParticleEffect

use of org.spongepowered.api.effect.particle.ParticleEffect in project Skree by Skelril.

the class WildernessWorldWrapper method onBlockPlace.

@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        Optional<Location<World>> optLoc = block.getFinal().getLocation();
        if (!optLoc.isPresent() || !isApplicable(optLoc.get())) {
            continue;
        }
        Location<World> loc = optLoc.get();
        BlockState finalState = block.getFinal().getState();
        if (config.getDropAmplificationConfig().amplifies(finalState)) {
            // Allow creative mode players to still place blocks
            if (player.getGameModeData().type().get().equals(GameModes.CREATIVE)) {
                continue;
            }
            BlockType originalType = block.getOriginal().getState().getType();
            if (ore().contains(originalType)) {
                continue;
            }
            try {
                Vector3d origin = loc.getPosition();
                World world = loc.getExtent();
                for (int i = 0; i < 40; ++i) {
                    ParticleEffect effect = ParticleEffect.builder().type(ParticleTypes.MAGIC_CRITICAL_HIT).velocity(new Vector3d(Probability.getRangedRandom(-1, 1), Probability.getRangedRandom(-.7, .7), Probability.getRangedRandom(-1, 1))).quantity(1).build();
                    world.spawnParticles(effect, origin.add(.5, .5, .5));
                }
            } catch (Exception ex) {
                player.sendMessage(/* ChatTypes.SYSTEM, */
                Text.of(TextColors.RED, "You find yourself unable to place that block."));
            }
            block.setValid(false);
        }
    }
}
Also used : ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 2 with ParticleEffect

use of org.spongepowered.api.effect.particle.ParticleEffect in project Skree by Skelril.

the class PatientXInstance method runAttack.

public void runAttack(PatientXAttack attackCase) {
    Optional<Zombie> optBoss = getBoss();
    if (!optBoss.isPresent()) {
        return;
    }
    Zombie boss = optBoss.get();
    Collection<Player> contained = getPlayers(PARTICIPANT);
    if (contained.isEmpty()) {
        return;
    }
    switch(attackCase) {
        case MUSICAL_CHAIRS:
            sendAttackBroadcast("Let's play musical chairs!", AttackSeverity.NORMAL);
            for (Player player : contained) {
                do {
                    player.setLocation(getRandomDest());
                } while (player.getLocation().getPosition().distanceSquared(boss.getLocation().getPosition()) <= 5 * 5);
                // TODO convert to Sponge
                if (((EntityZombie) boss).canEntityBeSeen(tf(player))) {
                    player.offer(Keys.HEALTH, Probability.getRandom(player.get(Keys.MAX_HEALTH).get()));
                    sendAttackBroadcast("Don't worry, I have a medical degree...", AttackSeverity.NORMAL);
                    sendAttackBroadcast("...or was that a certificate of insanity?", AttackSeverity.NORMAL);
                }
            }
            attackDur = System.currentTimeMillis() + 2000;
            break;
        case SMASHING_HIT:
            for (Player player : contained) {
                final double old = player.get(Keys.HEALTH).get();
                player.offer(Keys.HEALTH, 3D);
                Task.builder().execute(() -> {
                    if (!player.isRemoved() || !contains(player))
                        return;
                    player.offer(Keys.HEALTH, old * .75);
                }).delay(2, TimeUnit.SECONDS).submit(SkreePlugin.inst());
            }
            attackDur = System.currentTimeMillis() + 3000;
            sendAttackBroadcast("This special attack will be a \"smashing hit\"!", AttackSeverity.NORMAL);
            break;
        case BOMB_PERFORMANCE:
            double tntQuantity = Math.max(2, difficulty / 2.4);
            for (Player player : contained) {
                for (double i = Probability.getRangedRandom(tntQuantity, Math.pow(2, Math.min(9, tntQuantity))); i > 0; i--) {
                    PrimedTNT explosive = (PrimedTNT) getRegion().getExtent().createEntity(EntityTypes.PRIMED_TNT, player.getLocation().getPosition());
                    explosive.setVelocity(new Vector3d(random.nextDouble() * 1 - .5, random.nextDouble() * .8 + .2, random.nextDouble() * 1 - .5));
                    explosive.offer(Keys.FUSE_DURATION, 20 * 4);
                    getRegion().getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                }
            }
            attackDur = System.currentTimeMillis() + 5000;
            sendAttackBroadcast("Your performance is really going to \"bomb\"!", AttackSeverity.NORMAL);
            break;
        case WITHER_AWAY:
            PotionEffect witherEffect = PotionEffect.of(PotionEffectTypes.WITHER, 1, 20 * 15);
            for (Player player : contained) {
                List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
                potionEffects.add(witherEffect);
                player.offer(Keys.POTION_EFFECTS, potionEffects);
            }
            attackDur = System.currentTimeMillis() + 15750;
            sendAttackBroadcast("Like a candle I hope you don't \"whither\" and die!", AttackSeverity.NORMAL);
            break;
        case SPLASH_TO_IT:
            for (Player player : contained) {
                for (int i = Probability.getRandom(6) + 2; i > 0; --i) {
                    throwSlashPotion(player.getLocation());
                }
            }
            attackDur = System.currentTimeMillis() + 2000;
            sendAttackBroadcast("Splash to it!", AttackSeverity.NORMAL);
            break;
        case COLD_FEET:
            PotionEffect slowEffect = PotionEffect.of(PotionEffectTypes.SLOWNESS, 2, 20 * 60);
            for (Player player : contained) {
                List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
                potionEffects.add(slowEffect);
                player.offer(Keys.POTION_EFFECTS, potionEffects);
            }
            attackDur = System.currentTimeMillis() + 20000;
            sendAttackBroadcast("What's the matter, got cold feet?", AttackSeverity.NORMAL);
            break;
        case IM_JUST_BATTY:
            for (Player player : contained) {
                Cause cause = Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build();
                player.simulateChat(Text.of("I love Patient X!"), cause);
                Entity bat = getRegion().getExtent().createEntity(EntityTypes.BAT, player.getLocation().getPosition());
                getRegion().getExtent().spawnEntity(bat, cause);
                bat.getPassengers().add(player);
            }
            attackDur = System.currentTimeMillis() + 20000;
            sendAttackBroadcast("Awe, I love you too!", AttackSeverity.NORMAL);
            sendAttackBroadcast("But only cause I'm a little batty...", AttackSeverity.NORMAL);
            break;
        case RADIATION:
            ParticleEffect radiationEffect = ParticleEffect.builder().type(ParticleTypes.FLAME).quantity(1).build();
            Task.builder().execute(() -> {
                for (int i = config.radiationTimes; i > 0; i--) {
                    Task.builder().execute(() -> {
                        if (isBossSpawned()) {
                            for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
                                for (int e = 0; e < 30; ++e) {
                                    getRegion().getExtent().spawnParticles(radiationEffect, player.getLocation().getPosition().add(5 - Probability.getRandom(10) + Probability.getRangedRandom(0, 1.0), 5 - Probability.getRandom(10) + Probability.getRangedRandom(0, 1.0), 5 - Probability.getRandom(10) + Probability.getRangedRandom(0, 1.0)));
                                }
                                if (LightLevelUtil.getMaxLightLevel(player.getLocation()).get() >= config.radiationLightLevel) {
                                    player.damage(difficulty * config.radiationMultiplier, EntityDamageSource.builder().entity(boss).type(DamageTypes.MAGIC).build());
                                }
                            }
                        }
                    }).delay(i * 500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst());
                }
            }).delay(3, TimeUnit.SECONDS).submit(SkreePlugin.inst());
            attackDur = System.currentTimeMillis() + (config.radiationTimes * 500);
            sendAttackBroadcast("Ahhh not the radiation treatment!", AttackSeverity.NORMAL);
            break;
        case SNOWBALL_FIGHT:
            final int burst = Probability.getRangedRandom(10, 20);
            Task.builder().execute(() -> {
                for (int i = burst; i > 0; i--) {
                    Task.builder().execute(() -> {
                        if (boss != null)
                            freezeBlocks(true);
                    }).delay(i * 500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst());
                }
            }).delay(7, TimeUnit.SECONDS).submit(SkreePlugin.inst());
            attackDur = System.currentTimeMillis() + 7000 + (500 * burst);
            sendAttackBroadcast("Let's have a snow ball fight!", AttackSeverity.NORMAL);
            break;
    }
    lastAttack = attackCase;
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) EntityZombie(net.minecraft.entity.monster.EntityZombie) Zombie(org.spongepowered.api.entity.living.monster.Zombie) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) EntityZombie(net.minecraft.entity.monster.EntityZombie) Vector3d(com.flowpowered.math.vector.Vector3d) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) Cause(org.spongepowered.api.event.cause.Cause)

Example 3 with ParticleEffect

use of org.spongepowered.api.effect.particle.ParticleEffect in project Skree by Skelril.

the class SkyWarsListener method onInteract.

@Listener
public void onInteract(InteractBlockEvent event, @First Player player) {
    Optional<SkyWarsInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    SkyWarsInstance inst = optInst.get();
    if (inst.getState() != SkyWarsState.IN_PROGRESS) {
        return;
    }
    Optional<SkyWarsPlayerData> optPlayerData = inst.getPlayerData(player);
    if (!optPlayerData.isPresent()) {
        return;
    }
    SkyWarsPlayerData playerData = optPlayerData.get();
    Optional<ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optStack.isPresent()) {
        return;
    }
    ItemStack stack = optStack.get();
    if (stack.getItem() == CustomItemTypes.SKY_FEATHER) {
        Vector3d vel = EntityDirectionUtil.getFacingVector(player);
        Optional<SkyFeather.Data> optData = SkyFeather.getDataFor(stack);
        if (!optData.isPresent()) {
            return;
        }
        SkyFeather.Data data = optData.get();
        double radius = data.radius;
        double flight = data.flight;
        double pushBack = data.pushBack;
        if (event instanceof InteractBlockEvent.Primary.MainHand) {
            if (!playerData.canFly())
                return;
            vel = vel.mul(flight);
            player.setVelocity(vel);
            playerData.stopFlight(250);
        } else if (event instanceof InteractBlockEvent.Secondary.MainHand) {
            if (!playerData.canPushBack())
                return;
            vel = vel.mul(pushBack * 2);
            SpongePlayer spongePlayer = SpongeWorldEdit.inst().wrapPlayer(player);
            Collection<Entity> possibleTargets = inst.getContained(Player.class, Chicken.class);
            possibleTargets.remove(player);
            ParticleEffect radiationEffect = ParticleEffect.builder().type(ParticleTypes.FLAME).quantity(1).build();
            TargetBlock targetBlock = new TargetBlock(spongePlayer, 50, .2);
            while (targetBlock.getNextBlock() != null) {
                BlockWorldVector weBlock = targetBlock.getCurrentBlock();
                Location<World> loc = new Location<>(inst.getRegion().getExtent(), weBlock.getX(), weBlock.getY(), weBlock.getZ());
                for (int i = 0; i < 10; ++i) {
                    inst.getRegion().getExtent().spawnParticles(radiationEffect, loc.getPosition().add(Probability.getRangedRandom(0, 1.0), Probability.getRangedRandom(0, 1.0), Probability.getRangedRandom(0, 1.0)));
                }
                for (Entity aEntity : possibleTargets) {
                    if (aEntity.getLocation().getPosition().distanceSquared(loc.getPosition()) <= Math.pow(radius, 2)) {
                        if (aEntity instanceof Player) {
                            Player aPlayer = (Player) aEntity;
                            if (inst.isFriendlyFire(player, aPlayer))
                                continue;
                            // Handle Sender
                            playerData.stopPushBack(250);
                            player.sendMessage(Text.of(TextColors.YELLOW, "You push back: ", aPlayer.getName(), "!"));
                            // Handle Target
                            aPlayer.setVelocity(vel);
                            Optional<SkyWarsPlayerData> optAPlayerData = inst.getPlayerData(aPlayer);
                            if (optAPlayerData.isPresent()) {
                                SkyWarsPlayerData aPlayerData = optAPlayerData.get();
                                if (aPlayerData.canDefrost()) {
                                    aPlayerData.stopFlight();
                                }
                            }
                        } else {
                            inst.awardPowerup(player, stack);
                            aEntity.remove();
                        }
                    }
                }
            }
        }
        tf(stack).attemptDamageItem(1, new Random());
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) SpongePlayer(com.sk89q.worldedit.sponge.SpongePlayer) SkyFeather(com.skelril.skree.content.registry.item.minigame.SkyFeather) TargetBlock(com.sk89q.worldedit.util.TargetBlock) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) Random(java.util.Random) SpongePlayer(com.sk89q.worldedit.sponge.SpongePlayer) Player(org.spongepowered.api.entity.living.player.Player) Optional(java.util.Optional) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) BlockWorldVector(com.sk89q.worldedit.BlockWorldVector) Vector3d(com.flowpowered.math.vector.Vector3d) Collection(java.util.Collection) Chicken(org.spongepowered.api.entity.living.animal.Chicken) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 4 with ParticleEffect

use of org.spongepowered.api.effect.particle.ParticleEffect in project Skree by Skelril.

the class HeartsCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Player targetPlayer = args.<Player>getOne(Text.of("player")).get();
    IntegratedRunnable runnable = new IntegratedRunnable() {

        @Override
        public boolean run(int times) {
            for (int i = 0; i < 75; ++i) {
                ParticleEffect effect = ParticleEffect.builder().type(ParticleTypes.HEART).quantity(1).build();
                targetPlayer.getWorld().spawnParticles(effect, targetPlayer.getLocation().getPosition().add(getRangedRandom(-5.0, 5.0), getRangedRandom(-2, 5.0), getRangedRandom(-5.0, 5.0)));
            }
            return true;
        }

        @Override
        public void end() {
        }
    };
    TimedRunnable timedRunnable = new TimedRunnable<>(runnable, 20);
    timedRunnable.setTask(Task.builder().execute(timedRunnable).intervalTicks(5).submit(SkreePlugin.inst()));
    return CommandResult.success();
}
Also used : ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) Player(org.spongepowered.api.entity.living.player.Player) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) TimedRunnable(com.skelril.nitro.time.TimedRunnable)

Aggregations

ParticleEffect (org.spongepowered.api.effect.particle.ParticleEffect)4 Vector3d (com.flowpowered.math.vector.Vector3d)3 Player (org.spongepowered.api.entity.living.player.Player)3 Entity (org.spongepowered.api.entity.Entity)2 Listener (org.spongepowered.api.event.Listener)2 Location (org.spongepowered.api.world.Location)2 BlockWorldVector (com.sk89q.worldedit.BlockWorldVector)1 SpongePlayer (com.sk89q.worldedit.sponge.SpongePlayer)1 TargetBlock (com.sk89q.worldedit.util.TargetBlock)1 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)1 TimedRunnable (com.skelril.nitro.time.TimedRunnable)1 SkyFeather (com.skelril.skree.content.registry.item.minigame.SkyFeather)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Random (java.util.Random)1 EntityZombie (net.minecraft.entity.monster.EntityZombie)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 BlockState (org.spongepowered.api.block.BlockState)1 BlockType (org.spongepowered.api.block.BlockType)1 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)1