@EventHandler(priority = EventPriority.HIGH) public void onEntityExplode(EntityExplodeEvent event) { if (War.isWarTime()) { event.setCancelled(false); } else { event.setCancelled(true); return; } if (event.isCancelled()) { return; } if (event.getEntity() == null) { return; } if (event.getEntityType().equals(EntityType.UNKNOWN)) { return; } if (event.getEntityType().equals(EntityType.PRIMED_TNT) || event.getEntityType().equals(EntityType.MINECART_TNT)) { HashSet<Buildable> structuresHit = new HashSet<Buildable>(); for (int y = -yield; y <= yield; y++) { for (int x = -yield; x <= yield; x++) { for (int z = -yield; z <= yield; z++) { Location loc = event.getLocation().clone().add(new Vector(x, y, z)); Block b = loc.getBlock(); if (loc.distance(event.getLocation()) < yield) { BlockCoord bcoord = new BlockCoord(); bcoord.setFromLocation(loc); // StructureBlock sb = CivGlobal.getStructureBlock(bcoord); // if (sb == null) { // WarRegen.saveBlock(loc.getBlock(), Cannon.RESTORE_NAME, false); // } // if (sb.getTown() != null) { // WarRegen.destroyThisBlock(loc.getBlock(), sb.getTown()); // } else { // ItemManager.setTypeIdAndData(loc.getBlock(), CivData.AIR, 0, false); // } StructureBlock sb = CivGlobal.getStructureBlock(bcoord); CampBlock cb = CivGlobal.getCampBlock(bcoord); if (sb == null && cb == null) { explodeBlock(b); continue; } if (sb != null) { if (!sb.isDamageable()) { continue; } if (sb.getOwner() instanceof TownHall) { TownHall th = (TownHall) sb.getOwner(); if (th.getControlPoints().containsKey(bcoord)) { continue; } } if (!sb.getOwner().isDestroyed()) { if (!structuresHit.contains(sb.getOwner())) { structuresHit.add(sb.getOwner()); if (sb.getOwner() instanceof TownHall) { TownHall th = (TownHall) sb.getOwner(); if (th.getHitpoints() == 0) { explodeBlock(b); } else { th.onTNTDamage(structureDamage); } } else { sb.getOwner() .onDamage(structureDamage, b.getWorld(), null, sb.getCoord(), sb); CivMessage.sendCiv( sb.getCiv(), CivColor.Yellow + CivSettings.localize.localizedString( "var_war_tntMsg", sb.getOwner().getDisplayName(), (sb.getOwner().getCenterLocation().getX() + "," + sb.getOwner().getCenterLocation().getY() + "," + sb.getOwner().getCenterLocation().getZ() + ")"), (sb.getOwner().getHitpoints() + "/" + sb.getOwner().getMaxHitPoints()))); } } } else { explodeBlock(b); } continue; } } } } } event.setCancelled(true); } }