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


Java DamageEntityEvent.setCancelled方法代码示例

本文整理汇总了Java中org.spongepowered.api.event.entity.DamageEntityEvent.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java DamageEntityEvent.setCancelled方法的具体用法?Java DamageEntityEvent.setCancelled怎么用?Java DamageEntityEvent.setCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.event.entity.DamageEntityEvent的用法示例。


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

示例1: onPlayerDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerDamage(DamageEntityEvent event) {
	if (!Config.Values.Synchronize.getEnableHealth())
		return;

	Entity player = event.getTargetEntity();

	if (!(player instanceof Player))
		return;

	synchronized (waitingPlayers) {
		if (waitingPlayers.containsKey(player.getUniqueId())) {
			event.setCancelled(true);
		}
	}
}
 
开发者ID:AuraDevelopmentTeam,项目名称:InvSync,代码行数:17,代码来源:PlayerEvents.java

示例2: handleDamageEntity

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
public void handleDamageEntity(DamageEntityEvent event, Player victim, Player damager) {
    ClanPlayerImpl victimClanPlayer = ClansImpl.getInstance().getClanPlayer(victim.getUniqueId());
    ClanPlayerImpl damagerClanPlayer = ClansImpl.getInstance().getClanPlayer(damager.getUniqueId());
    if (victimClanPlayer == null || damagerClanPlayer == null)
        return;
    if (victimClanPlayer.getClan() == null || damagerClanPlayer.getClan() == null)
        return;
    if (Utils.isWorldBlockedFromAllowingFriendlyFireProtection(victim.getWorld().getName())) {
        return;
    }
    if (victim.getUniqueId().equals(damager.getUniqueId())) {
        return;
    }

    ClanImpl victimPlayerClan = victimClanPlayer.getClan();
    ClanImpl damagerPlayerClan = damagerClanPlayer.getClan();
    if (victimPlayerClan.isPlayerFriendlyToThisClan(damagerClanPlayer)) {
        if (victimClanPlayer.isFfProtected() && victimPlayerClan.isFfProtected() && damagerPlayerClan.isFfProtected()) {
            event.setCancelled(true);
            Messages.sendWarningMessage(damager, Messages.FRIENDLY_FIRE_IS_OFF);
        }
    }
}
 
开发者ID:iLefty,项目名称:mcClans,代码行数:24,代码来源:FriendlyFireListener.java

示例3: onEntityDamagedByPlayer

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onEntityDamagedByPlayer(DamageEntityEvent event, @All(ignoreEmpty=false) EntityDamageSource[] sources)
{
	if (!ConfigHandler.getNode("worlds").getNode(event.getTargetEntity().getWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	Entity attacker = null;
	for (int i = 0; i < sources.length; i++)
	{
		if (sources[i].getSource().getType() == EntityTypes.PLAYER
				|| (sources[i] instanceof IndirectEntityDamageSource && ((IndirectEntityDamageSource) sources[i]).getIndirectSource().getType() == EntityTypes.PLAYER))
		{
			attacker = sources[i].getSource();
		}
	}
	if (attacker != null && event.getTargetEntity().getType() == EntityTypes.PLAYER)
	{
		if (!DataHandler.getFlag("pvp", attacker.getLocation()) || !DataHandler.getFlag("pvp", event.getTargetEntity().getLocation()))
		{
			event.setCancelled(true);
			return;
		}
	}
}
 
开发者ID:Arckenver,项目名称:Nations,代码行数:26,代码来源:PvpListener.java

示例4: onEntityDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityDamage(DamageEntityEvent event, @Root EntityDamageSource dmgSource) {
    if(dmgSource.getSource() instanceof Player) {
        Player player = (Player)dmgSource.getSource();
        EntityType entityType = event.getTargetEntity().getType();
        String entityId = entityType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.entity.damage." + entityId + ".deal")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to damage " + entityType.getName() + "s!"));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:17,代码来源:DamageEntityListener.java

示例5: onPlayerDamaged

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerDamaged(DamageEntityEvent event)
{
	if (event.getTargetEntity() instanceof Player)
	{
		Player player = (Player) event.getTargetEntity();

		if (Utils.isTeleportCooldownEnabled() && EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
		{
			EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
			player.sendMessage(Text.of(TextColors.RED, "Teleportation canceled due to damage."));
		}

		if (EssentialCmds.godPlayers.contains(player.getUniqueId()))
		{
			event.setBaseDamage(0);
			event.setCancelled(true);
		}
	}
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:21,代码来源:PlayerDamageListener.java

示例6: onPlayerDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerDamage(DamageEntityEvent event) {

    Entity entity = event.getTargetEntity();
    if (!(entity instanceof Player)) {
        return;
    }
    Player player = (Player) entity;

    if (!event.willCauseDeath()) {
        return;
    }

    for (SurvivalGame survivalGame : SurvivalGameRepository.values()) {
        if (survivalGame.getPlayerUUIDs().contains(player.getUniqueId())) {
            performDeadPlayer(survivalGame, player, event.getCause());
            event.setCancelled(true);
            break;
        }
    }
}
 
开发者ID:m0pt0pmatt,项目名称:SurvivalGames,代码行数:22,代码来源:PlayerDeathListener.java

示例7: onFrameAndBoatBrake

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFrameAndBoatBrake(DamageEntityEvent e) {
	
	RedProtect.get().logger.debug("blocks","Is BlockListener - DamageEntityEvent event");
	Entity ent = e.getTargetEntity();
	Location<World> l = e.getTargetEntity().getLocation();
	    
	Region r = RedProtect.get().rm.getTopRegion(l);
	
	if (ent instanceof Hanging && e.getCause().first(Monster.class).isPresent()) {    		
		if (r != null && !r.canFire()){
			e.setCancelled(true);
    		return;
		}
    }   
	
	if (ent instanceof Boat && e.getCause().first(Player.class).isPresent()){
		Player p = e.getCause().first(Player.class).get();
		if (!r.canMinecart(p)){
			RPLang.sendMessage(p, "blocklistener.region.cantbreak");
			e.setCancelled(true);
        }
	}
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:25,代码来源:RPBlockListener.java

示例8: onDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onDamage(DamageEntityEvent event) {
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }
    Player p = (Player) event.getTargetEntity();
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    if (up.get(GodKeys.GOD).orElse(false)) {
        event.setCancelled(true);
        //Send error message to player trying to hit, if player
        Player t = event.getCause().first(Player.class).orElse(null);
        if (t != null && t.getUniqueId() != p.getUniqueId()) {
            Messages.send(t, "god.onhit");
        }
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:17,代码来源:GodListener.java

示例9: onEntityDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityDamage(final DamageEntityEvent event) {
    if (event.getTargetEntity() instanceof Player) {
        Player player = (Player) event.getTargetEntity();

        if (player.get(BedrockKeys.IS_INVINCIBLE).orElse(false)) {
            event.setCancelled(true);
        }
    }
}
 
开发者ID:prism,项目名称:Bedrock,代码行数:11,代码来源:DamageEntityListener.java

示例10: onEntityDamaged

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityDamaged(DamageEntityEvent evt) {
    EntityDamagedScriptEvent event = (EntityDamagedScriptEvent) clone();
    event.internal = evt;
    event.entity = new EntityTag(evt.getTargetEntity());
    event.damage = new NumberTag(evt.getFinalDamage());
    event.cancelled = evt.isCancelled();
    // TODO: Cause viewing
    event.run();
    evt.setCancelled(event.cancelled);
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:12,代码来源:EntityDamagedScriptEvent.java

示例11: onEntityKilled

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onEntityKilled(DamageEntityEvent evt) {
    if (!evt.willCauseDeath()) {
        return;
    }
    EntityKilledScriptEvent event = (EntityKilledScriptEvent) clone();
    event.internal = evt;
    event.entity = new EntityTag(evt.getTargetEntity());
    event.damage = new NumberTag(evt.getFinalDamage());
    event.cancelled = evt.isCancelled();
    // TODO: Cause viewing
    event.run();
    evt.setCancelled(event.cancelled);
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:15,代码来源:EntityKilledScriptEvent.java

示例12: onDamageEntity

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onDamageEntity(DamageEntityEvent event) {
    if (event.getTargetEntity().getType() == EntityTypes.PLAYER) {
        if (Main.getMinigame().getChallenger(event.getTargetEntity().getUniqueId()).isPresent()) {
            event.setCancelled(true);
        }
    }
}
 
开发者ID:caseif,项目名称:InfernoSpleef,代码行数:9,代码来源:PlayerListener.java

示例13: onDamageEntity

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener(order = Order.LAST)
public void onDamageEntity(DamageEntityEvent event) {
    java.util.Optional<Player> damager = event.getCause().first(Player.class);
    if (!damager.isPresent()) {
        return; // not a player, so return
    }

    Optional<Challenger> chal = CommonCore.getChallenger(event.getTargetEntity().getUniqueId());
    Optional<Challenger> damChal = CommonCore.getChallenger(damager.get().getUniqueId());

    // cancel if either of the players is spectating
    if (chal.isPresent() && chal.get().isSpectating() || (damChal.isPresent() && damChal.get().isSpectating())) {
        event.setCancelled(true);
        return;
    }

    // check whether both are in a round
    if (chal.isPresent() && damChal.isPresent()) {
        // check whether they're in the same round
        if (chal.get().getRound() == damChal.get().getRound()) {
            // check whether damage is disabled entirely in the round, or if they're on the same team
            if (!chal.get().getRound().getConfigValue(ConfigNode.ALLOW_DAMAGE)
                    || (!chal.get().getRound().getConfigValue(ConfigNode.ALLOW_FRIENDLY_FIRE)
                    && chal.get().getTeam().orNull() == damChal.get().getTeam().orNull())) {
                event.setCancelled(true);
            }
        } else {
            event.setCancelled(true);
        }
    } else if (chal.isPresent() != damChal.isPresent()) {
        event.setCancelled(true); // one's in a round and one's not
    }
}
 
开发者ID:caseif,项目名称:Inferno,代码行数:34,代码来源:PlayerWorldListener.java

示例14: onPlayerDamage

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerDamage(DamageEntityEvent event) {
	// C'est un joueur
	if (event.getTargetEntity() instanceof Player) {
		EPlayer player = this.plugin.getEServer().getEPlayer((Player) event.getTargetEntity());
		if (player.isGod()) {
			Optional<DamageSource> damagesource = event.getCause().first(DamageSource.class);
			// Le joueur tombe dans le vide
			if (damagesource.isPresent() && damagesource.get().equals(DamageSources.VOID)) {
				// L'option de téléportation au spwan est activé
				if (this.plugin.getConfigs().isGodTeleportToSpawn()) {
					EEMessages.GOD_TELEPORT.sendTo(player);
					player.teleportSpawn();
					player.heal();
					event.setCancelled(true);
				}
				// Domage normal
			} else {
				player.heal();
				event.setCancelled(true);
			}
		}
	} else if (event.getTargetEntity() instanceof Creature) {
		if (this.plugin.getConfigs().isGameModeKill()) {
			Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
			if (optDamageSource.isPresent() && optDamageSource.get().getSource() instanceof Player) {
				Player killer = (Player) optDamageSource.get().getSource();
				if (killer.get(Keys.IS_SNEAKING).orElse(false) && 
						killer.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL).equals(GameModes.CREATIVE)) {
					Entity entity = event.getTargetEntity();
					event.setBaseDamage(entity.get(Keys.MAX_HEALTH).orElse(Double.MAX_VALUE));
				}
			}
		}
	}
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:37,代码来源:EEPlayerListeners.java

示例15: onAttackEntity

import org.spongepowered.api.event.entity.DamageEntityEvent; //导入方法依赖的package包/类
@Listener
public void onAttackEntity(DamageEntityEvent event) {
	if (event.isCancelled()) return;
	if (!(event.getTargetEntity() instanceof Living)) return;
	Living target = (Living)event.getTargetEntity();
	
	if (VillagerShops.isNPCused(target)) event.setCancelled(true);
}
 
开发者ID:DosMike,项目名称:VillagerShops,代码行数:9,代码来源:EventListeners.java


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