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;
}
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);
}
}
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;
}
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);
}
}
}
}
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);
}
}
}
Aggregations