Search in sources :

Example 1 with Minecart

use of org.spongepowered.api.entity.vehicle.minecart.Minecart in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onPlayerInteract.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEntityEvent e, @Root Player p) {
    Entity ent = e.getTargetEntity();
    Location<World> l = ent.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (!canInteract(p, r)) {
        e.setCancelled(true);
    }
    if (r != null) {
        return;
    }
    if (ent instanceof Minecart || ent instanceof Boat) {
        if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            return;
        }
    }
    if (ent instanceof Hanging || ent instanceof ArmorStand) {
        if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            return;
        }
    }
    if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "interact") && !p.hasPermission("redprotect.world.bypass") && (!(ent instanceof Player))) {
        e.setCancelled(true);
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) Hanging(org.spongepowered.api.entity.hanging.Hanging) TNTMinecart(org.spongepowered.api.entity.vehicle.minecart.TNTMinecart) Minecart(org.spongepowered.api.entity.vehicle.minecart.Minecart) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Boat(org.spongepowered.api.entity.vehicle.Boat) Listener(org.spongepowered.api.event.Listener)

Example 2 with Minecart

use of org.spongepowered.api.entity.vehicle.minecart.Minecart 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

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