public function setFood($amount)
{
if (!$this->server->foodEnabled) {
$amount = 20;
}
if ($amount > 20) {
$amount = 20;
}
if ($amount < 0) {
$amount = 0;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerHungerChangeEvent($this, $amount));
if ($ev->isCancelled()) {
return false;
}
$amount = $ev->getData();
if ($amount <= 6 && !($this->getFood() <= 6)) {
$this->setDataProperty(self::DATA_FLAG_SPRINTING, self::DATA_TYPE_BYTE, false);
} elseif ($amount > 6 && !($this->getFood() > 6)) {
$this->setDataProperty(self::DATA_FLAG_SPRINTING, self::DATA_TYPE_BYTE, true);
}
$this->food = $amount;
$this->getAttribute()->getAttribute(AttributeManager::MAX_HUNGER)->setValue($amount);
return true;
}