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());
}
}
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);
}
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();
}
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();
}
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);
}
Aggregations