use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class AirSupplyAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity entity = context.getTargetEntity();
if (entity == null || !(entity instanceof LivingEntity)) {
return SpellResult.NO_TARGET;
}
LivingEntity livingEntity = (LivingEntity) entity;
int airLevel = air;
if (airLevel > livingEntity.getMaximumAir()) {
airLevel = livingEntity.getMaximumAir();
}
context.registerModified(livingEntity);
livingEntity.setRemainingAir(airLevel);
return SpellResult.CAST;
}
use of org.bukkit.entity.LivingEntity 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.LivingEntity 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);
}
}
}
use of org.bukkit.entity.LivingEntity in project RedProtect by FabioZumbi12.
the class McMMoListener method onPlayerActivateAbillity.
@EventHandler
public void onPlayerActivateAbillity(McMMOPlayerAbilityActivateEvent e) {
if (e.isCancelled()) {
return;
}
RedProtect.get().logger.debug("Mcmmo McMMOPlayerAbilityActivateEvent event.");
Player p = e.getPlayer();
// try to fix invisibility on bersek
if (RPConfig.getBool("hooks.mcmmo.fix-berserk-invisibility") && e.getAbility().equals(AbilityType.BERSERK)) {
p.damage(0);
for (Entity ent : p.getNearbyEntities(10, 10, 10)) {
if (ent instanceof LivingEntity) {
((LivingEntity) ent).damage(0);
}
}
}
Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
if (r == null) {
return;
}
if (!r.canSkill(p)) {
p.sendMessage(RPLang.get("mcmmolistener.notallowed"));
e.setCancelled(true);
}
if (!r.canPVP(p, null) && (e.getSkill().equals(SkillType.SWORDS) || e.getSkill().equals(SkillType.UNARMED))) {
e.setCancelled(true);
}
}
use of org.bukkit.entity.LivingEntity in project RedProtect by FabioZumbi12.
the class RPBlockListener method onEntityExplode.
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent e) {
RedProtect.get().logger.debug("Is BlockListener - EntityExplodeEvent event");
List<Block> toRemove = new ArrayList<>();
if (e.getEntity() == null) {
return;
}
Region or = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());
for (Block b : e.blockList()) {
if (b == null) {
continue;
}
RedProtect.get().logger.debug("Blocks: " + b.getType().name());
Location l = b.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canFire() || !cont.canWorldBreak(b)) {
RedProtect.get().logger.debug("canWorldBreak Called!");
// e.setCancelled(true);
toRemove.add(b);
continue;
}
if (r == null) {
continue;
}
if (r != or) {
toRemove.add(b);
continue;
}
if (e.getEntity() instanceof LivingEntity && !r.canMobLoot()) {
toRemove.add(b);
}
}
if (!toRemove.isEmpty()) {
e.blockList().removeAll(toRemove);
}
}
Aggregations