org.spongepowered.api.event.world.ExplosionEvent Java Examples
The following examples show how to use
org.spongepowered.api.event.world.ExplosionEvent.
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: ExplosionListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onExplosion(ExplosionEvent.Pre event) { if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean()) { return; } if (!DataHandler.getFlag("explosions", event.getExplosion().getLocation())) { event.setCancelled(true); /*event.setExplosion(Sponge.getRegistry().createBuilder(Explosion.Builder.class) .from(event.getExplosion()) .canCauseFire(canCauseFire) .shouldBreakBlocks(canBreakBlocks) .build());*/ } }
Example #2
Source File: ExplosionListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onExplosion(ExplosionEvent.Post event) { if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean()) { return; } if (event.getTransactions().size() > 100) { event.setCancelled(true); } for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { BlockSnapshot blockSnapshot = transaction.getOriginal(); if (blockSnapshot.getLocation().isPresent() && !DataHandler.getFlag("explosions", blockSnapshot.getLocation().get())) { transaction.setValid(false); } } }
Example #3
Source File: EntityListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockExplode(ExplosionEvent.Detonate e) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "Is BlockListener - BlockExplodeEvent event"); for (Location<World> bex : e.getAffectedLocations()) { Region r = RedProtect.get().rm.getTopRegion(bex, this.getClass().getName()); if (!cont.canWorldBreak(bex.createSnapshot())) { e.setCancelled(true); return; } if (r != null && !r.canFire()) { e.setCancelled(true); return; } } }
Example #4
Source File: EntityEventHandler.java From GriefPrevention with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityExplosionDetonate(ExplosionEvent.Detonate event) { if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetWorld().getProperties())) { return; } if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.EXPLOSION.toString(), event.getSource(), event.getTargetWorld().getProperties())) { return; } GPTimings.ENTITY_EXPLOSION_DETONATE_EVENT.startTimingIfSync(); final User user = CauseContextHelper.getEventUser(event); Iterator<Entity> iterator = event.getEntities().iterator(); GPClaim targetClaim = null; Object source = event.getSource(); if (source instanceof Explosion) { final Explosion explosion = (Explosion) source; if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } } while (iterator.hasNext()) { Entity entity = iterator.next(); targetClaim = GriefPreventionPlugin.instance.dataStore.getClaimAt(entity.getLocation(), targetClaim); if (GPPermissionHandler.getClaimPermission(event, entity.getLocation(), targetClaim, GPPermissions.ENTITY_DAMAGE, source, entity, user) == Tristate.FALSE) { iterator.remove(); } } GPTimings.ENTITY_EXPLOSION_DETONATE_EVENT.stopTimingIfSync(); }
Example #5
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityExplode(ExplosionEvent.Detonate e) { World w = e.getTargetWorld(); for (Location<World> b : e.getAffectedLocations()) { Region r = RedProtect.get().rm.getTopRegion(b, this.getClass().getName()); if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(w.getName()).entity_block_damage) { e.setCancelled(true); return; } } }
Example #6
Source File: EntityEventHandler.java From GriefDefender with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityExplosionDetonate(ExplosionEvent.Detonate event) { if (!GDFlags.EXPLOSION_ENTITY || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetWorld().getUniqueId())) { return; } if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.EXPLOSION_ENTITY.getName(), event.getSource(), event.getTargetWorld().getProperties())) { return; } GDTimings.ENTITY_EXPLOSION_DETONATE_EVENT.startTimingIfSync(); final User user = CauseContextHelper.getEventUser(event); Iterator<Entity> iterator = event.getEntities().iterator(); GDClaim targetClaim = null; Object source = event.getSource(); if (source instanceof Explosion) { final Explosion explosion = (Explosion) source; if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } } final String sourceId = GDPermissionManager.getInstance().getPermissionIdentifier(source); boolean denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(event.getTargetWorld().getUniqueId()).getConfig().claim.explosionEntitySurfaceBlacklist.contains(sourceId); if (!denySurfaceExplosion) { denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(event.getTargetWorld().getUniqueId()).getConfig().claim.explosionEntitySurfaceBlacklist.contains("any"); } while (iterator.hasNext()) { Entity entity = iterator.next(); final Location<World> location = entity.getLocation(); targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(entity.getLocation(), targetClaim); if (denySurfaceExplosion && location.getExtent().getDimension().getType() != DimensionTypes.NETHER && location.getBlockY() >= location.getExtent().getSeaLevel()) { iterator.remove(); GDPermissionManager.getInstance().processEventLog(event, location, targetClaim, Flags.EXPLOSION_ENTITY.getPermission(), source, entity, user, "explosion-surface", Tristate.FALSE); continue; } if (GDPermissionManager.getInstance().getFinalPermission(event, entity.getLocation(), targetClaim, Flags.EXPLOSION_ENTITY, source, entity, user) == Tristate.FALSE) { iterator.remove(); } else if (GDPermissionManager.getInstance().getFinalPermission(event, entity.getLocation(), targetClaim, Flags.ENTITY_DAMAGE, source, entity, user) == Tristate.FALSE) { iterator.remove(); } } GDTimings.ENTITY_EXPLOSION_DETONATE_EVENT.stopTimingIfSync(); }
Example #7
Source File: BlockEventHandler.java From GriefDefender with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onExplosionPre(ExplosionEvent.Pre event) { final World world = event.getExplosion().getWorld(); if (!GDFlags.EXPLOSION_BLOCK || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) { return; } Object source = event.getSource(); final Explosion explosion = event.getExplosion(); if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.EXPLOSION_BLOCK.getName(), source, event.getExplosion().getWorld().getProperties())) { return; } GDTimings.EXPLOSION_PRE_EVENT.startTimingIfSync(); final User user = CauseContextHelper.getEventUser(event); final Location<World> location = event.getExplosion().getLocation(); final GDClaim radiusClaim = NMSUtil.getInstance().createClaimFromCenter(location, event.getExplosion().getRadius()); final GDClaimManager claimManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getExtent().getUniqueId()); final Set<Claim> surroundingClaims = claimManager.findOverlappingClaims(radiusClaim); if (surroundingClaims.size() == 0) { return; } for (Claim claim : surroundingClaims) { // Use any location for permission check Location<World> targetLocation = new Location<>(location.getExtent(), claim.getLesserBoundaryCorner()); Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.EXPLOSION_BLOCK, source, targetLocation, user, true); if (result == Tristate.FALSE) { event.setCancelled(true); break; } } GDTimings.EXPLOSION_PRE_EVENT.stopTimingIfSync(); }
Example #8
Source File: BlockEventHandler.java From GriefDefender with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onExplosionDetonate(ExplosionEvent.Detonate event) { final World world = event.getExplosion().getWorld(); if (!GDFlags.EXPLOSION_BLOCK || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) { return; } Object source = event.getSource(); if (source instanceof Explosion) { final Explosion explosion = (Explosion) source; if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } } if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.EXPLOSION_BLOCK.getName(), source, event.getExplosion().getWorld().getProperties())) { return; } GDTimings.EXPLOSION_EVENT.startTimingIfSync(); final User user = CauseContextHelper.getEventUser(event); GDClaim targetClaim = null; final List<Location<World>> filteredLocations = new ArrayList<>(); final String sourceId = GDPermissionManager.getInstance().getPermissionIdentifier(source); final int cancelBlockLimit = GriefDefenderPlugin.getGlobalConfig().getConfig().claim.explosionCancelBlockLimit; boolean denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUniqueId()).getConfig().claim.explosionBlockSurfaceBlacklist.contains(sourceId); if (!denySurfaceExplosion) { denySurfaceExplosion = !GriefDefenderPlugin.getActiveConfig(world.getUniqueId()).getConfig().claim.explosionBlockSurfaceBlacklist.contains("any"); } for (Location<World> location : event.getAffectedLocations()) { targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location, targetClaim); if (denySurfaceExplosion && world.getDimension().getType() != DimensionTypes.NETHER && location.getBlockY() >= world.getSeaLevel()) { filteredLocations.add(location); GDPermissionManager.getInstance().processEventLog(event, location, targetClaim, Flags.EXPLOSION_BLOCK.getPermission(), source, location.getBlock(), user, "explosion-surface", Tristate.FALSE); continue; } Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.EXPLOSION_BLOCK, source, location.getBlock(), user, true); if (result == Tristate.FALSE) { // Avoid lagging server from large explosions. if (event.getAffectedLocations().size() > cancelBlockLimit) { event.setCancelled(true); break; } filteredLocations.add(location); } } // Workaround for SpongeForge bug if (event.isCancelled()) { event.getAffectedLocations().clear(); } else if (!filteredLocations.isEmpty()) { event.getAffectedLocations().removeAll(filteredLocations); } GDTimings.EXPLOSION_EVENT.stopTimingIfSync(); }
Example #9
Source File: ExplosionListener.java From EagleFactions with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onExplosionPre(final ExplosionEvent.Pre event) { final EventContext context = event.getContext(); final Cause cause = event.getCause(); User user = null; if (cause.root() instanceof TileEntity) { user = context.get(EventContextKeys.OWNER) .orElse(context.get(EventContextKeys.NOTIFIER) .orElse(context.get(EventContextKeys.CREATOR) .orElse(null))); } else { user = context.get(EventContextKeys.NOTIFIER) .orElse(context.get(EventContextKeys.OWNER) .orElse(context.get(EventContextKeys.CREATOR) .orElse(null))); } if(event.getCause().containsType(Player.class)) { user = event.getCause().first(Player.class).get(); } else if(event.getCause().containsType(User.class)) { user = event.getCause().first(User.class).get(); } final Location<World> location = event.getExplosion().getLocation(); if (user == null) { if(!super.getPlugin().getProtectionManager().canExplode(location).hasAccess()) { event.setCancelled(true); return; } } else { if (!super.getPlugin().getProtectionManager().canExplode(location, user, false).hasAccess()) { event.setCancelled(true); return; } } }
Example #10
Source File: ExplosionListener.java From EagleFactions with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onExplosion(final ExplosionEvent.Detonate event) { final List<Location<World>> locationList = new ArrayList<>(event.getAffectedLocations()); final List<Entity> entityList = new ArrayList<>(event.getEntities()); User user = null; final Cause cause = event.getCause(); final EventContext context = event.getContext(); if (cause.root() instanceof TileEntity) { user = context.get(EventContextKeys.OWNER) .orElse(context.get(EventContextKeys.NOTIFIER) .orElse(context.get(EventContextKeys.CREATOR) .orElse(null))); } else { user = context.get(EventContextKeys.NOTIFIER) .orElse(context.get(EventContextKeys.OWNER) .orElse(context.get(EventContextKeys.CREATOR) .orElse(null))); } if(event.getCause().containsType(Player.class)) { user = event.getCause().first(Player.class).get(); } else if(event.getCause().containsType(User.class)) { user = event.getCause().first(User.class).get(); } for(final Entity entity : entityList) { final Location<World> entityLocation = entity.getLocation(); if(user != null) { if(!super.getPlugin().getProtectionManager().canExplode(entityLocation, user, false).hasAccess()) { event.getEntities().remove(entity); } } else if(!super.getPlugin().getProtectionManager().canExplode(entityLocation).hasAccess()) { event.getEntities().remove(entity); } } for(final Location<World> location : locationList) { if(user != null) { if(!super.getPlugin().getProtectionManager().canExplode(location, user, false).hasAccess()) { event.getAffectedLocations().remove(location); } } else if(!super.getPlugin().getProtectionManager().canExplode(location).hasAccess()) { event.getAffectedLocations().remove(location); } } }
Example #11
Source File: EntityEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityExplosionPre(ExplosionEvent.Pre event) { if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetWorld().getProperties())) { return; } if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.EXPLOSION.toString(), event.getSource(), event.getTargetWorld().getProperties())) { return; } GPTimings.ENTITY_EXPLOSION_PRE_EVENT.startTimingIfSync(); Location<World> location = event.getExplosion().getLocation(); GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAt(location); User user = CauseContextHelper.getEventUser(event); Object source = event.getSource(); if (source instanceof Explosion) { final Explosion explosion = (Explosion) source; if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } } Tristate result = Tristate.UNDEFINED; if (GPFlags.EXPLOSION_SURFACE && location.getPosition().getY() > ((net.minecraft.world.World) location.getExtent()).getSeaLevel()) { result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.EXPLOSION_SURFACE, source, location.getBlock(), user, true); } else { result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.EXPLOSION, source, location.getBlock(), user, true); } if(result == Tristate.FALSE) { event.setCancelled(true); GPTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTimingIfSync(); return; } GPTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTimingIfSync(); }
Example #12
Source File: BlockEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onExplosionDetonate(ExplosionEvent.Detonate event) { final World world = event.getExplosion().getWorld(); if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) { return; } Object source = event.getSource(); if (source instanceof Explosion) { final Explosion explosion = (Explosion) source; if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } } if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.EXPLOSION.toString(), source, event.getExplosion().getWorld().getProperties())) { return; } GPTimings.EXPLOSION_EVENT.startTimingIfSync(); final User user = CauseContextHelper.getEventUser(event); GPClaim targetClaim = null; final List<Location<World>> filteredLocations = new ArrayList<>(); for (Location<World> location : event.getAffectedLocations()) { targetClaim = GriefPreventionPlugin.instance.dataStore.getClaimAt(location, targetClaim); Tristate result = Tristate.UNDEFINED; if (GPFlags.EXPLOSION_SURFACE && location.getPosition().getY() > ((net.minecraft.world.World) world).getSeaLevel()) { result = GPPermissionHandler.getClaimPermission(event, location, targetClaim, GPPermissions.EXPLOSION_SURFACE, source, location.getBlock(), user, true); } else { result = GPPermissionHandler.getClaimPermission(event, location, targetClaim, GPPermissions.EXPLOSION, source, location.getBlock(), user, true); } if (result == Tristate.FALSE) { // Avoid lagging server from large explosions. if (event.getAffectedLocations().size() > 100) { event.setCancelled(true); break; } filteredLocations.add(location); } } // Workaround for SpongeForge bug if (event.isCancelled()) { event.getAffectedLocations().clear(); } else if (!filteredLocations.isEmpty()) { event.getAffectedLocations().removeAll(filteredLocations); } GPTimings.EXPLOSION_EVENT.stopTimingIfSync(); }