Search in sources :

Example 1 with Hanging

use of org.spongepowered.api.entity.hanging.Hanging 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 Hanging

use of org.spongepowered.api.entity.hanging.Hanging 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 3 with Hanging

use of org.spongepowered.api.entity.hanging.Hanging in project RedProtect by FabioZumbi12.

the class RPPlayerListener method onEntityDamageEvent.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEvent(DamageEntityEvent e) {
    // victim
    Entity e1 = e.getTargetEntity();
    // damager
    Entity e2 = null;
    if (e.getCause().first(IndirectEntityDamageSource.class).isPresent()) {
        e2 = e.getCause().first(IndirectEntityDamageSource.class).get().getSource();
        RedProtect.get().logger.debug("player", "RPLayerListener: Is DamageEntityEvent event. Damager " + e2.getType().getName());
    }
    Player damager = null;
    if (e2 instanceof Projectile) {
        Projectile proj = (Projectile) e2;
        if (proj.getShooter() instanceof Player) {
            damager = (Player) proj.getShooter();
        }
    } else if (e2 instanceof Player) {
        damager = (Player) e2;
    }
    Location<World> l = e1.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r == null) {
        return;
    }
    RedProtect.get().logger.debug("player", "RPLayerListener: Is DamageEntityEvent event. Victim " + e1.getType().getName());
    if (damager instanceof Player) {
        if (e1 instanceof Hanging && !r.canBuild(damager)) {
            RPLang.sendMessage(damager, "entitylistener.region.cantinteract");
            e.setCancelled(true);
            return;
        }
        if (e1 instanceof Player && r.flagExists("pvp") && !r.canPVP(damager)) {
            RPLang.sendMessage(damager, "entitylistener.region.cantpvp");
            e.setCancelled(true);
            return;
        }
    }
    // return if not player
    if (!(e1 instanceof Player)) {
        return;
    }
    Player play = (Player) e.getTargetEntity();
    if (RedProtect.get().tpWait.contains(play.getName())) {
        RedProtect.get().tpWait.remove(play.getName());
        RPLang.sendMessage(play, RPLang.get("cmdmanager.region.tpcancelled"));
    }
    if (r != null && !r.canPlayerDamage()) {
        e.setCancelled(true);
    }
    // execute on health
    if (r.cmdOnHealth(play)) {
        RedProtect.get().logger.debug("player", "Cmd on healt: true");
    }
    if (!r.canDeath() && play.get(Keys.HEALTH).get() <= 1) {
        e.setCancelled(true);
    }
    // deny damagecauses
    List<String> Causes = RedProtect.get().cfgs.getStringList("server-protection.deny-playerdeath-by");
    if (e.getCause().containsType(DamageSource.class) && Causes.size() > 0) {
        DamageType damagec = e.getCause().first(DamageSource.class).get().getType();
        for (String cause : Causes) {
            if (damagec.getName().equalsIgnoreCase(cause)) {
                e.setCancelled(true);
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Hanging(org.spongepowered.api.entity.hanging.Hanging) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) World(org.spongepowered.api.world.World) DamageType(org.spongepowered.api.event.cause.entity.damage.DamageType) Projectile(org.spongepowered.api.entity.projectile.Projectile) Listener(org.spongepowered.api.event.Listener)

Example 4 with Hanging

use of org.spongepowered.api.entity.hanging.Hanging in project RedProtect by FabioZumbi12.

the class RPPlayerListener method onPlayerInteract.

/*
    @Listener(order = Order.FIRST, beforeModifications = true)
    public void MoveItem(ClickInventoryEvent e, @First Player p){
    	Container cont = e.getTargetInventory().getProperties(Names.);
    	
    	Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    	if (r != null && e.getInventory().getTitle() != null){
    		if (r.getName().length() > 16){
        		if (e.getInventory().getTitle().equals(RPLang.get("gui.invflag").replace("{region}", r.getName().substring(0, 16)))){
            		return;
            	}
        	} else {
        		if (e.getInventory().getTitle().equals(RPLang.get("gui.invflag").replace("{region}", r.getName())) || e.getInventory().getTitle().equals(RPLang.get("gui.editflag"))){
            		return;
            	}
        	}
    	}    	
    	
    	if (RPUtil.RemoveGuiItem(e.getCurrentItem())){
    		e.setCurrentItem(new ItemStack(Material.AIR));
    	}
    }
    	*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEntityEvent e, @First Player p) {
    Entity ent = e.getTargetEntity();
    RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractEntityEvent event: " + ent.getType().getName());
    Location<World> l = ent.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r == null) {
        return;
    }
    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }
    if (ent instanceof Hanging || ent.getType().equals(EntityTypes.ARMOR_STAND)) {
        if (!r.canBuild(p)) {
            RPLang.sendMessage(p, "playerlistener.region.cantedit");
            e.setCancelled(true);
        }
    } else if ((ent.getType().getName().contains("minecart") || ent.getType().getName().contains("boat")) && !r.canMinecart(p)) {
        RPLang.sendMessage(p, "blocklistener.region.cantenter");
        e.setCancelled(true);
    } else if (!r.allowMod(p) && !RPUtil.isBukkitEntity(ent) && (!(ent instanceof Player))) {
        RedProtect.get().logger.debug("player", "PlayerInteractEntityEvent - Block is " + ent.getType().getName());
        RPLang.sendMessage(p, "playerlistener.region.cantinteract");
        e.setCancelled(true);
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Hanging(org.spongepowered.api.entity.hanging.Hanging) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 5 with Hanging

use of org.spongepowered.api.entity.hanging.Hanging in project RedProtect by FabioZumbi12.

the class RPBlockListener method onFrameAndBoatBrake.

/*
    @Listener
    public void onEntityExplode(ExplosionEvent.Detonate e) {
    	RedProtect.get().logger.debug("Is BlockListener - ExplosionEvent.Detonate event");
    	
        for (Transaction<BlockSnapshot> bl:e.getTransactions()) {
        	BlockSnapshot b = bl.getOriginal();
        	RedProtect.get().logger.debug("Blocks: "+b.getState().getType().getName());
        	
        	Location<World> l = b.getLocation().get();
        	Region r = RedProtect.get().rm.getTopRegion(l);
        	if (!cont.canWorldBreak(b)){
        		RedProtect.get().logger.debug("canWorldBreak Called!");
        		bl.setValid(false);
        		//toRemove.add(bl);
        		continue;
        	}        	
        	if (r == null){
        		continue;
        	}
        	
        	if ((b.getState().getType().getName().contains("tnt") || e.getCause().first(Lightning.class).isPresent()) && !r.canFire()){
        		//toRemove.add(bl);
        		bl.setValid(false);
    			continue;
        	}  
        	
        	if (e.getCause().first(Living.class).isPresent() && !r.canMobLoot()){
        		//toRemove.add(bl);
        		bl.setValid(false);
        		continue;
        	}
        	
        }
        /*if (!toRemove.isEmpty()){
        	e.getTransactions().removeAll(toRemove);
        }
        
    }*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFrameAndBoatBrake(DamageEntityEvent e) {
    RedProtect.get().logger.debug("blocks", "Is BlockListener - DamageEntityEvent event");
    Entity ent = e.getTargetEntity();
    Location<World> l = e.getTargetEntity().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (ent instanceof Hanging && e.getCause().first(Monster.class).isPresent()) {
        if (r != null && !r.canFire()) {
            e.setCancelled(true);
            return;
        }
    }
    if (ent instanceof Boat && e.getCause().first(Player.class).isPresent()) {
        Player p = e.getCause().first(Player.class).get();
        if (!r.canMinecart(p)) {
            RPLang.sendMessage(p, "blocklistener.region.cantbreak");
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Hanging(org.spongepowered.api.entity.hanging.Hanging) 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)

Aggregations

Entity (org.spongepowered.api.entity.Entity)7 Hanging (org.spongepowered.api.entity.hanging.Hanging)7 Player (org.spongepowered.api.entity.living.player.Player)7 Listener (org.spongepowered.api.event.Listener)7 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)6 World (org.spongepowered.api.world.World)5 Ambient (org.spongepowered.api.entity.living.Ambient)3 ArmorStand (org.spongepowered.api.entity.living.ArmorStand)3 Villager (org.spongepowered.api.entity.living.Villager)3 Animal (org.spongepowered.api.entity.living.animal.Animal)3 Golem (org.spongepowered.api.entity.living.golem.Golem)3 Monster (org.spongepowered.api.entity.living.monster.Monster)3 Projectile (org.spongepowered.api.entity.projectile.Projectile)3 Boat (org.spongepowered.api.entity.vehicle.Boat)3 Living (org.spongepowered.api.entity.living.Living)2 Minecart (org.spongepowered.api.entity.vehicle.minecart.Minecart)2 TNTMinecart (org.spongepowered.api.entity.vehicle.minecart.TNTMinecart)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