use of org.spongepowered.api.entity.living.Living in project RedProtect by FabioZumbi12.
the class RPEntityListener method onCreatureSpawn.
@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {
for (Entity e : event.getEntities()) {
if (e == null || e.getType() == null) {
continue;
}
if (!(e instanceof Living)) {
continue;
}
Optional<SpawnTypes> cause = event.getCause().first(SpawnTypes.class);
RedProtect.get().logger.debug("entity", "SpawnCause: " + (cause.map(Object::toString).orElse(" null")));
if (e instanceof Wither && cause.isPresent() && cause.get().equals(SpawnTypes.PLACEMENT)) {
Region r = RedProtect.get().rm.getTopRegion(e.getLocation());
if (r != null && !r.canSpawnWhiter()) {
event.isCancelled();
return;
}
}
if (e instanceof Monster) {
Location<World> l = e.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canSpawnMonsters()) {
RedProtect.get().logger.debug("entity", "Cancelled spawn of monster " + e.getType().getName());
event.setCancelled(true);
return;
}
}
if (e instanceof Animal || e instanceof Golem || e instanceof Ambient || e instanceof Aquatic) {
Location<World> l = e.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canSpawnPassives()) {
RedProtect.get().logger.debug("entity", "Cancelled spawn of animal " + e.getType().getName());
event.setCancelled(true);
return;
}
}
RedProtect.get().logger.debug("entity", "RPEntityListener - Spawn mob " + e.getType().getName());
}
}
use of org.spongepowered.api.entity.living.Living in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onEntityDamageEntity.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEntity(DamageEntityEvent e) {
Entity e1 = e.getTargetEntity();
Entity e2;
RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - e1: " + e1.getType().getName());
Region r = RedProtect.get().rm.getTopRegion(e1.getLocation());
if (e1 instanceof Living && !(e1 instanceof Monster)) {
if (r == null && RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "invincible")) {
e.setCancelled(true);
}
}
if (e.getCause().first(Living.class).isPresent()) {
e2 = e.getCause().first(Living.class).get();
RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - Is DamageEntityEvent event. Damager " + e2.getType().getName());
} else {
return;
}
RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - e1: " + e1.getType().getName() + " - e2: " + e2.getType().getName());
Location<World> loc = e1.getLocation();
Region r1 = RedProtect.get().rm.getTopRegion(loc);
if (r1 != null) {
return;
}
if (e2 instanceof Projectile) {
Projectile proj = (Projectile) e2;
if (proj.getShooter() instanceof Entity) {
e2 = (Entity) proj.getShooter();
}
if (!(e2 instanceof Player)) {
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage")) {
e.setCancelled(true);
return;
}
}
}
}
if (e2 instanceof Creeper || e2 instanceof PrimedTNT || e2 instanceof TNTMinecart) {
if (e1 instanceof Player) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage")) {
e.setCancelled(true);
return;
}
}
}
if (e2 instanceof Player) {
Player p = (Player) e2;
if (e1 instanceof Player) {
if (!e1.equals(e2) && !RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "pvp") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "player-hurt-passives") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "player-hurt-monsters") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Boat || e1 instanceof Minecart) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
}
}
use of org.spongepowered.api.entity.living.Living 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(), 4, 4, 4);
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());
}
use of org.spongepowered.api.entity.living.Living in project Skree by Skelril.
the class WildernessWorldWrapper method createFor.
private PlayerCombatParser createFor(Cancellable event, int level) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender) {
if (allowsPvP(level)) {
return;
}
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;
}
}
attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in this part of the Wilderness!"));
attacker.sendMessage(Text.of(TextColors.RED, "Mandatory PvP is from level ", getFirstPvPLevel(), " and on."));
event.setCancelled(true);
}
@Override
public void processMonsterAttack(Living attacker, Player defender) {
if (!(event instanceof DamageEntityEvent)) {
return;
}
DamageEntityEvent dEvent = (DamageEntityEvent) event;
// If they're endermites they hit through armor, otherwise they get a damage boost
if (attacker.getType() == EntityTypes.ENDERMITE) {
for (DamageFunction modifier : dEvent.getModifiers()) {
dEvent.setDamage(modifier.getModifier(), (a) -> 0D);
}
dEvent.setBaseDamage(Probability.getCompoundRandom(getDamageMod(level), 3));
if (Probability.getChance(5)) {
List<PotionEffect> potionEffects = defender.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>());
potionEffects.add(PotionEffect.of(PotionEffectTypes.POISON, 2, 30 * 20));
defender.offer(Keys.POTION_EFFECTS, potionEffects);
}
} else {
dEvent.setBaseDamage(dEvent.getBaseDamage() + getDamageMod(level));
}
// Only apply scoring while in survival mode
if (defender.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.SURVIVAL) {
return;
}
WildernessPlayerMeta meta = playerMetaMap.get(defender.getUniqueId());
if (meta != null) {
meta.hit();
}
}
@Override
public void processPlayerAttack(Player attacker, Living defender) {
Task.builder().delayTicks(1).execute(() -> healthPrinter.print(MessageChannel.fixed(attacker), defender)).submit(SkreePlugin.inst());
if (!(defender instanceof Monster) || defender instanceof Creeper) {
return;
}
// Only apply scoring while in survival mode
if (attacker.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.SURVIVAL) {
return;
}
WildernessPlayerMeta meta = playerMetaMap.get(attacker.getUniqueId());
if (meta != null) {
meta.attack();
if (meta.getRatio() > 30 && meta.getFactors() > 35) {
Deque<Entity> spawned = new ArrayDeque<>();
for (int i = Probability.getRandom(5); i > 0; --i) {
Entity entity = attacker.getWorld().createEntity(EntityTypes.ENDERMITE, defender.getLocation().getPosition());
entity.getWorld().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
spawned.add(entity);
}
IntegratedRunnable runnable = new IntegratedRunnable() {
@Override
public boolean run(int times) {
Entity mob = spawned.poll();
if (mob.isLoaded() && mob.getWorld().equals(attacker.getWorld())) {
mob.setLocation(attacker.getLocation());
}
return true;
}
@Override
public void end() {
}
};
TimedRunnable timedRunnable = new TimedRunnable<>(runnable, spawned.size());
timedRunnable.setTask(Task.builder().execute(timedRunnable).delayTicks(40).intervalTicks(20).submit(SkreePlugin.inst()));
}
if (System.currentTimeMillis() - meta.getLastReset() >= TimeUnit.MINUTES.toMillis(5)) {
meta.reset();
}
}
}
};
}
use of org.spongepowered.api.entity.living.Living in project Skree by Skelril.
the class StormBringer method setupStormBringer.
private void setupStormBringer() {
Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Skeleton.class));
List<Instruction<BindCondition, Boss<Skeleton, WildernessBossDetail>>> bindProcessor = bossManager.getBindProcessor();
bindProcessor.add((condition, boss) -> {
Optional<Skeleton> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Skeleton bossEnt = optBossEnt.get();
bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Storm Bringer"));
bossEnt.offer(Keys.CUSTOM_NAME_VISIBLE, true);
double bossHealth = 20 * 30 * boss.getDetail().getLevel();
setMaxHealth(bossEnt, bossHealth, true);
}
return Optional.empty();
});
List<Instruction<DamageCondition, Boss<Skeleton, WildernessBossDetail>>> damageProcessor = bossManager.getDamageProcessor();
damageProcessor.add((condition, boss) -> {
Entity eToHit = condition.getAttacked();
if (!(eToHit instanceof Living)) {
return Optional.empty();
}
Living toHit = (Living) eToHit;
Location<World> targetLocation = toHit.getLocation();
for (int i = boss.getDetail().getLevel() * Probability.getRangedRandom(1, 10); i >= 0; --i) {
Task.builder().execute(() -> {
Entity lightning = targetLocation.getExtent().createEntity(EntityTypes.LIGHTNING, targetLocation.getPosition());
targetLocation.getExtent().spawnEntity(lightning, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}).delayTicks(5 * (6 + i)).submit(SkreePlugin.inst());
}
return Optional.empty();
});
}
Aggregations