Search in sources :

Example 1 with Lightning

use of org.spongepowered.api.entity.weather.Lightning in project Skree by Skelril.

the class ZoneMasterOrb method createLightningStrike.

private void createLightningStrike(Player player) {
    Location<World> loc = player.getLocation();
    Lightning lightning = (Lightning) loc.getExtent().createEntity(EntityTypes.LIGHTNING, loc.getPosition());
    lightning.setEffect(true);
    loc.getExtent().spawnEntity(lightning, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
Also used : Lightning(org.spongepowered.api.entity.weather.Lightning) World(org.spongepowered.api.world.World)

Example 2 with Lightning

use of org.spongepowered.api.entity.weather.Lightning in project Skree by Skelril.

the class ThorAttack method apply.

@Override
public Optional<Instruction<DamageCondition, Boss<Zombie, CatacombsBossDetail>>> apply(DamageCondition damageCondition, Boss<Zombie, CatacombsBossDetail> zombieCatacombsBossDetailBoss) {
    Living bossEnt = zombieCatacombsBossDetailBoss.getTargetEntity().get();
    Entity toHit = damageCondition.getAttacked();
    toHit.setVelocity(EntityDirectionUtil.getFacingVector(bossEnt).mul(2));
    Task.builder().execute(() -> {
        Location<World> targetLoc = toHit.getLocation();
        Task.builder().execute(() -> {
            Lightning lightning = (Lightning) toHit.getWorld().createEntity(EntityTypes.LIGHTNING, targetLoc.getPosition());
            toHit.getWorld().spawnEntity(lightning, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
        }).delay(750, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst());
    }).delay(1500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst());
    return Optional.empty();
}
Also used : Entity(org.spongepowered.api.entity.Entity) Living(org.spongepowered.api.entity.living.Living) Lightning(org.spongepowered.api.entity.weather.Lightning) World(org.spongepowered.api.world.World)

Example 3 with Lightning

use of org.spongepowered.api.entity.weather.Lightning in project modules-extra by CubeEngine.

the class PlayerCommands method lightning.

@Command(alias = "strike", desc = "Throws a lightning bolt at a player or where you're looking")
public void lightning(CommandSource context, @Optional Integer damage, @Named({ "player", "p" }) Player player, @Named({ "fireticks", "f" }) Integer seconds, @Flag boolean unsafe) {
    damage = damage == null ? -1 : damage;
    if (damage != -1 && !context.hasPermission(module.perms().COMMAND_LIGHTNING_PLAYER_DAMAGE.getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to specify the damage!");
        return;
    }
    if ((damage != -1 && damage < 0) || damage > 20) {
        i18n.send(context, NEGATIVE, "The damage value has to be a number from 1 to 20");
        return;
    }
    if (unsafe && !context.hasPermission(module.perms().COMMAND_LIGHTNING_UNSAFE.getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to use the unsafe flag");
        return;
    }
    Location<World> location;
    if (player != null) {
        location = player.getLocation();
        player.offer(Keys.FIRE_TICKS, 20 * (seconds == null ? 0 : seconds));
        if (damage != -1) {
            // TODO better source
            player.damage(damage, DamageSource.builder().type(DamageTypes.CONTACT).build());
        }
    } else {
        if (!(context instanceof Player)) {
            i18n.send(context, NEGATIVE, "This command can only be used by a player!");
            return;
        }
        java.util.Optional<BlockRayHit<World>> end = BlockRay.from(((Player) context)).distanceLimit(module.getConfig().command.lightning.distance).stopFilter(BlockRay.onlyAirFilter()).build().end();
        if (end.isPresent()) {
            location = end.get().getLocation();
        } else {
            throw new IllegalStateException();
        }
    }
    Entity entity = location.getExtent().createEntity(EntityTypes.LIGHTNING, location.getPosition());
    if (!unsafe) {
        ((Lightning) entity).setEffect(true);
    }
    Sponge.getCauseStackManager().pushCause(context);
    location.getExtent().spawnEntity(entity);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Lightning(org.spongepowered.api.entity.weather.Lightning) World(org.spongepowered.api.world.World) BlockRayHit(org.spongepowered.api.util.blockray.BlockRayHit) Command(org.cubeengine.butler.parametric.Command)

Example 4 with Lightning

use of org.spongepowered.api.entity.weather.Lightning in project Skree by Skelril.

the class BuildWorldWrapper method onEntitySpawn.

@Listener
public void onEntitySpawn(SpawnEntityEvent event) {
    List<Entity> entities = event.getEntities();
    Optional<BlockSpawnCause> optBlockCause = event.getCause().first(BlockSpawnCause.class);
    for (Entity entity : entities) {
        if (!isApplicable(entity)) {
            continue;
        }
        if (entity instanceof Lightning) {
            ((Lightning) entity).setEffect(true);
            continue;
        }
        if (entity instanceof Egg && optBlockCause.isPresent()) {
            new ItemDropper(entity.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.EGG)), SpawnTypes.DISPENSE);
            event.setCancelled(true);
            return;
        }
        if (entity instanceof Monster || (entity instanceof SkeletonHorse)) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Egg(org.spongepowered.api.entity.projectile.Egg) ItemDropper(com.skelril.nitro.item.ItemDropper) Lightning(org.spongepowered.api.entity.weather.Lightning) Monster(org.spongepowered.api.entity.living.monster.Monster) BlockSpawnCause(org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause) SkeletonHorse(org.spongepowered.api.entity.living.animal.SkeletonHorse) Listener(org.spongepowered.api.event.Listener)

Example 5 with Lightning

use of org.spongepowered.api.entity.weather.Lightning in project Skree by Skelril.

the class LightningStrike method run.

@Override
public void run(Living owner, Location<World> target) {
    Lightning lightning = (Lightning) target.createEntity(EntityTypes.LIGHTNING);
    target.spawnEntity(lightning, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
Also used : Lightning(org.spongepowered.api.entity.weather.Lightning)

Aggregations

Lightning (org.spongepowered.api.entity.weather.Lightning)5 Entity (org.spongepowered.api.entity.Entity)3 World (org.spongepowered.api.world.World)3 ItemDropper (com.skelril.nitro.item.ItemDropper)1 Command (org.cubeengine.butler.parametric.Command)1 Living (org.spongepowered.api.entity.living.Living)1 SkeletonHorse (org.spongepowered.api.entity.living.animal.SkeletonHorse)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Player (org.spongepowered.api.entity.living.player.Player)1 Egg (org.spongepowered.api.entity.projectile.Egg)1 Listener (org.spongepowered.api.event.Listener)1 BlockSpawnCause (org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause)1 BlockRayHit (org.spongepowered.api.util.blockray.BlockRayHit)1