use of org.bukkit.entity.Golem 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.Golem in project RedProtect by FabioZumbi12.
the class RPEntityListener method onInteractEvent.
@EventHandler
public void onInteractEvent(PlayerInteractEntityEvent e) {
RedProtect.get().logger.debug("RPEntityListener - Is PlayerInteractEntityEvent");
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
if (p == null) {
return;
}
Location l = e.getRightClicked().getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
Entity et = e.getRightClicked();
if (r != null && !r.canInteractPassives(p) && (et instanceof Animals || et instanceof Villager || et instanceof Golem)) {
if (et instanceof Tameable) {
Tameable tam = (Tameable) et;
if (tam.isTamed() && tam.getOwner() != null && tam.getOwner().getName().equals(p.getName())) {
return;
}
}
e.setCancelled(true);
RPLang.sendMessage(p, "entitylistener.region.cantinteract");
}
}
use of org.bukkit.entity.Golem 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);
}
}
}
}
}
use of org.bukkit.entity.Golem 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);
}
}
}
use of org.bukkit.entity.Golem in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onCreatureSpawn.
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
RedProtect.get().logger.debug("RPGlobalListener - Is CreatureSpawnEvent event! Cancelled? " + event.isCancelled());
if (event.isCancelled()) {
return;
}
Entity e = event.getEntity();
if (e == null) {
return;
}
Location l = event.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null) {
return;
}
if (e instanceof Wither && event.getSpawnReason().equals(SpawnReason.BUILD_WITHER) && !RPConfig.getGlobalFlagBool(e.getWorld().getName() + ".spawn-wither")) {
event.setCancelled(true);
return;
}
if (e instanceof Monster && !RPConfig.getGlobalFlagBool(e.getWorld().getName() + ".spawn-monsters")) {
if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CHUNK_GEN) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.DEFAULT)) {
event.setCancelled(true);
return;
}
}
if ((e instanceof Animals || e instanceof Villager || e instanceof Golem) && !RPConfig.getGlobalFlagBool(e.getWorld().getName() + ".spawn-passives")) {
if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CHUNK_GEN) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.DEFAULT)) {
event.setCancelled(true);
}
}
}
Aggregations