Search in sources :

Example 6 with Hanging

use of org.bukkit.entity.Hanging in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onEntityDamageEntity.

@EventHandler
public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Entity e1 = e.getEntity();
    Entity e2 = e.getDamager();
    Location loc = e1.getLocation();
    Region r1 = RedProtect.get().rm.getTopRegion(loc);
    if (r1 != null) {
        return;
    }
    if (e2 instanceof Creeper || e2.getType().equals(EntityType.PRIMED_TNT) || e2.getType().equals(EntityType.MINECART_TNT)) {
        if (e1 instanceof Player) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Monster) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
    }
    if (e2 instanceof Player) {
        Player p = (Player) e2;
        if (e.getCause().equals(DamageCause.LIGHTNING) || e.getCause().equals(DamageCause.BLOCK_EXPLOSION) || e.getCause().equals(DamageCause.ENTITY_EXPLOSION)) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".entity-block-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if ((e1 instanceof Minecart || e1 instanceof Boat) && !RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".use-minecart") && !p.hasPermission("redprotect.bypass.world")) {
            e.setCancelled(true);
            return;
        }
        if (e1 instanceof Player) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".pvp") && !p.hasPermission("redprotect.bypass.world")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-passives") && !p.hasPermission("redprotect.bypass.world")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Monster) {
            if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-monsters") && !p.hasPermission("redprotect.bypass.world")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Hanging || e1 instanceof EnderCrystal || e1 instanceof ArmorStand) {
            if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(e1.getType().name()) && !bypassBuild(p, null, 0)) {
                e.setCancelled(true);
                return;
            }
        }
    }
    if (e2 instanceof Projectile) {
        Projectile proj = (Projectile) e2;
        if (proj.getShooter() instanceof Player) {
            Player p = (Player) proj.getShooter();
            if (e1 instanceof Player) {
                if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".pvp") && !p.hasPermission("redprotect.bypass.world")) {
                    e.setCancelled(true);
                    return;
                }
            }
            if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
                if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-passives") && !p.hasPermission("redprotect.bypass.world")) {
                    e.setCancelled(true);
                    return;
                }
            }
            if (e1 instanceof Monster) {
                if (!RPConfig.getGlobalFlagBool(loc.getWorld().getName() + ".player-hurt-monsters") && !p.hasPermission("redprotect.bypass.world")) {
                    e.setCancelled(true);
                    return;
                }
            }
            if (e1 instanceof Hanging || e1 instanceof EnderCrystal || e1 instanceof ArmorStand) {
                if (!RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.break-blocks").contains(e1.getType().name()) && !bypassBuild(p, null, 0)) {
                    e.setCancelled(true);
                }
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Creeper(org.bukkit.entity.Creeper) Minecart(org.bukkit.entity.Minecart) EnderCrystal(org.bukkit.entity.EnderCrystal) Projectile(org.bukkit.entity.Projectile) Golem(org.bukkit.entity.Golem) Animals(org.bukkit.entity.Animals) ArmorStand(org.bukkit.entity.ArmorStand) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Example 7 with Hanging

use of org.bukkit.entity.Hanging in project modules-extra by CubeEngine.

the class ListenerHanging method onHangingBreak.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    if (event.getCause() == HangingBreakEvent.RemoveCause.PHYSICS) {
        Hanging hanging = event.getEntity();
        Location location = hanging.getLocation();
        BaseAction cause = this.plannedHangingBreak.get(location);
        if (cause != null) {
            if (cause instanceof ActionPlayerBlock) {
                HangingBreak action;
                if (hanging instanceof ItemFrame) {
                    action = this.newAction(ItemframeBreak.class, location.getWorld());
                    ItemStack item = ((ItemFrame) hanging).getItem();
                    if (action != null && item != null) {
                        ((ItemframeBreak) action).item = item;
                    }
                } else if (hanging instanceof Painting) {
                    action = this.newAction(PaintingBreak.class, location.getWorld());
                    ((PaintingBreak) action).art = ((Painting) hanging).getArt();
                } else {
                    action = this.newAction(HangingBreak.class, location.getWorld());
                }
                if (action != null) {
                    action.setLocation(location);
                    action.setHanging(hanging);
                    action.player = ((ActionPlayerBlock) cause).player;
                    action.setCause(cause);
                    this.logAction(action);
                }
            }
        // else // TODO
        }
    // else TODO this.module.getLog().info("Unexpected HangingBreakEvent");
    }
}
Also used : ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) Hanging(org.bukkit.entity.Hanging) BaseAction(org.cubeengine.module.log.action.BaseAction) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 8 with Hanging

use of org.bukkit.entity.Hanging in project modules-extra by CubeEngine.

the class ListenerHanging method onHangingBreakByEntity.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
    Entity causer;
    if (event.getRemover() instanceof Projectile) {
        ProjectileSource shooter = ((Projectile) event.getRemover()).getShooter();
        if (shooter instanceof Entity) {
            causer = (Entity) shooter;
        } else {
            // TODO other ProjectileSources
            return;
        }
    } else {
        causer = event.getRemover();
    }
    Hanging hanging = event.getEntity();
    Location location = hanging.getLocation();
    if (causer instanceof Player) {
        HangingBreak action;
        if (hanging instanceof ItemFrame) {
            action = this.newAction(ItemframeBreak.class, location.getWorld());
            ItemStack item = ((ItemFrame) hanging).getItem();
            if (action != null && item != null) {
                ((ItemframeBreak) action).item = item;
            }
        } else if (hanging instanceof Painting) {
            action = this.newAction(PaintingBreak.class, location.getWorld());
            if (action != null) {
                ((PaintingBreak) action).art = ((Painting) hanging).getArt();
            }
        } else {
            action = this.newAction(HangingBreak.class, location.getWorld());
        }
        if (action != null) {
            action.setLocation(location);
            action.setHanging(hanging);
            action.setPlayer((Player) causer);
            this.logAction(action);
        }
    } else {
    // TODO
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.player.Player) Hanging(org.bukkit.entity.Hanging) ProjectileSource(org.bukkit.projectiles.ProjectileSource) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Projectile(org.bukkit.entity.Projectile) Location(org.spongepowered.api.world.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Hanging

use of org.bukkit.entity.Hanging in project Glowstone by GlowstoneMC.

the class GlowPainting method isObstructed.

/**
 * Check if the painting is obstructed at the current location.
 *
 * <p>Survivability is defined as:
 * <ul>
 *     <li>The wall behind the painting is completely solid</li>
 *     <li>The painting is not inside a block</li>
 *     <li>The painting is not inside another entity</li>
 * </ul>
 *
 * @return true if the painting should drop, false otherwise
 */
public boolean isObstructed() {
    Location current = getTopLeftCorner();
    BlockFace right = getRightFace();
    for (int y = 0; y < art.getBlockHeight(); y++) {
        for (int x = 0; x < art.getBlockWidth(); x++) {
            if (!canHoldPainting(current)) {
                return true;
            }
            current = current.getBlock().getRelative(right).getLocation();
        }
        current = current.getBlock().getRelative(BlockFace.DOWN).getLocation();
        // reset x and z
        current.subtract(right.getModX() * art.getBlockWidth(), 0, right.getModZ() * art.getBlockWidth());
    }
    List<Entity> entitiesInside = this.world.getEntityManager().getEntitiesInside(this.boundingBox, this);
    return entitiesInside.stream().anyMatch(e -> e instanceof Hanging);
}
Also used : Entity(org.bukkit.entity.Entity) GlowHangingEntity(net.glowstone.entity.GlowHangingEntity) Hanging(org.bukkit.entity.Hanging) BlockFace(org.bukkit.block.BlockFace) Location(org.bukkit.Location)

Example 10 with Hanging

use of org.bukkit.entity.Hanging in project RedProtect by FabioZumbi12.

the class RPEntityListener method entityFire.

@EventHandler(priority = EventPriority.HIGHEST)
public void entityFire(EntityCombustByEntityEvent e) {
    Entity e1 = e.getEntity();
    Entity e2 = e.getCombuster();
    if (e2 == null) {
        return;
    }
    RedProtect.get().logger.debug("EntityCombustByEntityEvent - Is EntityCombustByEntityEvent event.");
    if (e2 instanceof Projectile) {
        Projectile a = (Projectile) e2;
        if (a.getShooter() instanceof Entity) {
            e2 = (Entity) a.getShooter();
        }
        a = null;
        if (e2 == null) {
            return;
        }
    }
    Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
    Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
    if (r1 != null && !r1.canFire() && !(e2 instanceof Player)) {
        e.setCancelled(true);
        return;
    }
    if (e1 instanceof Player) {
        if (e2 instanceof Player && !e1.equals(e2)) {
            Player p2 = (Player) e2;
            if (r1 != null) {
                if (r2 != null) {
                    if ((r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) || (r1.flagExists("pvp") && !r2.canPVP((Player) e1, p2))) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                    }
                } else if (r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                }
            } else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP((Player) e1, p2)) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
            }
        }
    } else if (e1 instanceof Animals || e1 instanceof Villager || e1 instanceof Golem) {
        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) && !r1.canBreak(e1.getType())) {
            e.setCancelled(true);
            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
            return;
        }
        if (r2 != null && !r2.canBuild(p2) && !r2.canBreak(e1.getType())) {
            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("Cancelled ItemFrame drop Item");
            e.setCancelled(true);
        }
    } else if (e2 instanceof Explosive) {
        if ((r1 != null && !r1.canFire()) || (r2 != null && !r2.canFire())) {
            e.setCancelled(true);
        }
    }
}
Also used : Golem(org.bukkit.entity.Golem) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Explosive(org.bukkit.entity.Explosive) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Hanging (org.bukkit.entity.Hanging)19 EventHandler (org.bukkit.event.EventHandler)11 Entity (org.bukkit.entity.Entity)9 Location (org.bukkit.Location)8 Player (org.bukkit.entity.Player)8 LivingEntity (org.bukkit.entity.LivingEntity)7 Projectile (org.bukkit.entity.Projectile)7 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)5 Painting (org.bukkit.entity.Painting)4 BlockFace (org.bukkit.block.BlockFace)3 Animals (org.bukkit.entity.Animals)3 Minecart (org.bukkit.entity.Minecart)3 Monster (org.bukkit.entity.Monster)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)2 Block (org.bukkit.block.Block)2 ArmorStand (org.bukkit.entity.ArmorStand)2 Boat (org.bukkit.entity.Boat)2 EnderCrystal (org.bukkit.entity.EnderCrystal)2 Golem (org.bukkit.entity.Golem)2 ItemFrame (org.bukkit.entity.ItemFrame)2