use of org.bukkit.entity.Hanging 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.Hanging in project modules-extra by CubeEngine.
the class ListenerHanging method onHangingBreak.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
if (event.getCause() == HangingBreakEvent.RemoveCause.PHYSICS) {
Hanging hanging = event.getEntity();
Location location = hanging.getLocation();
BaseAction cause = this.plannedHangingBreak.get(location);
if (cause != null) {
if (cause instanceof ActionPlayerBlock) {
HangingBreak action;
if (hanging instanceof ItemFrame) {
action = this.newAction(ItemframeBreak.class, location.getWorld());
ItemStack item = ((ItemFrame) hanging).getItem();
if (action != null && item != null) {
((ItemframeBreak) action).item = item;
}
} else if (hanging instanceof Painting) {
action = this.newAction(PaintingBreak.class, location.getWorld());
((PaintingBreak) action).art = ((Painting) hanging).getArt();
} else {
action = this.newAction(HangingBreak.class, location.getWorld());
}
if (action != null) {
action.setLocation(location);
action.setHanging(hanging);
action.player = ((ActionPlayerBlock) cause).player;
action.setCause(cause);
this.logAction(action);
}
}
// else // TODO
}
// else TODO this.module.getLog().info("Unexpected HangingBreakEvent");
}
}
use of org.bukkit.entity.Hanging in project modules-extra by CubeEngine.
the class ListenerHanging method onHangingBreakByEntity.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
Entity causer;
if (event.getRemover() instanceof Projectile) {
ProjectileSource shooter = ((Projectile) event.getRemover()).getShooter();
if (shooter instanceof Entity) {
causer = (Entity) shooter;
} else {
// TODO other ProjectileSources
return;
}
} else {
causer = event.getRemover();
}
Hanging hanging = event.getEntity();
Location location = hanging.getLocation();
if (causer instanceof Player) {
HangingBreak action;
if (hanging instanceof ItemFrame) {
action = this.newAction(ItemframeBreak.class, location.getWorld());
ItemStack item = ((ItemFrame) hanging).getItem();
if (action != null && item != null) {
((ItemframeBreak) action).item = item;
}
} else if (hanging instanceof Painting) {
action = this.newAction(PaintingBreak.class, location.getWorld());
if (action != null) {
((PaintingBreak) action).art = ((Painting) hanging).getArt();
}
} else {
action = this.newAction(HangingBreak.class, location.getWorld());
}
if (action != null) {
action.setLocation(location);
action.setHanging(hanging);
action.setPlayer((Player) causer);
this.logAction(action);
}
} else {
// TODO
}
}
use of org.bukkit.entity.Hanging in project Glowstone by GlowstoneMC.
the class GlowPainting method isObstructed.
/**
* Check if the painting is obstructed at the current location.
*
* <p>Survivability is defined as:
* <ul>
* <li>The wall behind the painting is completely solid</li>
* <li>The painting is not inside a block</li>
* <li>The painting is not inside another entity</li>
* </ul>
*
* @return true if the painting should drop, false otherwise
*/
public boolean isObstructed() {
Location current = getTopLeftCorner();
BlockFace right = getRightFace();
for (int y = 0; y < art.getBlockHeight(); y++) {
for (int x = 0; x < art.getBlockWidth(); x++) {
if (!canHoldPainting(current)) {
return true;
}
current = current.getBlock().getRelative(right).getLocation();
}
current = current.getBlock().getRelative(BlockFace.DOWN).getLocation();
// reset x and z
current.subtract(right.getModX() * art.getBlockWidth(), 0, right.getModZ() * art.getBlockWidth());
}
List<Entity> entitiesInside = this.world.getEntityManager().getEntitiesInside(this.boundingBox, this);
return entitiesInside.stream().anyMatch(e -> e instanceof Hanging);
}
use of org.bukkit.entity.Hanging 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);
}
}
}
Aggregations