public function exhaust(float $amount, int $cause = PlayerExhaustEvent::CAUSE_CUSTOM) : float
{
$this->server->getPluginManager()->callEvent($ev = new PlayerExhaustEvent($this, $amount, $cause));
if ($ev->isCancelled()) {
return 0.0;
}
$exhaustion = $this->getExhaustion();
$exhaustion += $ev->getAmount();
while ($exhaustion >= 4.0) {
$exhaustion -= 4.0;
$saturation = $this->getSaturation();
if ($saturation > 0) {
$saturation = max(0, $saturation - 1.0);
$this->setSaturation($saturation);
} else {
$food = $this->getFood();
if ($food > 0) {
$food--;
$this->setFood($food);
}
}
}
$this->setExhaustion($exhaustion);
return $ev->getAmount();
}