Search in sources :

Example 1 with Villager

use of org.spongepowered.api.entity.living.Villager in project RedProtect by FabioZumbi12.

the class RPEntityListener method onEntityDamage.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent e) {
    // victim
    Entity e1 = e.getTargetEntity();
    RedProtect.get().logger.debug("entity", "RPEntityListener - DamageEntityEvent entity target " + e1.getType().getName());
    Region r = RedProtect.get().rm.getTopRegion(e1.getLocation());
    if (e1 instanceof Living && !(e1 instanceof Monster)) {
        if (r != null && r.flagExists("invincible")) {
            if (r.getFlagBool("invincible")) {
                e.setCancelled(true);
            }
        }
    }
    if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
        if (r != null && r.flagExists("invincible")) {
            if (r.getFlagBool("invincible")) {
                if (e1 instanceof Animal) {
                    ((Animal) e1).setTarget(null);
                }
                e.setCancelled(true);
            }
        }
    }
    // damager
    if (!e.getCause().first(Living.class).isPresent()) {
        return;
    }
    Entity e2 = e.getCause().first(Living.class).get();
    RedProtect.get().logger.debug("entity", "RPEntityListener - DamageEntityEvent damager " + e2.getType().getName());
    if (e2 instanceof Projectile) {
        Projectile a = (Projectile) e2;
        if (a.getShooter() instanceof Entity) {
            e2 = (Entity) a.getShooter();
        }
    }
    Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
    Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
    if (e.getCause().containsType(Lightning.class) || e.getCause().containsType(Explosive.class) || e.getCause().containsType(Fireball.class) || e.getCause().containsType(Explosion.class)) {
        if (r1 != null && !r1.canFire() && !(e2 instanceof Player)) {
            e.setCancelled(true);
            return;
        }
    }
    if (e1 instanceof Player) {
        if (e2 instanceof Player) {
            Player p2 = (Player) e2;
            if (r1 != null) {
                ItemType itemInHand = ItemTypes.NONE;
                if (p2.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
                    itemInHand = p2.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
                } else if (p2.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
                    itemInHand = p2.getItemInHand(HandTypes.OFF_HAND).get().getItem();
                }
                if (itemInHand.getType().equals(ItemTypes.EGG) && !r1.canProtectiles(p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                    return;
                }
                if (r2 != null) {
                    if (itemInHand.getType().equals(ItemTypes.EGG) && !r2.canProtectiles(p2)) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                        return;
                    }
                    if ((r1.flagExists("pvp") && !r1.canPVP(p2)) || (r1.flagExists("pvp") && !r2.canPVP(p2))) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                    }
                } else if (r1.flagExists("pvp") && !r1.canPVP(p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                }
            } else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP(p2)) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
            }
        }
    } else if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e instanceof Ambient) {
        if (r1 != null && e2 instanceof Player) {
            Player p2 = (Player) e2;
            if (!r1.canInteractPassives(p2)) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "entitylistener.region.cantpassive");
            }
        }
    } else if ((e1 instanceof Hanging) && e2 instanceof Player) {
        Player p2 = (Player) e2;
        if (r1 != null && !r1.canBuild(p2)) {
            e.setCancelled(true);
            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
            return;
        }
        if (r2 != null && !r2.canBuild(p2)) {
            e.setCancelled(true);
            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
        }
    } else if ((e1 instanceof Hanging) && e2 instanceof Monster) {
        if (r1 != null || r2 != null) {
            RedProtect.get().logger.debug("entity", "Cancelled ItemFrame drop Item");
            e.setCancelled(true);
        }
    } else if ((e1 instanceof Explosive)) {
        if ((r1 != null && !r1.canFire()) || (r2 != null && !r2.canFire())) {
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Explosion(org.spongepowered.api.world.explosion.Explosion) Living(org.spongepowered.api.entity.living.Living) ItemType(org.spongepowered.api.item.ItemType) Projectile(org.spongepowered.api.entity.projectile.Projectile) Golem(org.spongepowered.api.entity.living.golem.Golem) Ambient(org.spongepowered.api.entity.living.Ambient) Explosive(org.spongepowered.api.entity.explosive.Explosive) Hanging(org.spongepowered.api.entity.hanging.Hanging) Animal(org.spongepowered.api.entity.living.animal.Animal) Lightning(org.spongepowered.api.entity.weather.Lightning) Monster(org.spongepowered.api.entity.living.monster.Monster) Villager(org.spongepowered.api.entity.living.Villager) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 2 with Villager

use of org.spongepowered.api.entity.living.Villager in project RedProtect by FabioZumbi12.

the class RPEntityListener method onInteractEvent.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractEvent(InteractEntityEvent.Secondary e, @First Player p) {
    Entity et = e.getTargetEntity();
    Location<World> l = et.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    RedProtect.get().logger.debug("entity", "RPEntityListener - InteractEntityEvent.Secondary entity " + et.getType().getName());
    if (r != null && !r.canInteractPassives(p) && (et instanceof Animal || et instanceof Villager || et instanceof Golem || et instanceof Ambient)) {
        if (RedProtect.get().getPVHelper().checkHorseOwner(et, p)) {
            return;
        }
        e.setCancelled(true);
        RPLang.sendMessage(p, "entitylistener.region.cantinteract");
    }
}
Also used : Golem(org.spongepowered.api.entity.living.golem.Golem) Entity(org.spongepowered.api.entity.Entity) Ambient(org.spongepowered.api.entity.living.Ambient) Animal(org.spongepowered.api.entity.living.animal.Animal) Villager(org.spongepowered.api.entity.living.Villager) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 3 with Villager

use of org.spongepowered.api.entity.living.Villager in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onProjectileHit.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onProjectileHit(CollideEntityEvent event, @Root Projectile proj) {
    RedProtect.get().logger.debug("entity", "Is CollideEntityEvent(onProjectileHit) event.");
    RedProtect.get().logger.debug("entity", "Projectile: " + proj.getType().getName());
    if (RedProtect.get().rm.getTopRegion(proj.getLocation()) != null)
        return;
    for (Entity ent : event.getEntities()) {
        RedProtect.get().logger.debug("entity", "Entity: " + ent.getType().getName());
        if (proj.getShooter() instanceof Player) {
            Player p = (Player) proj.getShooter();
            if (ent instanceof Player) {
                if (!p.equals(ent) && !RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "pvp") && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Animal || ent instanceof Villager || ent instanceof Golem || ent instanceof Ambient) {
                if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "player-hurt-passives") && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Monster) {
                if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "player-hurt-monsters") && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Hanging || ent instanceof ArmorStand) {
                if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                }
            }
        } else {
            if (ent instanceof Hanging || ent instanceof ArmorStand) {
                if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "entity-block-damage")) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
Also used : Golem(org.spongepowered.api.entity.living.golem.Golem) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Ambient(org.spongepowered.api.entity.living.Ambient) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) Hanging(org.spongepowered.api.entity.hanging.Hanging) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Villager(org.spongepowered.api.entity.living.Villager) Listener(org.spongepowered.api.event.Listener)

Example 4 with Villager

use of org.spongepowered.api.entity.living.Villager in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onCreatureSpawn.

@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {
    for (Entity e : event.getEntities()) {
        if (e == null || RedProtect.get().rm.getTopRegion(e.getLocation()) != null) {
            continue;
        }
        if (e instanceof Wither && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-wither")) {
            RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Wither " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        if (e instanceof Monster && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-monsters")) {
            RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Monster " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        if ((e instanceof Animal || e instanceof Villager || e instanceof Ambient || e instanceof Golem) && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-passives")) {
            RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Animal " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        RedProtect.get().logger.debug("spawn", "RPGlobalListener - Spawn mob " + e.getType().getName());
    }
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Golem(org.spongepowered.api.entity.living.golem.Golem) Entity(org.spongepowered.api.entity.Entity) Ambient(org.spongepowered.api.entity.living.Ambient) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Villager(org.spongepowered.api.entity.living.Villager) Listener(org.spongepowered.api.event.Listener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Example 5 with Villager

use of org.spongepowered.api.entity.living.Villager 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;
            }
        }
    }
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) Creeper(org.spongepowered.api.entity.living.monster.Creeper) TNTMinecart(org.spongepowered.api.entity.vehicle.minecart.TNTMinecart) Minecart(org.spongepowered.api.entity.vehicle.minecart.Minecart) World(org.spongepowered.api.world.World) Projectile(org.spongepowered.api.entity.projectile.Projectile) Golem(org.spongepowered.api.entity.living.golem.Golem) Ambient(org.spongepowered.api.entity.living.Ambient) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) Hanging(org.spongepowered.api.entity.hanging.Hanging) TNTMinecart(org.spongepowered.api.entity.vehicle.minecart.TNTMinecart) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Villager(org.spongepowered.api.entity.living.Villager) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Boat(org.spongepowered.api.entity.vehicle.Boat) Listener(org.spongepowered.api.event.Listener)

Aggregations

Entity (org.spongepowered.api.entity.Entity)5 Ambient (org.spongepowered.api.entity.living.Ambient)5 Villager (org.spongepowered.api.entity.living.Villager)5 Animal (org.spongepowered.api.entity.living.animal.Animal)5 Golem (org.spongepowered.api.entity.living.golem.Golem)5 Listener (org.spongepowered.api.event.Listener)5 Monster (org.spongepowered.api.entity.living.monster.Monster)4 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)3 Hanging (org.spongepowered.api.entity.hanging.Hanging)3 Player (org.spongepowered.api.entity.living.player.Player)3 ArmorStand (org.spongepowered.api.entity.living.ArmorStand)2 Living (org.spongepowered.api.entity.living.Living)2 Projectile (org.spongepowered.api.entity.projectile.Projectile)2 World (org.spongepowered.api.world.World)2 Explosive (org.spongepowered.api.entity.explosive.Explosive)1 PrimedTNT (org.spongepowered.api.entity.explosive.PrimedTNT)1 Creeper (org.spongepowered.api.entity.living.monster.Creeper)1 Wither (org.spongepowered.api.entity.living.monster.Wither)1 Boat (org.spongepowered.api.entity.vehicle.Boat)1 Minecart (org.spongepowered.api.entity.vehicle.minecart.Minecart)1