本文整理汇总了Java中org.bukkit.entity.LivingEntity.setHealth方法的典型用法代码示例。如果您正苦于以下问题:Java LivingEntity.setHealth方法的具体用法?Java LivingEntity.setHealth怎么用?Java LivingEntity.setHealth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.LivingEntity
的用法示例。
在下文中一共展示了LivingEntity.setHealth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPetFeed
import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
@EventHandler
public void onPetFeed(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
ItemStack itemInHand = player.getEquipment().getItemInMainHand();
if (!InventoryManager.playerIsLoaded(player)) {
return;
}
PlayerWrapper playerWrapper = InventoryManager.get(player);
if (PetFood.isFoodItem(itemInHand) && playerWrapper.hasPet() && event.getRightClicked() == playerWrapper.getPet()) {
event.setCancelled(true);
LivingEntity pet = (LivingEntity) event.getRightClicked();
PetFood petFood = PetManager.getFoodFromItem(itemInHand);
if (pet.getHealth() == pet.getMaxHealth() || petFood == null || !petFood.canBeEaten(playerWrapper.getPet())) {
return;
}
double health = pet.getHealth() + petFood.getValue();
pet.setHealth(health < pet.getMaxHealth() ? health : pet.getMaxHealth());
itemInHand.setAmount(itemInHand.getAmount() - 1);
player.getEquipment().setItemInMainHand(itemInHand);
pet.getWorld().playSound(pet.getLocation(), Sound.ENTITY_GENERIC_EAT, 1.0f, (float) (1.0 + Math.random() * 0.4));
}
}
示例2: offenseEffect
import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
@Override
public void offenseEffect(LivingEntity user, LivingEntity target, EntityDamageByEntityEvent event){
user.setHealth(user.getHealth() + (event.getDamage()/4));
}