Search in sources :

Example 76 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPBlockListener method onInteractPrimBlock.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractPrimBlock(InteractBlockEvent.Primary event, @First Player p) {
    BlockSnapshot b = event.getTargetBlock();
    RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent.Primary event");
    if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
        if (b.getState().getType().getName().contains("sign") && !cont.canBreak(p, b)) {
            RPLang.sendMessage(p, "blocklistener.container.breakinside");
            event.setCancelled(true);
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Example 77 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPEntityListener method WitherBlockBreak.

@Listener(order = Order.FIRST, beforeModifications = true)
public void WitherBlockBreak(ChangeBlockEvent.Break event, @First Entity e) {
    if (e instanceof Monster) {
        BlockSnapshot b = event.getTransactions().get(0).getOriginal();
        RedProtect.get().logger.debug("entity", "RPEntityListener - Is EntityChangeBlockEvent event! Block " + b.getState().getType().getName());
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
        if (!cont.canWorldBreak(b)) {
            event.setCancelled(true);
            return;
        }
        if (r != null && !r.canMobLoot()) {
            event.setCancelled(true);
        }
    }
}
Also used : Monster(org.spongepowered.api.entity.living.monster.Monster) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 78 with Listener

use of org.spongepowered.api.event.Listener 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 79 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPEntityListener method onPotionSplash.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onPotionSplash(LaunchProjectileEvent event) {
    if (event.getTargetEntity() instanceof ThrownPotion) {
        ThrownPotion potion = (ThrownPotion) event.getTargetEntity();
        ProjectileSource thrower = potion.getShooter();
        RedProtect.get().logger.debug("entity", "RPEntityListener - LaunchProjectileEvent entity " + event.getTargetEntity().getType().getName());
        List<PotionEffect> pottypes = potion.get(Keys.POTION_EFFECTS).get();
        for (PotionEffect t : pottypes) {
            if (!t.getType().equals(PotionEffectTypes.BLINDNESS) && !t.equals(PotionEffectTypes.WEAKNESS) && !t.equals(PotionEffectTypes.NAUSEA) && !t.equals(PotionEffectTypes.HUNGER) && !t.equals(PotionEffectTypes.POISON) && !t.equals(PotionEffectTypes.MINING_FATIGUE) && !t.equals(PotionEffectTypes.HASTE) && !t.equals(PotionEffectTypes.SLOWNESS) && !t.equals(PotionEffectTypes.WITHER)) {
                return;
            }
        }
        Player shooter;
        if (thrower instanceof Player) {
            shooter = (Player) thrower;
        } else {
            return;
        }
        RedProtect.get().logger.debug("entity", "RPEntityListener - LaunchProjectileEvent shooter " + shooter.getName());
        Entity e2 = event.getTargetEntity();
        Region r = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (e2 instanceof Player) {
            if (r != null && r.flagExists("pvp") && !r.canPVP(shooter)) {
                event.setCancelled(true);
            }
        } else {
            if (r != null && !r.canInteractPassives(shooter)) {
                event.setCancelled(true);
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ThrownPotion(org.spongepowered.api.entity.projectile.ThrownPotion) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) Listener(org.spongepowered.api.event.Listener)

Example 80 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method PlayerDropItem.

@Listener(order = Order.FIRST, beforeModifications = true)
public void PlayerDropItem(DropItemEvent.Dispense e, @Root Player p) {
    for (Entity ent : e.getEntities()) {
        Location<World> l = ent.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r == null && !RedProtect.get().cfgs.getGlobalFlag(l.getExtent().getName(), "player-candrop") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Aggregations

Listener (org.spongepowered.api.event.Listener)360 Player (org.spongepowered.api.entity.living.player.Player)118 World (org.spongepowered.api.world.World)97 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)65 Entity (org.spongepowered.api.entity.Entity)58 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)46 Text (org.spongepowered.api.text.Text)46 ItemStack (org.spongepowered.api.item.inventory.ItemStack)45 Location (org.spongepowered.api.world.Location)45 Sponge (org.spongepowered.api.Sponge)22 BlockType (org.spongepowered.api.block.BlockType)22 Task (org.spongepowered.api.scheduler.Task)17 IOException (java.io.IOException)16 Optional (java.util.Optional)16 Living (org.spongepowered.api.entity.living.Living)15 ItemType (org.spongepowered.api.item.ItemType)15 UUID (java.util.UUID)14 Monster (org.spongepowered.api.entity.living.monster.Monster)14 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)14 Map (java.util.Map)13