Search in sources :

Example 51 with Entity

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

the class PatientXListener method onEntityDamageEvent.

@Listener(order = Order.LAST)
public void onEntityDamageEvent(DamageEntityEvent event) {
    Entity defender = event.getTargetEntity();
    Optional<PatientXInstance> optInst = manager.getApplicableZone(defender);
    if (!optInst.isPresent())
        return;
    PatientXInstance inst = optInst.get();
    DamageSource dmgSource = event.getCause().first(DamageSource.class).get();
    if (defender instanceof Player && manager.getBlockedDamage().contains(dmgSource.getType())) {
        // Explosive damage formula: (1 × 1 + 1) × 8 × power + 1
        // Use 49, snowball power is 3
        double ratio = event.getBaseDamage() / 49;
        // Nullify all modifiers
        for (Tuple<DamageModifier, Function<? super Double, Double>> modifier : event.getModifiers()) {
            event.setDamage(modifier.getFirst(), (a) -> 0D);
        }
        event.setBaseDamage(ratio * inst.getDifficulty());
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Function(java.util.function.Function) Player(org.spongepowered.api.entity.living.player.Player) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) Listener(org.spongepowered.api.event.Listener)

Example 52 with Entity

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

the class MeleeAttackClusterListener method getSource.

public Optional<Living> getSource(Cause cause) {
    Optional<EntityDamageSource> optEntityDamageSource = cause.first(EntityDamageSource.class);
    if (!optEntityDamageSource.isPresent()) {
        return Optional.empty();
    }
    EntityDamageSource damageSource = optEntityDamageSource.get();
    Entity source = damageSource.getSource();
    if (!(source instanceof Living)) {
        return Optional.empty();
    }
    return Optional.of((Living) source);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Living(org.spongepowered.api.entity.living.Living) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)

Example 53 with Entity

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

the class VelocityEntitySpawner method send.

public static Optional<Entity> send(EntityType type, Location<World> loc, Vector3d dir, float speed, Cause cause) {
    Vector3d actualDir = dir.normalize();
    // Shift the entity out two movements to prevent collision with the source entity
    Vector3d finalVecLoc = loc.getPosition().add(actualDir.mul(2));
    loc = loc.setPosition(finalVecLoc);
    Entity entity = loc.getExtent().createEntity(type, loc.getPosition());
    entity.setVelocity(dir.mul(speed));
    return loc.getExtent().spawnEntity(entity, cause) ? Optional.of(entity) : Optional.empty();
}
Also used : Entity(org.spongepowered.api.entity.Entity) Vector3d(com.flowpowered.math.vector.Vector3d)

Example 54 with Entity

use of org.spongepowered.api.entity.Entity in project HuskyCrates-Sponge by codeHusky.

the class CrateUtilities method particleRunner.

private void particleRunner() {
    if (flag)
        return;
    try {
        ArrayList<Location<World>> invalidLocations = new ArrayList<>();
        HashSet<World> invalidLocationWorlds = new HashSet<>();
        for (Location<World> b : physicalCrates.keySet()) {
            PhysicalCrate c = physicalCrates.get(b);
            if (c.vc.crateBlockType != c.location.getBlock().getType() && c.location.getExtent().isLoaded() && c.location.getExtent().getChunk(c.location.getChunkPosition()).isPresent()) {
                if (c.location.getExtent().getChunk(c.location.getChunkPosition()).get().isLoaded()) {
                    invalidLocations.add(c.location);
                    invalidLocationWorlds.add(c.location.getExtent());
                    continue;
                }
            }
            c.runParticles();
        }
        for (World w : invalidLocationWorlds) {
            for (Entity e : w.getEntities()) {
                if (invalidLocations.contains(e.getLocation()) && e.getType() != EntityTypes.ARMOR_STAND) {
                    //System.out.println("woah");
                    invalidLocations.remove(e.getLocation());
                    physicalCrates.get(e.getLocation()).runParticles();
                }
            }
        }
        for (Location<World> l : invalidLocations) {
            PhysicalCrate c = physicalCrates.get(l);
            HuskyCrates.instance.logger.warn("Removing crate that no longer exists! " + c.location.getPosition().toString());
            c.as.remove();
            physicalCrates.remove(l);
            flag = true;
        }
    } catch (Exception e) {
    }
    if (flag)
        HuskyCrates.instance.updatePhysicalCrates();
}
Also used : Entity(org.spongepowered.api.entity.Entity) World(org.spongepowered.api.world.World) IOException(java.io.IOException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Location(org.spongepowered.api.world.Location)

Example 55 with Entity

use of org.spongepowered.api.entity.Entity in project ClearMob by axle2005.

the class clearMain method run.

public void run(Boolean[] configoptions, List<EntityType> listEntityType, CommandSource src) {
    int removedEntities = 0;
    Map<UUID, Entity> entityData = new ConcurrentHashMap<>();
    for (World world : Sponge.getServer().getWorlds()) {
        for (Entity entity : world.getEntities()) {
            entityData.put(entity.getUniqueId(), entity);
        }
        for (Entity entity : entityData.values()) {
            if (!entity.isRemoved()) {
                if (entity instanceof Player) {
                } else if (entity.get(DisplayNameData.class).isPresent()) {
                // Checks if entity has nametag and ignores it.
                } else if (configoptions[1] == true && entity instanceof Monster) {
                    // KillAllMonsters
                    removedEntities++;
                    entity.remove();
                } else if (configoptions[2] == true && entity instanceof Item) {
                    // KillDrops
                    if (ClearItems.run(entity, plugin.getListItemType(), plugin.getitemWB())) {
                        removedEntities++;
                    }
                } else if (configoptions[3] == true && entity instanceof Animal) {
                    // KillAnimalGroups
                    removedEntities = removedEntities + animals.run(entity);
                } else {
                    if (wl.clear(entity, plugin.getListEntityType()) == true) {
                        removedEntities++;
                    }
                }
            }
        }
    }
    ClearTileEntity.run(plugin, plugin.getListTileEntityType(), plugin.getWorlds(), src);
    feedback(src, removedEntities);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Item(org.spongepowered.api.entity.Item) Player(org.spongepowered.api.entity.living.player.Player) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) 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