use of org.spongepowered.api.entity.hanging.Hanging in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onProjectileHit.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onProjectileHit(CollideEntityEvent event, @Root Projectile proj) {
RedProtect.get().logger.debug("entity", "Is CollideEntityEvent(onProjectileHit) event.");
RedProtect.get().logger.debug("entity", "Projectile: " + proj.getType().getName());
if (RedProtect.get().rm.getTopRegion(proj.getLocation()) != null)
return;
for (Entity ent : event.getEntities()) {
RedProtect.get().logger.debug("entity", "Entity: " + ent.getType().getName());
if (proj.getShooter() instanceof Player) {
Player p = (Player) proj.getShooter();
if (ent instanceof Player) {
if (!p.equals(ent) && !RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "pvp") && !p.hasPermission("redprotect.world.bypass")) {
event.setCancelled(true);
return;
}
}
if (ent instanceof Animal || ent instanceof Villager || ent instanceof Golem || ent instanceof Ambient) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "player-hurt-passives") && !p.hasPermission("redprotect.world.bypass")) {
event.setCancelled(true);
return;
}
}
if (ent instanceof Monster) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "player-hurt-monsters") && !p.hasPermission("redprotect.world.bypass")) {
event.setCancelled(true);
return;
}
}
if (ent instanceof Hanging || ent instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass")) {
event.setCancelled(true);
}
}
} else {
if (ent instanceof Hanging || ent instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "entity-block-damage")) {
event.setCancelled(true);
return;
}
}
}
}
}
use of org.spongepowered.api.entity.hanging.Hanging in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onEntityDamageEntity.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEntity(DamageEntityEvent e) {
Entity e1 = e.getTargetEntity();
Entity e2;
RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - e1: " + e1.getType().getName());
Region r = RedProtect.get().rm.getTopRegion(e1.getLocation());
if (e1 instanceof Living && !(e1 instanceof Monster)) {
if (r == null && RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "invincible")) {
e.setCancelled(true);
}
}
if (e.getCause().first(Living.class).isPresent()) {
e2 = e.getCause().first(Living.class).get();
RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - Is DamageEntityEvent event. Damager " + e2.getType().getName());
} else {
return;
}
RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - e1: " + e1.getType().getName() + " - e2: " + e2.getType().getName());
Location<World> loc = e1.getLocation();
Region r1 = RedProtect.get().rm.getTopRegion(loc);
if (r1 != null) {
return;
}
if (e2 instanceof Projectile) {
Projectile proj = (Projectile) e2;
if (proj.getShooter() instanceof Entity) {
e2 = (Entity) proj.getShooter();
}
if (!(e2 instanceof Player)) {
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage")) {
e.setCancelled(true);
return;
}
}
}
}
if (e2 instanceof Creeper || e2 instanceof PrimedTNT || e2 instanceof TNTMinecart) {
if (e1 instanceof Player) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage")) {
e.setCancelled(true);
return;
}
}
}
if (e2 instanceof Player) {
Player p = (Player) e2;
if (e1 instanceof Player) {
if (!e1.equals(e2) && !RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "pvp") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "player-hurt-passives") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "player-hurt-monsters") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Boat || e1 instanceof Minecart) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage") && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
}
}
Aggregations