Implemented a proper way to handle items cooldown (#6405)

This commit is contained in:
ipad54
2024-09-25 21:28:17 +03:00
committed by GitHub
parent 4e6b34f573
commit f6e6f15c63
6 changed files with 86 additions and 4 deletions

View File

@ -30,6 +30,7 @@ use pocketmine\event\server\DataPacketDecodeEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\form\Form;
use pocketmine\item\Item;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\Translatable;
use pocketmine\math\Vector3;
@ -65,6 +66,7 @@ use pocketmine\network\mcpe\protocol\Packet;
use pocketmine\network\mcpe\protocol\PacketDecodeException;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlayerStartItemCooldownPacket;
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\network\mcpe\protocol\serializer\PacketBatch;
@ -111,6 +113,7 @@ use pocketmine\utils\BinaryDataException;
use pocketmine\utils\BinaryStream;
use pocketmine\utils\ObjectSet;
use pocketmine\utils\TextFormat;
use pocketmine\world\format\io\GlobalItemDataHandlers;
use pocketmine\world\Position;
use pocketmine\YmlServerProperties;
use function array_map;
@ -1289,6 +1292,13 @@ class NetworkSession{
$this->sendDataPacket(OpenSignPacket::create(BlockPosition::fromVector3($signPosition), $frontSide));
}
public function onItemCooldownChanged(Item $item, int $ticks) : void{
$this->sendDataPacket(PlayerStartItemCooldownPacket::create(
GlobalItemDataHandlers::getSerializer()->serializeType($item)->getName(),
$ticks
));
}
public function tick() : void{
if(!$this->isConnected()){
$this->dispose();