Java Code Examples for org.bukkit.event.entity.EntityExplodeEvent#setCancelled()

The following examples show how to use org.bukkit.event.entity.EntityExplodeEvent#setCancelled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShopProtectionListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onExplode(EntityExplodeEvent e) {

    for (int i = 0, a = e.blockList().size(); i < a; i++) {
        final Block b = e.blockList().get(i);
        final Shop shop = getShopNature(b.getLocation(), true);

        if (shop == null) {
            continue;
        }
        if (plugin.getConfig().getBoolean("protect.explode")) {
            e.setCancelled(true);
        } else {
            plugin.log("Deleting shop "+shop+" request by block break (explode).");
            shop.delete();
        }
    }
}
 
Example 2
Source File: LWCEntityListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event) {
    if (!LWC.ENABLED || event.isCancelled()) {
        return;
    }

    LWC lwc = LWC.getInstance();

    for (Block block : event.blockList()) {
        Protection protection = plugin.getLWC().findProtection(block.getLocation());

        if (protection != null) {
            boolean ignoreExplosions = Boolean
                    .parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "ignoreExplosions"));

            if (!(ignoreExplosions || protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS))) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 3
Source File: ChunkEventHelper.java    From ClaimChunk with MIT License 6 votes vote down vote up
private static void cancelExplosionEvent(boolean hardCancel, @Nonnull EntityExplodeEvent e) {
    if (hardCancel) {
        // This explosion event occurred within a claimed chunk.
        e.setYield(0);
        e.setCancelled(true);
    } else {
        // This explosion occurred outside of a claimed chunk but it might
        // interfere with claimed blocks.
        final ChunkHandler CHUNK_HANDLER = ClaimChunk.getInstance().getChunkHandler();

        // Remove all of the blocks within claimed chunks from this event
        // so they are not destroyed.
        // Unfortunately, there is no way to remove specific entities from
        // the damage list, so entities will not be protected from
        // explosions by this method.
        e.blockList().removeIf(block -> CHUNK_HANDLER.isClaimed(block.getChunk()));
    }
}
 
Example 4
Source File: FlyingMobEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void MobExplosion(final EntityExplodeEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    // Only cover in the island world
    if (e.getEntity() == null || !IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    if (mobSpawnInfo.containsKey(e.getEntity())) {
        // We know about this mob
        if (DEBUG) {
            plugin.getLogger().info("DEBUG: We know about this mob");
        }
        if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getLocation())) {
            // Cancel the explosion and block damage
            if (DEBUG) {
                plugin.getLogger().info("DEBUG: cancel flying mob explosion");
            }
            e.blockList().clear();
            e.setCancelled(true);
        }
    }
}
 
Example 5
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
    IEntity entity = plugin.wrapEntity(event.getEntity());
    if (manager.isPlotWorld(entity)) {
        PlotMapInfo pmi = manager.getMap(entity.getLocation());

        if (pmi != null && pmi.isDisableExplosion()) {
            event.setCancelled(true);
        } else {
            PlotId id = manager.getPlotId(entity.getLocation());
            if (id == null) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 6
Source File: EntityExplodeListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
    try {
        final Entity entity = event.getEntity();
        final Location location = entity.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        if (!IridiumSkyblock.getConfiguration().allowExplosions)
            event.setCancelled(true);
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example 7
Source File: DWorldListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityExplode(EntityExplodeEvent event) {
    if (plugin.getGameWorld(event.getEntity().getWorld()) == null) {
        return;
    }
    if (event.getEntity() instanceof LivingEntity) {
        // Disable Creeper explosions in gameWorlds
        event.setCancelled(true);
    } else {// TODO respect block breaking game rules
        // Disable drops from TNT
        event.setYield(0);
    }
}
 
Example 8
Source File: GlobalProtectionListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityExplode(EntityExplodeEvent event) {
    List<Block> blocklist = event.blockList();
    for (Block block : blocklist) {
        if (plugin.getGlobalProtectionCache().isProtectedBlock(block)) {
            event.setCancelled(true);
        }
    }
}
 
Example 9
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onGhastExplode(EntityExplodeEvent event) {
    if (!plugin.getWorldManager().isSkyNether(event.getEntity().getWorld())) {
        return; // Bail out, not our problem
    }
    // TODO: 23/09/2015 - R4zorax: Perhaps enable this when island has a certain level?
    if (event.getEntity() instanceof Fireball) {
        Fireball fireball = (Fireball) event.getEntity();
        fireball.setIsIncendiary(false);
        fireball.setFireTicks(0);
        event.setCancelled(true);
    }
}
 
Example 10
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EntityExplodeEvent(EntityExplodeEvent e) {

    if (e.getEntity() != null && e.getEntity().hasMetadata("ce.explosive")) {
        e.getEntity().remove();
        e.setCancelled(true);
    }

}
 
Example 11
Source File: LivingEntityShopListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onExplode(EntityExplodeEvent event) {
	if (plugin.isShopkeeper(event.getEntity())) {
		event.setCancelled(true);
		Log.debug("Cancelled event for living shop: " + event.getEventName());
	}
}
 
Example 12
Source File: EntityExplodeListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMonitorEntityExplode(EntityExplodeEvent event) {
    try {
        final Entity entity = event.getEntity();
        final Location location = entity.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        final UUID uuid = entity.getUniqueId();
        final IridiumSkyblock plugin = IridiumSkyblock.getInstance();
        final Map<UUID, Island> entities = plugin.entities;
        Island island = entities.get(uuid);
        if (island != null && island.isInIsland(location)) {
            event.setCancelled(true);
            entity.remove();
            entities.remove(uuid);
            return;
        }

        island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        for (Block block : event.blockList()) {
            if (!island.isInIsland(block.getLocation())) {
                final BlockState state = block.getState();
                IridiumSkyblock.nms.setBlockFast(block, 0, (byte) 0);
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> state.update(true, true));
            }

            if (!Utils.isBlockValuable(block)) continue;

            if (!(block.getState() instanceof CreatureSpawner)) {
                final Material material = block.getType();
                final XMaterial xmaterial = XMaterial.matchXMaterial(material);
                island.valuableBlocks.computeIfPresent(xmaterial.name(), (name, original) -> original - 1);
            }

            if (island.updating)
                island.tempValues.remove(block.getLocation());
        }
        island.calculateIslandValue();
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example 13
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplodeEvent(EntityExplodeEvent event) {
    final World world = event.getEntity().getLocation().getWorld();
    if (!GDFlags.EXPLOSION_BLOCK || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    GDCauseStackManager.getInstance().pushCause(event.getEntity());
    // check entity tracker
    final GDEntity gdEntity = EntityTracker.getCachedEntity(event.getEntity().getEntityId());
    GDPermissionUser user = null;
    if (gdEntity != null) {
        user = PermissionHolderCache.getInstance().getOrCreateUser(gdEntity.getOwnerUUID());
    }

    Entity source = event.getEntity();
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.EXPLOSION_BLOCK.toString(), source, world.getUID())) {
        return;
    }

    final String sourceId = GDPermissionManager.getInstance().getPermissionIdentifier(source);
    boolean denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUID()).getConfig().claim.explosionBlockSurfaceBlacklist.contains(sourceId);
    if (!denySurfaceExplosion) {
        denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUID()).getConfig().claim.explosionBlockSurfaceBlacklist.contains("any");
    }
    GDTimings.EXPLOSION_EVENT.startTiming();
    GDClaim targetClaim = null;
    final int cancelBlockLimit = GriefDefenderPlugin.getGlobalConfig().getConfig().claim.explosionCancelBlockLimit;
    final List<Block> filteredLocations = new ArrayList<>();
    for (Block block : event.blockList()) {
        final Location location = block.getLocation();
        targetClaim =  GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location);
        if (denySurfaceExplosion && block.getWorld().getEnvironment() != Environment.NETHER && location.getBlockY() >= location.getWorld().getSeaLevel()) {
            filteredLocations.add(block);
            GDPermissionManager.getInstance().processEventLog(event, location, targetClaim, Flags.EXPLOSION_BLOCK.getPermission(), source, block, user, "explosion-surface", Tristate.FALSE);
            continue;
        }
        final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.EXPLOSION_BLOCK, source, block, user, true);
        if (result == Tristate.FALSE) {
            // Avoid lagging server from large explosions.
            if (event.blockList().size() > cancelBlockLimit) {
                event.setCancelled(true);
                break;
            }
            filteredLocations.add(block);
        }
    }

    if (event.isCancelled()) {
        event.blockList().clear();
    } else if (!filteredLocations.isEmpty()) {
        event.blockList().removeAll(filteredLocations);
    }
    GDTimings.EXPLOSION_EVENT.stopTiming();
}
 
Example 14
Source File: WarListener.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event) {
		
	if (event.isCancelled()) {
		return;
	}
	
	if (!War.isWarTime()) {
		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)) {
					
		int yield;
		try {
			yield = CivSettings.getInteger(CivSettings.warConfig, "cannon.yield");
		} catch (InvalidConfiguration e) {
			e.printStackTrace();
			return;
		}
	
		yield = yield / 2;
	
		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));
				
					if (loc.distance(event.getLocation()) < yield) {
						WarRegen.saveBlock(loc.getBlock(), Cannon.RESTORE_NAME, false);
						ItemManager.setTypeIdAndData(loc.getBlock(), CivData.AIR, 0, false);
					}
				}	
			}
		}
		event.setCancelled(true);
	}
}
 
Example 15
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void OnEntityExplodeEvent(EntityExplodeEvent event) {
	if (event.getEntity() == null) {
		return;
	}
	/* prevent ender dragons from breaking blocks. */
	if (event.getEntityType().equals(EntityType.COMPLEX_PART)) {
		event.setCancelled(true);
	} else if (event.getEntityType().equals(EntityType.ENDER_DRAGON)) {
		event.setCancelled(true);
	}

	for (Block block : event.blockList()) {
		bcoord.setFromLocation(block.getLocation());
		StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
		if (sb != null) {
			event.setCancelled(true);
			return;
		}

		RoadBlock rb = CivGlobal.getRoadBlock(bcoord);
		if (rb != null) {
			event.setCancelled(true);
			return;
		}

		CampBlock cb = CivGlobal.getCampBlock(bcoord);
		if (cb != null) {
			event.setCancelled(true);
			return;
		}

		StructureSign structSign = CivGlobal.getStructureSign(bcoord);
		if (structSign != null) {
			event.setCancelled(true);
			return;
		}

		StructureChest structChest = CivGlobal.getStructureChest(bcoord);
		if (structChest != null) {
			event.setCancelled(true);
			return;
		}

		coord.setFromLocation(block.getLocation());

		HashSet<Wall> walls = CivGlobal.getWallChunk(coord);
		if (walls != null) {
			for (Wall wall : walls) {
				if (wall.isProtectedLocation(block.getLocation())) {
					event.setCancelled(true);
					return;
				}
			}
		}

		TownChunk tc = CivGlobal.getTownChunk(coord);
		if (tc == null) {
			continue;
		}

		event.setCancelled(true);
		return;
	}

}
 
Example 16
Source File: WorldFreeze.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
    if (!match.isRunning()) {
        event.setCancelled(true);
    }
}