Search in sources :

Example 1 with Hanging

use of org.bukkit.entity.Hanging in project Denizen-For-Bukkit by DenizenScript.

the class BukkitScriptEvent method tryEntity.

public boolean tryEntity(dEntity entity, String comparedto) {
    if (comparedto == null || comparedto.isEmpty() || entity == null) {
        return false;
    }
    Entity bEntity = entity.getBukkitEntity();
    comparedto = CoreUtilities.toLowerCase(comparedto);
    if (comparedto.equals("entity")) {
        return true;
    } else if (comparedto.equals("npc")) {
        return entity.isCitizensNPC();
    } else if (comparedto.equals("player")) {
        return entity.isPlayer();
    } else if (comparedto.equals("vehicle")) {
        return bEntity instanceof Vehicle;
    } else if (comparedto.equals("projectile")) {
        return bEntity instanceof Projectile;
    } else if (comparedto.equals("hanging")) {
        return bEntity instanceof Hanging;
    } else if (entity.getEntityScript() != null && comparedto.equals(CoreUtilities.toLowerCase(entity.getEntityScript()))) {
        return true;
    } else if (comparedto.equals(entity.getEntityType().getLowercaseName())) {
        return true;
    }
    return false;
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Entity(org.bukkit.entity.Entity) Hanging(org.bukkit.entity.Hanging) Projectile(org.bukkit.entity.Projectile)

Example 2 with Hanging

use of org.bukkit.entity.Hanging in project MagicPlugin by elBukkit.

the class HangingController method onHangingBreak.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    final Hanging entity = event.getEntity();
    if (!entity.isValid())
        return;
    try {
        final BlockFace attachedFace = entity.getAttachedFace();
        Location location = entity.getLocation();
        UndoList undoList = controller.getPendingUndo(location);
        if (undoList != null) {
            event.setCancelled(true);
            undoList.damage(entity);
        } else {
            location = location.getBlock().getRelative(attachedFace).getLocation();
            undoList = controller.getPendingUndo(location);
            if (undoList != null) {
                event.setCancelled(true);
                undoList.damage(entity);
            }
        }
    } catch (Exception ex) {
        controller.getLogger().log(Level.WARNING, "Failed to handle HangingBreakEvent", ex);
    }
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Hanging(org.bukkit.entity.Hanging) BlockFace(org.bukkit.block.BlockFace) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Hanging

use of org.bukkit.entity.Hanging in project MagicPlugin by elBukkit.

the class VelocityAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (entity instanceof Hanging) {
        return SpellResult.NO_TARGET;
    }
    Entity mountEntity = entity.getVehicle();
    while (mountEntity != null) {
        entity = mountEntity;
        mountEntity = entity.getVehicle();
    }
    double magnitude = defaultSpeed;
    if (entity instanceof LivingEntity) {
        magnitude = livingEntitySpeed;
    } else if (entity instanceof Item) {
        magnitude = itemSpeed;
    }
    if (minSpeed > 0 || maxSpeed > 0) {
        int height = 0;
        Block playerBlock = context.getLocation().getBlock();
        while (height < maxSpeedAtElevation && playerBlock.getType() == Material.AIR) {
            playerBlock = playerBlock.getRelative(BlockFace.DOWN);
            height++;
        }
        double heightModifier = maxSpeedAtElevation > 0 ? ((double) height / maxSpeedAtElevation) : 1;
        magnitude = (minSpeed + ((maxSpeed - minSpeed) * heightModifier));
    }
    Vector velocity = direction == null ? context.getDirection() : direction.clone();
    if (pushDirection != 0) {
        Location to = entity.getLocation();
        Location from = context.getLocation();
        Vector toVector = new Vector(to.getBlockX(), to.getBlockY(), to.getBlockZ());
        Vector fromVector = new Vector(from.getBlockX(), from.getBlockY(), from.getBlockZ());
        velocity = toVector;
        velocity.subtract(fromVector);
        double distanceSquared = velocity.lengthSquared();
        if (distanceSquared < Double.MIN_NORMAL) {
            velocity = context.getDirection();
        }
        double speed = pushDirection;
        if (maxDistanceSquared > 0) {
            if (distanceSquared > maxDistanceSquared) {
                return SpellResult.NO_TARGET;
            }
            if (distanceSquared > 0) {
                speed = speed * (1 - distanceSquared / maxDistanceSquared);
            }
        }
        velocity.normalize().multiply(speed);
    }
    if (context.getLocation().getBlockY() >= 256) {
        velocity.setY(0);
    } else if (yOffset != 0) {
        velocity.setY(velocity.getY() + yOffset);
    }
    velocity.multiply(magnitude);
    if (additive) {
        velocity = entity.getVelocity().clone().add(velocity);
    }
    if (maxMagnitudeSquared != 0D && velocity.lengthSquared() > maxMagnitudeSquared) {
        velocity = velocity.normalize().multiply(maxMagnitude);
        magnitude = maxMagnitude;
    }
    if (registerDamaged) {
        context.registerDamaged(entity);
    }
    context.registerVelocity(entity);
    context.registerMoved(entity);
    if (exemptionDuration > 0 && entity instanceof Player) {
        context.getController().addFlightExemption((Player) entity, exemptionDuration);
    }
    context.getMage().sendDebugMessage(ChatColor.AQUA + "Applying velocity of " + ChatColor.BLUE + velocity + ChatColor.AQUA + " to " + ChatColor.DARK_AQUA + entity.getType() + ChatColor.AQUA + " from magnitude of " + ChatColor.BLUE + magnitude, 11);
    if (!MathUtils.isFinite(velocity.getX()) || !MathUtils.isFinite(velocity.getY()) || !MathUtils.isFinite(velocity.getZ())) {
        context.getMage().sendDebugMessage(ChatColor.AQUA + "Invalid velocity!" + ChatColor.BLUE + velocity + ChatColor.AQUA + "Context direction: " + ChatColor.DARK_AQUA + context.getDirection() + ChatColor.AQUA + "direction: " + ChatColor.DARK_AQUA + direction);
    } else {
        SafetyUtils.setVelocity(entity, velocity);
    }
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) Hanging(org.bukkit.entity.Hanging) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 4 with Hanging

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

the class RPEntityListener method onEntityDamage.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Entity ent = e.getEntity();
    Region r = RedProtect.get().rm.getTopRegion(ent.getLocation());
    if (ent instanceof LivingEntity && !(ent instanceof Monster)) {
        if (r != null && r.flagExists("invincible")) {
            if (r.getFlagBool("invincible")) {
                if (ent instanceof Animals) {
                    ((Animals) ent).setTarget(null);
                }
                e.setCancelled(true);
            }
        }
    }
    if (e instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent de = (EntityDamageByEntityEvent) e;
        Entity e1 = de.getEntity();
        Entity e2 = de.getDamager();
        if (e2 == null) {
            return;
        }
        RedProtect.get().logger.debug("RPEntityListener - Is EntityDamageByEntityEvent event. Damager: " + e2.getType().name());
        if (e2 instanceof Projectile) {
            Projectile a = (Projectile) e2;
            if (a.getShooter() instanceof Entity) {
                e2 = (Entity) a.getShooter();
            }
            a = null;
            if (e2 == null) {
                return;
            }
        }
        RedProtect.get().logger.debug("EntityDamageByEntityEvent event. Damager Player: " + e2.getType().name());
        RedProtect.get().logger.debug("Cause: " + de.getCause().name());
        Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
        Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (de.getCause().equals(DamageCause.LIGHTNING) || de.getCause().equals(DamageCause.BLOCK_EXPLOSION) || de.getCause().equals(DamageCause.FIRE) || de.getCause().equals(DamageCause.WITHER) || de.getCause().equals(DamageCause.CUSTOM) || de.getCause().equals(DamageCause.ENTITY_EXPLOSION)) {
            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) {
                    Material mp2 = p2.getItemInHand().getType();
                    if (RedProtect.get().version >= 190) {
                        if (p2.getInventory().getItemInMainHand() != null) {
                            mp2 = p2.getInventory().getItemInMainHand().getType();
                        } else {
                            mp2 = p2.getInventory().getItemInOffHand().getType();
                        }
                    }
                    if (mp2.equals(Material.EGG) && !r1.canProtectiles(p2)) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                        return;
                    }
                    if (r2 != null) {
                        if (mp2.equals(Material.EGG) && !r2.canProtectiles(p2)) {
                            e.setCancelled(true);
                            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                            return;
                        }
                        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 : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Material(org.bukkit.Material) Projectile(org.bukkit.entity.Projectile) LivingEntity(org.bukkit.entity.LivingEntity) Golem(org.bukkit.entity.Golem) Animals(org.bukkit.entity.Animals) Explosive(org.bukkit.entity.Explosive) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Hanging

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

the class RPEntityListener method onCreatureSpawn.

@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event.isCancelled()) {
        return;
    }
    Entity e = event.getEntity();
    if (e == null) {
        return;
    }
    RedProtect.get().logger.debug("Spawn monster " + event.getEntityType().name());
    if (e instanceof Wither && event.getSpawnReason().equals(SpawnReason.BUILD_WITHER)) {
        Location l = event.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canSpawnWhiter()) {
            event.isCancelled();
            return;
        }
    }
    if (e instanceof Monster) {
        Location l = event.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canSpawnMonsters()) {
            RedProtect.get().logger.debug("Cancelled spawn of monster " + event.getEntityType().name());
            event.setCancelled(true);
        }
    }
    if (e instanceof LivingEntity && (!(e instanceof Monster) && !(e instanceof Player)) && (RedProtect.get().version >= 180 && !(e instanceof ArmorStand)) && !(e instanceof Hanging)) {
        Location l = event.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canSpawnPassives()) {
            RedProtect.get().logger.debug("Cancelled spawn of animal " + event.getEntityType().name());
            event.setCancelled(true);
        }
    }
}
Also used : Wither(org.bukkit.entity.Wither) LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ArmorStand(org.bukkit.entity.ArmorStand) Hanging(org.bukkit.entity.Hanging) Monster(org.bukkit.entity.Monster) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) 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