Player: mark as not using item when held item slot is changed

closes #4538
This commit is contained in:
Dylan K. Taylor 2021-11-03 21:26:20 +00:00
parent 0356716e8e
commit 2405e45b35
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -73,6 +73,7 @@ use pocketmine\event\player\PlayerToggleSprintEvent;
use pocketmine\event\player\PlayerTransferEvent;
use pocketmine\form\Form;
use pocketmine\form\FormValidationException;
use pocketmine\inventory\CallbackInventoryListener;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\PlayerCursorInventory;
use pocketmine\inventory\transaction\action\DropItemAction;
@ -291,6 +292,17 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
parent::initEntity($nbt);
$this->addDefaultWindows();
$this->inventory->getListeners()->add(new CallbackInventoryListener(
function(Inventory $unused, int $slot) : void{
if($slot === $this->inventory->getHeldItemIndex()){
$this->setUsingItem(false);
}
},
function() : void{
$this->setUsingItem(false);
}
));
$this->firstPlayed = $nbt->getLong("firstPlayed", $now = (int) (microtime(true) * 1000));
$this->lastPlayed = $nbt->getLong("lastPlayed", $now);