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


Java EntityDamageEvent.isCancelled方法代码示例

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


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

示例1: inflictDamage

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
/**
 * Inflicts the given damage on an entity.
 *
 * This method will call the appropriate damage method and fire an {@link EntityDamageEvent}.
 *
 * @param entity Entity to inflict damage upon
 * @param damage Amount of half-hearts of damage to inflict
 * @param info {@link DamageInfo} object that details the type of damage
 * @return the final {@link Damage} object (never null)
 *
 * @throws NullPointerException if entity or info is null
 * throws IllegalArgumentExcpetion if hearts is less than zero
 */
public static @Nonnull
Damage inflictDamage(@Nonnull LivingEntity entity, int damage, @Nonnull DamageInfo info) {
    Preconditions.checkNotNull(entity, "living entity");
    Preconditions.checkArgument(damage >= 0, "damage must be greater than or equal to zero");
    Preconditions.checkNotNull(info, "damage info");

    DamageAPIHelper helper = DamageAPIHelper.get();

    EntityDamageEvent event = new EntityDamageEvent(entity, DamageCause.CUSTOM, damage);
    helper.setEventDamageInfo(event, info);

    Bukkit.getPluginManager().callEvent(event);

    if(event.isCancelled()) {
        return null;
    }

    entity.damage(event.getDamage());

    helper.setEventDamageInfo(event, null);

    return helper.getOurEvent(event).toDamageObject();
}
 
开发者ID:WarzoneMC,项目名称:Warzone,代码行数:37,代码来源:DamageAPI.java

示例2: onEntityDamage

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if(event.getCause() == EntityDamageEvent.DamageCause.CUSTOM) return;
    if(Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().getGameState() != GameState.INGAME) {
        event.setCancelled(true);
    } else {
        if(!Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().getCurrentGame().allowPVP) event.setCancelled(true);
    }
    if(!event.isCancelled() && event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        if((player.getHealth()-event.getDamage()) <= 0) {
            event.setDamage(0);
            if(Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().isAlive(player)) {
                Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().setAlive(player, false);
            }
        }
    }
}
 
开发者ID:ArcadiaPlugins,项目名称:Arcadia-Spigot,代码行数:19,代码来源:DamageListener.java

示例3: onHit

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onHit(EntityDamageEvent event)
{
	if(event.isCancelled()) return;
	Entity hitTarget = event.getEntity();
	if(hitTarget != null && hitTarget instanceof ArmorStand && hitTarget.getCustomName() == "Chair")
		// Chair entity is immune to damage.
		event.setCancelled(true);
	else if(hitTarget != null && hitTarget instanceof Player && hitTarget.getVehicle() != null)
	{
		// Let players stand up if receiving damage.
		Entity vehicle = hitTarget.getVehicle();
		if(vehicle != null && vehicle instanceof ArmorStand && vehicle.getCustomName() == "Chair")
			vehicle.remove();
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:17,代码来源:Chairs.java

示例4: damage

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@Override
public void damage(double amount)
{
	Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class);
	modifiers.put(DamageModifier.BASE, 1.0);
	Map<DamageModifier, Function<Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class);
	modifierFunctions.put(DamageModifier.BASE, damage -> damage);
	
	EntityDamageEvent event = new EntityDamageEvent(this, DamageCause.CUSTOM, modifiers, modifierFunctions);
	event.setDamage(amount);
	Bukkit.getPluginManager().callEvent(event);
	if (!event.isCancelled())
	{
		setHealth(health - amount);
	}
}
 
开发者ID:seeseemelk,项目名称:MockBukkit,代码行数:17,代码来源:PlayerMock.java

示例5: onEntityDamage

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
	if (event instanceof EntityDamageByEntityEvent)
		return;
	
	if (event.getEntity() instanceof Player == false)
		return;

	Player t = (Player) event.getEntity();
	
	if (!damages.containsKey(t.getName()))
		damages.put(t.getName(), new ArrayList<PlayerDamageEvent>());
	
	PlayerDamageEvent callMe = new PlayerDamageEvent(t, event.getCause());
	Bukkit.getPluginManager().callEvent(callMe);
	event.setCancelled(callMe.isCancelled());
	
	if (event.isCancelled() == false)
		damages.get(t.getName()).add(callMe);
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:21,代码来源:DamageEvents.java

示例6: onDamageGet

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.MONITOR)
public void onDamageGet(EntityDamageEvent e) {
	if (!e.isCancelled()) {
		if (e instanceof EntityDamageByEntityEvent) {
			if (((EntityDamageByEntityEvent) e).getDamager() instanceof Player && SlimefunStartup.chance(100, 45)) {
				if (SlimefunManager.isItemSimiliar(((Player) ((EntityDamageByEntityEvent) e).getDamager()).getInventory().getItemInMainHand(), SlimefunItem.getItem("BLADE_OF_VAMPIRES"), true)) {
					((Player) ((EntityDamageByEntityEvent) e).getDamager()).playSound(((EntityDamageByEntityEvent) e).getDamager().getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.7F, 0.7F);
					((Player) ((EntityDamageByEntityEvent) e).getDamager()).addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 1));
				}
			}
		}
		if (e.getEntity() instanceof Player) {
			if (!e.isCancelled()) {
				if (e.getCause() == DamageCause.LAVA) Talisman.checkFor(e, SlimefunItem.getByID("LAVA_TALISMAN"));
				if (e.getCause() == DamageCause.DROWNING) Talisman.checkFor(e, SlimefunItem.getByID("WATER_TALISMAN"));
				if (e.getCause() == DamageCause.FALL) Talisman.checkFor(e, SlimefunItem.getByID("ANGEL_TALISMAN"));
				if (e.getCause() == DamageCause.FIRE) Talisman.checkFor(e, SlimefunItem.getByID("FIRE_TALISMAN"));
				if (e.getCause() == DamageCause.ENTITY_ATTACK) Talisman.checkFor(e, SlimefunItem.getByID("WARRIOR_TALISMAN"));
				if (e.getCause() == DamageCause.ENTITY_ATTACK) Talisman.checkFor(e, SlimefunItem.getByID("KNIGHT_TALISMAN"));
				if (e.getCause() == DamageCause.PROJECTILE) {
					if (Talisman.checkFor(e, SlimefunItem.getByID("WHIRLWIND_TALISMAN"))) {
						if (((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
							Vector direction = ((Player) e.getEntity()).getEyeLocation().getDirection().multiply(2.0);
							Projectile projectile = (Projectile) e.getEntity().getWorld().spawnEntity(((LivingEntity) e.getEntity()).getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), ((EntityDamageByEntityEvent) e).getDamager().getType());
							projectile.setVelocity(direction);
							((EntityDamageByEntityEvent) e).getDamager().remove();
						}
					}
				}
			}
		}
	}
}
 
开发者ID:StarWishsama,项目名称:Slimefun4-Chinese-Version,代码行数:34,代码来源:TalismanListener.java

示例7: onDamage

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onDamage(EntityDamageEvent event) {
    MatchPlayer victim = getVictim(event.getEntity());
    if(victim == null) return;
    final DamageInfo info = damageResolver.resolveDamage(event);
    processDamageEvent(event, victim.getParticipantState(), info);
    if(!event.isCancelled()) {
        getMatch().callEvent(new MatchPlayerDamageEvent(event, victim, info));
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:11,代码来源:DamageMatchModule.java

示例8: onDamage

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onDamage(EntityDamageEvent e)
{
	if(e.isCancelled()) return;
	if(e.getEntity() instanceof Player)
	{
		Player player = (Player)e.getEntity();
		
		e.setDamage(e.getDamage() * addMultiplier(player));
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:12,代码来源:FoodDiversityConsume.java

示例9: onEntityDamage

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
/**
 * Set Potion Effect SLOWNESS I when player takes fall damage
 * @param event Entity Damage Event
 */
@EventHandler
public void onEntityDamage(EntityDamageEvent event)
{
    if (event.getEntity() instanceof Player && event.getCause() == EntityDamageEvent.DamageCause.FALL && !event.isCancelled())
        ((Player) event.getEntity()).addPotionEffect(PotionEffectType.SLOW.createEffect((int) this.moduleConfiguration.get("penalty-time") * 20, 1));
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:11,代码来源:CrippleModule.java

示例10: onDamage

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
/**
 * Fire player on damage
 * @param event Event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onDamage(EntityDamageEvent event)
{
    if (((SurvivalGame) SamaGamesAPI.get().getGameManager().getGame()).isDamagesActivated()
            && event.getEntityType() == EntityType.PLAYER
            && event.getCause() != EntityDamageEvent.DamageCause.FIRE
            && event.getCause() != EntityDamageEvent.DamageCause.FIRE_TICK
            && event.getDamage() > 0
            && !event.isCancelled())
        event.getEntity().setFireTicks((int) this.moduleConfiguration.get("fire-time") * 20);
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:16,代码来源:PyroTechnicsModule.java

示例11: call

import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@Override
public void call(Event event) {
	if (event instanceof PlayerMoveEvent) {
		final PlayerMoveEvent pme = (PlayerMoveEvent) event;

		final Player player = profile.getPlayer();

		/*
		 * Players cannot take fall damage when in creative or spectator
		 * mode.
		 */
		if (!profile.getBehaviour().isInCreativeOrSpectator()) {

			final Material from = pme.getFrom().getBlock().getRelative(BlockFace.DOWN).getType();
			final Material to = pme.getTo().getBlock().getRelative(BlockFace.DOWN).getType();

			final double fallDistance = profile.getBehaviour().getMotion().getFallDistance();

			if (fallDistance < 4.0) {
				/*
				 * The player has not fallen enough distance to take fall
				 * damage.
				 */
				return;
			}

			// The player has fallen far enough to take damage.

			final Behaviour behaviour = profile.getBehaviour();

			// Check if player has moved from air to ground.
			if (from == Material.AIR && to != Material.AIR) {

				if (!behaviour.isInWater() && !behaviour.isInWeb() && !player.isInsideVehicle()
						&& !player.isSleeping()) {

					/*
					 * Their expected health cannot be higher than their
					 * maximum allowed health and cannot be lower then zero.
					 */
					final double expected = Math
							.max(Math.min(player.getHealth() - getExpectedDamage(profile, fallDistance),
									player.getMaxHealth()), 0.0);

					/*
					 * Check a bit later if their health is higher than it
					 * is expected to be.
					 */
					Bukkit.getScheduler().runTaskLater(Crescent.getInstance(), () -> {
						callback(!fallCancelled && player.getHealth() > expected);
					}, 5L);

				}
			}
		}
	} else if (event instanceof EntityDamageEvent) {
		final EntityDamageEvent ede = (EntityDamageEvent) event;

		fallCancelled = ede.getCause() == DamageCause.FALL && ede.isCancelled();
	}
}
 
开发者ID:davidm98,项目名称:Crescent,代码行数:62,代码来源:NoFallA.java


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