当前位置: 首页>>代码示例>>Java>>正文


Java ExplosionEvent类代码示例

本文整理汇总了Java中org.spongepowered.api.event.world.ExplosionEvent的典型用法代码示例。如果您正苦于以下问题:Java ExplosionEvent类的具体用法?Java ExplosionEvent怎么用?Java ExplosionEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExplosionEvent类属于org.spongepowered.api.event.world包,在下文中一共展示了ExplosionEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onExplosion

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@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());*/
	}
}
 
开发者ID:Arckenver,项目名称:Nations,代码行数:18,代码来源:ExplosionListener.java

示例2: onExplosion

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener
public void onExplosion(final ExplosionEvent.Detonate event) {
    Optional<Entity> optional = event.getCause().first(Entity.class);
    if (optional.isPresent()) {
        for (Location<World> location : event.getAffectedLocations()) {
            if (Keys.getLockableBlocks().contains(location.getBlockType())) {
                try {
                    // Are there locks on this block?
                    if (!Keys.getStorageAdapter().getLocks(location).isEmpty()) {
                        event.setCancelled(true);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
 
开发者ID:prism,项目名称:Keys,代码行数:19,代码来源:ExplosionListener.java

示例3: onExplosion

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener
public void onExplosion(ExplosionEvent.Detonate event) {
	Optional<Player> source = event.getCause().first(Player.class);
	if (!source.isPresent() && event.getExplosion().getSourceExplosive().isPresent()) {
		Explosive e = event.getExplosion().getSourceExplosive().get();
		Optional<UUID> creator = e.getCreator();
		if (creator.isPresent()) source = Sponge.getServer().getPlayer(creator.get());
	}
	
	List<Location<World>> denied = new LinkedList<>();
	for (NPCguard g : VillagerShops.npcs) {
		if (g.playershopcontainer != null && 
				event.getAffectedLocations().contains(g.playershopcontainer)) {
				denied.add(g.playershopcontainer);
		}
	}
	event.getAffectedLocations().removeAll(denied);
}
 
开发者ID:DosMike,项目名称:VillagerShops,代码行数:19,代码来源:EventListeners.java

示例4: preventExplosion

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
private void preventExplosion(ExplosionEvent.Pre event) {
    //"Clone" explosion, as we cannot change the existing one?
    Explosion old = event.getExplosion();
    Explosion newExplosion = Explosion.builder()
            .from(old)
            .shouldBreakBlocks(config.BREAK_BLOCKS)
            .shouldPlaySmoke(config.SHOW_PARTICLES)
            .sourceExplosive(null) //Do not check for a creeper in next Event listener Iteration
            .build();

    //Cancel default event...
    event.setCancelled(true);
    //...but trigger new event
    Cause genericCause = Cause.of(NamedCause.owner(container));
    newExplosion.getWorld().triggerExplosion(newExplosion, genericCause);

    //Remove the creeper (as the default event is canceled);
    ((Creeper) event.getCause().root()).remove();
}
 
开发者ID:Felfio,项目名称:treepers-sponge,代码行数:20,代码来源:Treepers.java

示例5: onEntityExplosionDetonate

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityExplosionDetonate(ExplosionEvent.Detonate event) {
    if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(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;
    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, event.getCause().root(), entity, user) == Tristate.FALSE) {
            iterator.remove();
        }
    }
    GPTimings.ENTITY_EXPLOSION_DETONATE_EVENT.stopTimingIfSync();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:21,代码来源:EntityEventHandler.java

示例6: onBlockExplode

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockExplode(ExplosionEvent.Detonate e){
	RedProtect.get().logger.debug("default","Is BlockListener - BlockExplodeEvent event");
	
	for (Location<World> bex:e.getAffectedLocations()){
		Region r = RedProtect.get().rm.getTopRegion(bex);
		if (!cont.canWorldBreak(bex.createSnapshot())){
			e.setCancelled(true);
			return;
    	}
		if (r != null && !r.canFire()){
			e.setCancelled(true);
			return;
		}
	}
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:17,代码来源:RPMine18.java

示例7: onCreeperExplode

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener
public void onCreeperExplode(ExplosionEvent.Pre event, @First Creeper entity) {
  Optional<FreakyFourInstance> optInst = manager.getApplicableZone(entity);
  if (!optInst.isPresent()) {
    return;
  }

  FreakyFourInstance inst = optInst.get();

  Optional<Living> boss = inst.getBoss(FreakyFourBoss.DA_BOMB);
  if (!boss.isPresent() || !boss.get().equals(entity)) {
    return;
  }

  inst.dabombDetonate(entity.get(Keys.HEALTH).get() / entity.get(Keys.MAX_HEALTH).get());
  throwBack(entity);

  event.setCancelled(true);
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:20,代码来源:FreakyFourListener.java

示例8: onBlockExplode

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onBlockExplode(ExplosionEvent.Detonate event)
{
    if (!this.module.getConfig().protectBlockFromExplosion) return;

    Iterator<Location<World>> it = event.getAffectedLocations().iterator();
    while (it.hasNext())
    {
        Location<World> worldLocation = it.next();
        if (manager.getLock(worldLocation) != null)
        {
            event.getAffectedLocations().clear();
            break;
        }
    }

    event.filterEntities(input -> manager.getLockForEntityUID(input.getUniqueId()) != null);
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:19,代码来源:LockerBlockListener.java

示例9: onExplosion

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener
public void onExplosion(final ExplosionEvent.Detonate event) {
    Optional<Entity> optional = event.getCause().first(Entity.class);
    if (optional.isPresent()) {
        for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
            if (SafeGuard.getZoneManager().zoneExists(transaction.getOriginal().getLocation().get())) {
                transaction.setValid(false);
            }
        }
    }
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:12,代码来源:ExplosionListener.java

示例10: onExplosionOccurs

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener
public void onExplosionOccurs(ExplosionEvent.Detonate evt) {
    ExplosionOccursScriptEvent event = (ExplosionOccursScriptEvent) clone();
    event.internal = evt;
    event.location = new LocationTag(evt.getExplosion().getLocation());
    ListTag locs = new ListTag();
    for (Location<World> loc : evt.getAffectedLocations()) {
        locs.getInternal().add(new LocationTag(loc));
    }
    event.blocks = locs;
    ListTag ents = new ListTag();
    for (Entity ent : evt.getEntities()) {
        ents.getInternal().add(new EntityTag(ent));
    }
    event.entities = ents;
    Explosion exp = evt.getExplosion();
    MapTag data = new MapTag();
    data.getInternal().put("radius", new NumberTag(exp.getRadius()));
    data.getInternal().put("fire", new BooleanTag(exp.canCauseFire()));
    data.getInternal().put("break_blocks", new BooleanTag(exp.shouldBreakBlocks()));
    data.getInternal().put("damage_entities", new BooleanTag(exp.shouldDamageEntities()));
    data.getInternal().put("smoke", new BooleanTag(exp.shouldPlaySmoke()));
    event.explosion_data = data;
    event.cancelled = evt.isCancelled();
    event.run();
    evt.setCancelled(event.cancelled);
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:28,代码来源:ExplosionOccursScriptEvent.java

示例11: onBlockBrokenByExplosion

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener
public void onBlockBrokenByExplosion(final ExplosionEvent.Post event) {
    if (Latch.getConfig().getNode("protect_from_explosives").getBoolean(true)) {
        //If we're supposed to protect from explosions, invalidate the transaction
        final LockManager lockManager = Latch.getLockManager();
        for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
            if (transaction.isValid() && transaction.getOriginal().getLocation().isPresent()) {
                final Location<World> location = transaction.getOriginal().getLocation().get();
                if (lockManager.getLock(location).isPresent()) {
                    transaction.setValid(false);
                }
                final Optional<Lock> aboveLock = lockManager.getLock(location.getBlockRelative(Direction.UP));
                if (aboveLock.isPresent() && lockManager.isProtectBelowBlocks(location.getBlockRelative(Direction.UP).getBlockType())) {
                    transaction.setValid(false);
                }
            }
        }
    } else {
        //Otherwise we should delete the locks destroyed by the explosion
        for (Transaction<BlockSnapshot> bs : event.getTransactions()) {
            if (bs.isValid() && bs.getOriginal().getLocation().isPresent()) {
                if (Latch.getLockManager().getLock(bs.getOriginal().getLocation().get()).isPresent()) {
                    Latch.getLockManager().deleteLock(bs.getOriginal().getLocation().get(), false);
                }
            }
        }
    }
}
 
开发者ID:ichorpowered,项目名称:latch,代码行数:29,代码来源:ChangeBlockListener.java

示例12: onExplode

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener
public void onExplode(ExplosionEvent.Pre event) {
    Cause cause = event.getCause();
    Object root = cause.root();

    //Did a creeper directly cause this ExplosionEvent?
    boolean isCreeper = root instanceof Creeper;
    if (isCreeper) {
        preventExplosion(event);
        if (config.PLANT_TREE) {
            plantTree(event);
        }
    }
}
 
开发者ID:Felfio,项目名称:treepers-sponge,代码行数:15,代码来源:Treepers.java

示例13: onEntityExplosionPre

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityExplosionPre(ExplosionEvent.Pre event) {
    if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(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);
    Explosive explosive = null;
    if (event.getExplosion() instanceof Explosion) {
        explosive = ((Explosion) event.getExplosion()).getSourceExplosive().orElse(null);
    }

    if (explosive != null) {
        Entity entity = (Entity) explosive;

        if (user == null) {
            UUID uuid = entity.getCreator().orElse(null);
            if (uuid != null) {
                user = GriefPreventionPlugin.getOrCreateUser(uuid);
            }
        }

        if(GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.EXPLOSION, entity, location, user, true) == Tristate.FALSE) {
            event.setCancelled(true);
            GPTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTimingIfSync();
            return;
        }
    }

    GPTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTimingIfSync();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:36,代码来源:EntityEventHandler.java

示例14: onExplosion

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onExplosion(ExplosionEvent.Post event) {
    final World world = event.getExplosion().getWorld();
    if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) {
        return;
    }

    GPTimings.EXPLOSION_EVENT.startTimingIfSync();
    Object source = event.getCause().root();
    final User user = CauseContextHelper.getEventUser(event);
    GPClaim targetClaim = null;
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockSnapshot blockSnapshot = transaction.getOriginal();
        Location<World> location = blockSnapshot.getLocation().orElse(null);
        if (location == null) {
            continue;
        }

        targetClaim =  GriefPreventionPlugin.instance.dataStore.getClaimAt(blockSnapshot.getLocation().get(), targetClaim);
        if (GPFlags.EXPLOSION_SURFACE && location.getPosition().getY() > ((net.minecraft.world.World) world).getSeaLevel() && GPPermissionHandler.getClaimPermission(event, location, targetClaim, GPPermissions.EXPLOSION_SURFACE, source, blockSnapshot, user, true) == Tristate.FALSE) {
            event.setCancelled(true);
            GPTimings.EXPLOSION_EVENT.stopTimingIfSync();
            return;
        }

        if (GPPermissionHandler.getClaimPermission(event, location, targetClaim, GPPermissions.EXPLOSION, source, blockSnapshot, user, true) == Tristate.FALSE) {
            // Avoid lagging server from large explosions.
            if (event.getTransactions().size() > 100) {
                event.setCancelled(true);
                GPTimings.EXPLOSION_EVENT.stopTimingIfSync();
                return;
            }
            transaction.setValid(false);
            GPTimings.EXPLOSION_EVENT.stopTimingIfSync();
            return;
        }
    }
    GPTimings.EXPLOSION_EVENT.stopTimingIfSync();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:40,代码来源:BlockEventHandler.java

示例15: getEventUser

import org.spongepowered.api.event.world.ExplosionEvent; //导入依赖的package包/类
public static User getEventUser(Event event) {
    final Cause cause = event.getCause();
    final EventContext context = event.getContext();
    User user = null;
    if (cause != null) {
        user = cause.first(User.class).orElse(null);
    }

    if (user == null) {
        user = context.get(EventContextKeys.NOTIFIER)
                .orElse(context.get(EventContextKeys.OWNER)
                        .orElse(context.get(EventContextKeys.CREATOR)
                                .orElse(null)));
    }

    if (user == null) {
        if (event instanceof ExplosionEvent) {
            // Check igniter
            final Living living = context.get(EventContextKeys.IGNITER).orElse(null);
            if (living != null && living instanceof User) {
                user = (User) living;
            }
        }
    }

    return user;
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:28,代码来源:CauseContextHelper.java


注:本文中的org.spongepowered.api.event.world.ExplosionEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。