Search in sources :

Example 6 with Entity

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

the class WanderingMobManager method summon.

public boolean summon(String wandererType, int level, Location<World> location) {
    WanderingBoss<? extends Entity> wanderer = wanderers.get(wandererType);
    if (wanderer == null) {
        return false;
    }
    Entity entity = wanderer.createEntity(location);
    boolean spawned = location.getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
    if (!spawned) {
        return false;
    }
    return wanderer.apply(entity, new WildernessBossDetail(level));
}
Also used : Entity(org.spongepowered.api.entity.Entity)

Example 7 with Entity

use of org.spongepowered.api.entity.Entity 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 8 with Entity

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

the class CannonCurse method accept.

@Override
public void accept(Player player) {
    Entity entity = player.getWorld().createEntity(EntityTypes.FIREBALL, player.getLocation().getPosition());
    player.getWorld().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
Also used : Entity(org.spongepowered.api.entity.Entity)

Example 9 with Entity

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

the class DeadlyPotionCurse method throwSlashPotion.

private void throwSlashPotion(Location<World> location) {
    PotionEffectType[] thrownTypes = new PotionEffectType[] { PotionEffectTypes.INSTANT_DAMAGE, PotionEffectTypes.INSTANT_DAMAGE, PotionEffectTypes.POISON, PotionEffectTypes.WEAKNESS };
    Entity entity = location.getExtent().createEntity(EntityTypes.SPLASH_POTION, location.getPosition());
    entity.setVelocity(new Vector3d(random.nextDouble() * .5 - .25, random.nextDouble() * .4 + .1, random.nextDouble() * .5 - .25));
    PotionEffectType type = Probability.pickOneOf(thrownTypes);
    PotionEffect effect = PotionEffect.of(type, 2, type.isInstant() ? 1 : 15 * 20);
    entity.offer(Keys.POTION_EFFECTS, Lists.newArrayList(effect));
    location.getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
Also used : Entity(org.spongepowered.api.entity.Entity) Vector3d(com.flowpowered.math.vector.Vector3d) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) PotionEffectType(org.spongepowered.api.effect.potion.PotionEffectType)

Example 10 with Entity

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

the class MainWorldWrapper method run.

@Override
public void run() {
    PotionEffect speedEffect = PotionEffect.builder().duration(3 * 20).amplifier(5).particles(false).potionType(PotionEffectTypes.SPEED).build();
    for (World world : getWorlds()) {
        for (Entity entity : world.getEntities(p -> p.getType().equals(EntityTypes.PLAYER))) {
            if (entity.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) != GameModes.SURVIVAL) {
                continue;
            }
            List<PotionEffect> potionEffects = entity.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
            potionEffects.add(speedEffect);
            entity.offer(Keys.POTION_EFFECTS, potionEffects);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) World(org.spongepowered.api.world.World)

Aggregations

Entity (org.spongepowered.api.entity.Entity)59 Player (org.spongepowered.api.entity.living.player.Player)23 World (org.spongepowered.api.world.World)19 Living (org.spongepowered.api.entity.living.Living)17 Listener (org.spongepowered.api.event.Listener)13 Vector3d (com.flowpowered.math.vector.Vector3d)10 ArrayList (java.util.ArrayList)8 DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)8 Instruction (com.skelril.openboss.Instruction)7 ItemStack (org.spongepowered.api.item.inventory.ItemStack)7 Location (org.spongepowered.api.world.Location)7 Zombie (org.spongepowered.api.entity.living.monster.Zombie)6 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)6 ZoneBossDetail (com.skelril.skree.content.zone.ZoneBossDetail)5 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)5 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)5 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)5 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)4 Vector3i (com.flowpowered.math.vector.Vector3i)3 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)3