Search in sources :

Example 1 with Snowball

use of org.spongepowered.api.entity.projectile.Snowball in project Skree by Skelril.

the class PatientXInstance method freezeBlocks.

public void freezeBlocks(int percentage, boolean throwExplosives) {
    ice.forAll((pt) -> {
        BlockType aboveType = getRegion().getExtent().getBlockType(pt.add(0, 1, 0));
        BlockType belowType = getRegion().getExtent().getBlockType(pt.add(0, -1, 0));
        if (aboveType == BlockTypes.AIR && belowType == BlockTypes.WATER || belowType == BlockTypes.FLOWING_WATER) {
            if (percentage >= 100) {
                getRegion().getExtent().setBlockType(pt, BlockTypes.ICE, Cause.source(SkreePlugin.container()).build());
                return;
            }
            BlockType curType = getRegion().getExtent().getBlockType(pt);
            if (curType == BlockTypes.PACKED_ICE || curType == BlockTypes.ICE) {
                getRegion().getExtent().setBlockType(pt, BlockTypes.WATER, Cause.source(SkreePlugin.container()).build());
                if (!Probability.getChance(config.snowBallChance) || !throwExplosives)
                    return;
                Location target = new Location<>(getRegion().getExtent(), pt.add(0, 1, 0));
                for (int i = Probability.getRandom(3); i > 0; i--) {
                    Snowball melvin = (Snowball) getRegion().getExtent().createEntity(EntityTypes.SNOWBALL, target.getPosition());
                    melvin.setVelocity(new Vector3d(0, Probability.getRangedRandom(.25, 1), 0));
                    getRegion().getExtent().spawnEntity(melvin, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                }
            } else if (Probability.getChance(percentage, 100)) {
                getRegion().getExtent().setBlockType(pt, BlockTypes.PACKED_ICE, Cause.source(SkreePlugin.container()).build());
            }
        }
    });
}
Also used : Snowball(org.spongepowered.api.entity.projectile.Snowball) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location)

Example 2 with Snowball

use of org.spongepowered.api.entity.projectile.Snowball in project Skree by Skelril.

the class MainWorldWrapper method createFor.

private PlayerCombatParser createFor(Cancellable event) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
            Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
            if (optService.isPresent()) {
                PvPService service = optService.get();
                if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
                    return;
                }
            }
            if (!(indirectSource instanceof Snowball) || !lobby.contains(attacker)) {
                attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in the main world!"));
                event.setCancelled(true);
            }
        }

        @Override
        public void processNonLivingAttack(DamageSource attacker, Player defender) {
            if (attacker.getType() == DamageTypes.VOID) {
                defender.setLocation(defender.getWorld().getSpawnLocation());
                defender.offer(Keys.FALL_DISTANCE, 0F);
                event.setCancelled(true);
            }
        }
    };
}
Also used : Entity(org.spongepowered.api.entity.Entity) Snowball(org.spongepowered.api.entity.projectile.Snowball) Player(org.spongepowered.api.entity.living.player.Player) PvPService(com.skelril.skree.service.PvPService) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) Nullable(javax.annotation.Nullable)

Example 3 with Snowball

use of org.spongepowered.api.entity.projectile.Snowball in project Skree by Skelril.

the class JungleRaidEffectListener method onProjectileHit.

@Listener
public void onProjectileHit(CollideEvent.Impact event, @First Entity entity) {
    Optional<JungleRaidInstance> optInst = manager.getApplicableZone(entity);
    if (!optInst.isPresent())
        return;
    JungleRaidInstance inst = optInst.get();
    if (inst.getState() != JungleRaidState.IN_PROGRESS) {
        return;
    }
    int explosionSize = 2;
    if (entity.getType() == EntityTypes.TIPPED_ARROW) {
        if (inst.isFlagEnabled(JungleRaidFlag.TORMENT_ARROWS)) {
            ProjectileSource shooter = ((Arrow) entity).getShooter();
            CuboidContainmentPredicate predicate = new CuboidContainmentPredicate(entity.getLocation().getPosition(), 16, 16, 16);
            for (Entity e : entity.getNearbyEntities(en -> predicate.test(en.getLocation().getPosition()))) {
                if (e.equals(shooter))
                    continue;
                if (e instanceof Living && shooter instanceof Living) {
                    e.damage(1, IndirectEntityDamageSource.builder().type(DamageTypes.PROJECTILE).entity(entity).proxySource((Living) shooter).build());
                    if (Probability.getChance(5)) {
                        EntityHealthUtil.heal((Living) shooter, 1);
                    }
                }
            }
        }
        if (inst.isFlagEnabled(JungleRaidFlag.EXPLOSIVE_ARROWS)) {
            if (inst.isFlagEnabled(JungleRaidFlag.SUPER))
                explosionSize = 4;
        } else
            return;
    }
    if (entity instanceof Snowball) {
        if (inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
            if (inst.isFlagEnabled(JungleRaidFlag.SUPER))
                explosionSize = 10;
            else
                explosionSize = 6;
        } else
            return;
    }
    if (entity instanceof ThrownPotion) {
        return;
    }
    entity.getLocation().getExtent().triggerExplosion(Explosion.builder().radius(explosionSize).location(entity.getLocation()).shouldDamageEntities(true).shouldBreakBlocks(true).build(), Cause.source(SkreePlugin.container()).build());
}
Also used : Arrow(org.spongepowered.api.entity.projectile.arrow.Arrow) CuboidContainmentPredicate(com.skelril.nitro.position.CuboidContainmentPredicate) Entity(org.spongepowered.api.entity.Entity) Snowball(org.spongepowered.api.entity.projectile.Snowball) Living(org.spongepowered.api.entity.living.Living) ThrownPotion(org.spongepowered.api.entity.projectile.ThrownPotion) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) Listener(org.spongepowered.api.event.Listener)

Aggregations

Snowball (org.spongepowered.api.entity.projectile.Snowball)3 Entity (org.spongepowered.api.entity.Entity)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)1 CuboidContainmentPredicate (com.skelril.nitro.position.CuboidContainmentPredicate)1 PvPService (com.skelril.skree.service.PvPService)1 Nullable (javax.annotation.Nullable)1 BlockType (org.spongepowered.api.block.BlockType)1 Living (org.spongepowered.api.entity.living.Living)1 Player (org.spongepowered.api.entity.living.player.Player)1 ThrownPotion (org.spongepowered.api.entity.projectile.ThrownPotion)1 Arrow (org.spongepowered.api.entity.projectile.arrow.Arrow)1 ProjectileSource (org.spongepowered.api.entity.projectile.source.ProjectileSource)1 Listener (org.spongepowered.api.event.Listener)1 DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)1 Location (org.spongepowered.api.world.Location)1