org.spongepowered.api.world.explosion.Explosion Java Examples

The following examples show how to use org.spongepowered.api.world.explosion.Explosion. 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: ExplosionView.java    From Web-API with MIT License 5 votes vote down vote up
public ExplosionView(Explosion value) {
    super(value);

    this.causeFire = value.canCauseFire();
    this.radius = value.getRadius();
    this.breakBlocks = value.shouldBreakBlocks();
    this.damageEntities = value.shouldDamageEntities();
    this.playSmoke = value.shouldPlaySmoke();
}
 
Example #2
Source File: EntityEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@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 #3
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockStartBurn(IgniteEntityEvent e) {

    Entity b = e.getTargetEntity();
    Cause ignit = e.getCause();

    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockIgniteEvent event.");

    Region r = RedProtect.get().rm.getTopRegion(b.getLocation(), this.getClass().getName());
    if (r != null && !r.canFire()) {
        if (ignit.first(Player.class).isPresent()) {
            Player p = ignit.first(Player.class).get();
            if (!r.canBuild(p)) {
                RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace");
                e.setCancelled(true);
                return;
            }
        } else {
            e.setCancelled(true);
            return;
        }

        if (ignit.first(BlockSnapshot.class).isPresent() && (ignit.first(BlockSnapshot.class).get().getState().getType().equals(BlockTypes.FIRE) || ignit.first(BlockSnapshot.class).get().getState().getType().getName().contains("lava"))) {
            e.setCancelled(true);
            return;
        }
        if (ignit.first(Lightning.class).isPresent() || ignit.first(Explosion.class).isPresent() || ignit.first(Fireball.class).isPresent()) {
            e.setCancelled(true);
        }
    }
}
 
Example #4
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@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 #5
Source File: BlockEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@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 #6
Source File: BlockEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@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 #7
Source File: EntityEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@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 #8
Source File: BlockEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@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();
}