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


Java LivingEntity.damage方法代码示例

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


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

示例1: damageNearbyEnemies

import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
private void damageNearbyEnemies(Player player, int dmg)
{
	Collection<Entity> enemies = player.getLocation().getWorld().getNearbyEntities(player.getLocation().add(0, 0.5, 0), 3.5f, 1.5f, 3.5f);
    for(Entity e : enemies)
    {
    	if(e instanceof LivingEntity && e != (Entity)player)
    	{
    		LivingEntity enemy = (LivingEntity)e;
    		enemy.damage(dmg, (Entity)player);
    	}
    }
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:13,代码来源:Valkyrie.java

示例2: inflictDamage

import org.bukkit.entity.LivingEntity; //导入方法依赖的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

示例3: execute

import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
@Override
public void execute(KingdomFactionsPlayer player) {

	setLocation(player.getPlayer().getTargetBlock((Set<Material>) null, 80).getLocation());

	SpellExecuteEvent event = new SpellExecuteEvent(executeLocation, this, player);
	if (event.isCancelled())
		return;
	playSmoke(executeLocation);
	for (Entity e : Utils.getInstance().getNearbyEntities(executeLocation, 3)) {
		if (e instanceof LivingEntity) {
			LivingEntity en = (LivingEntity) e;

			if (e instanceof Player) {
				Player p = (Player) e;
				if (PlayerModule.getInstance().getPlayer(p).isVanished())
					return;
				if (en.getHealth() > 5) {
					en.damage(5D);
				} else {
					en.damage(en.getHealth());
				}
			}
		}
	}

}
 
开发者ID:ThEWiZ76,项目名称:KingdomFactions,代码行数:28,代码来源:Spark.java

示例4: damageNearbyEnemies

import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
private void damageNearbyEnemies(Player player, int dmg)
{
	Collection<Entity> enemies = player.getLocation().getWorld().getNearbyEntities(player.getLocation(), 2, 2, 2);
    for(Entity e : enemies)
    {
    	if(e instanceof LivingEntity && e != (Entity)player)
    	{
    		LivingEntity enemy = (LivingEntity)e;
    		enemy.damage(dmg, (Entity)player);
    	}
    }
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:13,代码来源:GiantBlade.java

示例5: onAttack

import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getEntity() instanceof Player)
	{
		Player player = (Player)event.getEntity();
		ItemStack offItem = player.getInventory().getItemInOffHand();

		if(dualWield.getScore(player).getScore() == 1)
		{
			event.setCancelled(true);
			return;
		}
		
		Random rand = new Random();
		
		if(offItem.getType() == Material.GOLD_HOE)
		{
			if(event.getDamager() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
			{
				LivingEntity enemy = (LivingEntity)event.getDamager();
				enemy.damage(event.getDamage() * 40 / 100, player);
			}
			
			int chance_reduceDur = rand.nextInt(10) + 1;
			switch(chance_reduceDur)
			{
				case 1:
					offItem.setDurability((short)(offItem.getDurability() + 1));
					break;
				default:
			}

			if(offItem.getDurability() >= 32)
			{
				player.getLocation().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
				player.getInventory().setItemInOffHand(null);
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:44,代码来源:GiantBlade.java

示例6: cast

import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
@Override
public void cast(Caster caster) {
	LivingEntity target = caster.getTargetLiving();
	target.damage(1);
}
 
开发者ID:mcardy,项目名称:MystiCraft,代码行数:6,代码来源:PunchSpell.java

示例7: attack

import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
/**
 * Attack the given target.
 * @param target
 */
public void attack(LivingEntity target) {
    target.damage(getDamage(), getSource());
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:8,代码来源:CustomAttack.java


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