Java Code Examples for org.bukkit.event.entity.EntityRegainHealthEvent#getRegainReason()

The following examples show how to use org.bukkit.event.entity.EntityRegainHealthEvent#getRegainReason() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeathListener.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onFoodHeal(EntityRegainHealthEvent event) {
    if (event.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED ||
            ConfigManager.getInstance().getFoodHealInCombat()) {
        return;
    }
    if (!(event.getEntity() instanceof Player)) {
        return;
    }
    Player player = (Player) event.getEntity();
    Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId());
    if (!civilian.isInCombat()) {
        return;
    }
    event.setCancelled(true);
}
 
Example 2
Source File: RegainHealth.java    From MarriageMaster with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHeal(EntityRegainHealthEvent event)
{
	if(event.getEntity() instanceof Player)
	{
		MarriagePlayer player = plugin.getPlayerData((Player) event.getEntity());
		if(player.isMarried())
		{
			Marriage marriage = player.getNearestPartnerMarriageData();
			if(marriage != null && marriage.inRangeSquared(range))
			{
				BonusHealEvent bonusHealEvent = new BonusHealEvent(player, marriage, event.getAmount() * multiplier, event.getRegainReason());
				plugin.getServer().getPluginManager().callEvent(bonusHealEvent);
				if(!bonusHealEvent.isCancelled())
				{
					event.setAmount(bonusHealEvent.getAmount());
				}
			}
		}
	}
}
 
Example 3
Source File: UHPluginListener.java    From KTP with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityRegainHealth(final EntityRegainHealthEvent ev) {
	if (ev.getRegainReason() == RegainReason.SATIATED) ev.setCancelled(true);
	if (ev.getEntity() instanceof Player) {
		Bukkit.getScheduler().runTaskLater(this.p, new BukkitRunnable() {
			
			@Override
			public void run() {
				p.updatePlayerListName((Player)ev.getEntity());
			}
		}, 1L);
	}
}