Help me pls plugin

Ребята подскажите пожалуйста как можно решить проблему: я хочу что бы игрок садился ровно на поверхность, а сейчас когда я прописываю /sit игрок проваливается под блок и только потом садится, или например если я хочу сесть в воздухе, меня тянет к земле я опять проваливаюсь под блок и только потом сажусь, pmmp 3 php 8 заранее спасибо!
Chair.php:

<?php

namespace Sit;

use pocketmine\entity\Entity;
use pocketmine\entity\Item;
use pocketmine\Player;
use pocketmine\Server;

use pocketmine\nbt\tag\ByteTag;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\SetEntityLinkPacket;

class Chair extends Entity {

    const NETWORK_ID = -1;

    const SITTING_ACTION_ID = 2;

    const STAND_ACTION_ID = 3;

    public $canCollide = false;

    private $sittingEntity = null;

    protected function initEntity(){
        parent::initEntity();

        if(isset($this->namedtag->remove)){//flag check
            $this->kill();
        }
    }

    public function spawnTo(Player $player){
        $pk = new AddEntityPacket();
        $pk->eid = $this->getId();
        $pk->type = Item::NETWORK_ID;
        $pk->x = $this->x;
        $pk->y = $this->y;
        $pk->z = $this->z;
        $pk->speedX = 0;
        $pk->speedY = 0;
        $pk->speedZ = 0;
        $pk->yaw = 0;
        $pk->pitch = 0;
        $flags = (1 << Entity::DATA_FLAG_IMMOBILE | 1 << Entity::DATA_FLAG_SILENT | 1 << Entity::DATA_FLAG_INVISIBLE);
        $pk->metadata = [
            Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, $flags]];
        /*$pk->metadata = [
            Entity::DATA_FLAGS => [Entity::DATA_TYPE_BYTE, 1 << Entity::DATA_FLAG_INVISIBLE],
            Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, ""],
            Entity::DATA_RIDER_SEAT_POSITION => [Entity::DATA_TYPE_VECTOR3F, [0, 2, 0]],
            Entity::DATA_RIDER_ROTATION_LOCKED => [Entity::DATA_TYPE_BYTE, 1],
            Entity::DATA_CONTROLLING_RIDER_SEAT_NUMBER => [Entity::DATA_TYPE_BYTE, 1],
            Entity::DATA_RIDER_MIN_ROTATION => [Entity::DATA_TYPE_FLOAT, 1],
            Entity::DATA_RIDER_MAX_ROTATION => [Entity::DATA_TYPE_FLOAT, 181],
            //Entity::DATA_SHOW_NAMETAG => [Entity::DATA_TYPE_BYTE, 1],
            //Entity::DATA_NO_AI => [Entity::DATA_TYPE_BYTE, 1],
            Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0]
        ];*/
        $player->dataPacket($pk);

        if($this->sittingEntity !== null){
            $this->sendLinkPacket($player, self::SITTING_ACTION_ID);
        }

        parent::spawnTo($player);
    }

    public function close(){
        if(!$this->closed){
            if($this->sittingEntity !== null){
                $this->standupSittingEntity();
            }
        }
        parent::close();
    }

    public function saveNBT(){
        parent::saveNBT();
        $this->namedtag->remove = new ByteTag("remove", 1);//remove flag
    }

    //

    public function getSittingEntity(){
        return $this->sittingEntity;
    }

    public function sitEntity(Entity $entity){
        if($this->sittingEntity != null){
            return false;
        }

        $this->sittingEntity = $entity;

        $this->sendLinkPacketToAll(self::SITTING_ACTION_ID);

        if($this->sittingEntity instanceof Player){
            $this->sendLinkPacketToSittingPlayer(self::SITTING_ACTION_ID);
        }

        return true;
    }
    public function standupSittingEntity(){
        if($this->sittingEntity === null){
            return false;
        }
        $this->sendLinkPacketToAll(self::STAND_ACTION_ID);
        if($this->sittingEntity instanceof Player){
            $this->sendLinkPacketToSittingPlayer(self::STAND_ACTION_ID);
        }

        $this->sittingEntity = null;
        return true;
    }

    public function sendLinkPacket(Player $player, $type){
        if($this->sittingEntity === null){
            return false;
        }
        $pk = new SetEntityLinkPacket();
        $pk->from = $this->getId();
        $pk->to = $this->sittingEntity->getId();
        $pk->type = $type;

        $player->dataPacket($pk);
        return true;
    }

    public function sendLinkPacketToSittingPlayer($type){
        if($this->sittingEntity === null or !($this->sittingEntity instanceof Player)){
            return false;
        }

        $pk = new SetEntityLinkPacket();
        $pk->from = $this->getId();
        $pk->to = 0;
        $pk->type = $type;

        $this->sittingEntity->dataPacket($pk);
        return true;
    }

    public function sendLinkPacketToAll($type){
        if($this->sittingEntity === null){
            return false;
        }

        $players = $this->level->getPlayers();
        foreach($players as $player){
            $this->sendLinkPacket($player, $type);
        }
        return true;
    }
}

Sit.php:

<?php

namespace Sit;


use Sit\Chair;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\entity\Entity;
use pocketmine\event\entity\EntityDespawnEvent;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\Info;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerToggleFlightEvent;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\Server;


class Sit extends PluginBase implements Listener{	
  public $sited = array();
  private $usedChairs = array();

    public function onEnable()
    {
        Entity::registerEntity(Chair::class, true);
        Server::getInstance()->getPluginManager()->registerEvents($this, $this);
    }

public function onMove(PlayerMoveEvent $event){
$player = $event->getPlayer();
$nick = strtolower($player->getName());
$x = $player->getX();
$z = $player->getZ();
$cords = "{$x},{$z}";
	if(isset($this->sited[$nick]) && $cords !== $this->sited[$nick]){
		
		 unset($this->sited[$nick]);
foreach(Server::getInstance()->getOnlinePlayers() as $pl){
		$pl->hidePlayer($player);
		 }
foreach(Server::getInstance()->getOnlinePlayers() as $pl){
	$pl->showPlayer($player);
		 }
		
}
}
    public function onCommand(CommandSender $sender, Command $command, $label, array $args)
    {
		$player = $sender;
		$nick = strtolower($sender->getName());
        if ($command->getName() == "sit") {
			   if(!$player->hasPermission("cmd.sit") && !$player->isOp()) return $player->sendMessage("§c§l> §cНедостаточно прав на использование данной команды");
            if ($sender->isSleeping()) {
                $sender->stopSleep();
            }
            $chair = new Chair($sender->level, new CompoundTag("", [
                new ListTag("Pos", [
                    new DoubleTag("", $sender->x),
                    new DoubleTag("", $sender->y),
                    new DoubleTag("", $sender->z)
                ]),
                new ListTag("Motion", [
                    new DoubleTag("", $sender->motionX),
                    new DoubleTag("", $sender->motionY),
                    new DoubleTag("", $sender->motionZ)
                ]),
                new ListTag("Rotation", [
                    new FloatTag("", $sender->yaw),
                    new FloatTag("", $sender->pitch)
                ])]));
            $chair->spawnToAll();
            $chair->sitEntity($sender);
            $sender->sendMessage("§r§8(§bОтдых§8) §fВы §eУспешно §fприсели отдохнуть");
			$x = $sender->getX();
			$z = $sender->getZ();
			$this->sited[$nick] = "{$x},{$z}";
			
        }
    }
	
	
	
	
	
	
	
	
	
	public function tap(PlayerInteractEvent $e) {
		$nick = strtolower($e->getPlayer()->getName());
		$player = $e->getPlayer();
		$id = $e->getBlock()->getId();
		if($id == 53 or $id == 134 or $id == 135 or $id == 136 or $id == 163 or $id == 164){
			if($player->getItemInHand()->getId() !== 0) return false;
			            if ($e->getPlayer()->isSleeping()) {
                $e->getPlayer()->stopSleep();
				$b = $e->getBlock();
            }
            $chair = new Chair($e->getPlayer()->level, new CompoundTag("", [
                new ListTag("Pos", [
                    new DoubleTag("", $e->getBlock()->x),
                    new DoubleTag("", $e->getBlock()->y),
                    new DoubleTag("", $e->getBlock()->z)
                ]),
                new ListTag("Motion", [
                    new DoubleTag("", $e->getPlayer()->motionX),
                    new DoubleTag("", $e->getPlayer()->motionY),
                    new DoubleTag("", $e->getPlayer()->motionZ)
                ]),
                new ListTag("Rotation", [
                    new FloatTag("", $e->getPlayer()->yaw),
                    new FloatTag("", $e->getPlayer()->pitch)
                ])]));
            $chair->spawnToAll();
            $chair->sitEntity($e->getPlayer());
				$x = $e->getBlock()->x + 1;
			$z = $e->getBlock()->z + 1;
				$this->sited[$nick] = "{$x},{$z}";
	
        }
}
	
	

    public function onDespawn(EntityDespawnEvent $event)
    {
        $entity = $event->getEntity();
        if ($entity instanceof Player) {
            $this->closeOldChair($entity);
        }
    }

    public function closeOldChair(Player $player)
    {
        if (isset($this->usedChairs[$player->getName()])) {
            $this->usedChairs[$player->getName()]->close();
            unset($this->usedChairs[$player->getName()]);
        }
    }

}

?>

зачем, и главное нахуя?

Комментарий, что такого?

это перечёркнутый кусок кода

1 лайк

Комментарий не обрабатывается

<?php

namespace Sit;

use pocketmine\entity\Entity;
use pocketmine\entity\Item;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\SetEntityLinkPacket;

class Chair extends Entity {

    const NETWORK_ID = -1;

    const SITTING_ACTION_ID = 2;

    const STAND_ACTION_ID = 3;

    public bool $canCollide = false;

    private $sittingEntity = null;

    protected function initEntity(){
        parent::initEntity();

        if(isset($this->namedtag->remove)){//flag check
            $this->kill();
        }
    }

    public function spawnTo(Player $player){
        $pk = new AddEntityPacket();
        $pk->eid = $this->getId();
        $pk->type = Item::NETWORK_ID;
        $pk->x = $this->x;
        $pk->y = $this->y;
        $pk->z = $this->z;
        $pk->speedX = 0;
        $pk->speedY = 0;
        $pk->speedZ = 0;
        $pk->yaw = 0;
        $pk->pitch = 0;
        $flags = (1 << Entity::DATA_FLAG_IMMOBILE | 1 << Entity::DATA_FLAG_SILENT | 1 << Entity::DATA_FLAG_INVISIBLE);
        $pk->metadata = [
            Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, $flags],
            Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, ""],
            Entity::DATA_RIDER_SEAT_POSITION => [Entity::DATA_TYPE_VECTOR3F, [0, 2, 0]],
            Entity::DATA_RIDER_ROTATION_LOCKED => [Entity::DATA_TYPE_BYTE, 1],
            Entity::DATA_CONTROLLING_RIDER_SEAT_NUMBER => [Entity::DATA_TYPE_BYTE, 1],
            Entity::DATA_RIDER_MIN_ROTATION => [Entity::DATA_TYPE_FLOAT, 1],
            Entity::DATA_RIDER_MAX_ROTATION => [Entity::DATA_TYPE_FLOAT, 181],
            Entity::DATA_NO_AI => [Entity::DATA_TYPE_BYTE, 1],
            Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT, 0]
        ];
        $player->dataPacket($pk);

        if($this->sittingEntity !== null){
            $this->sendLinkPacket($player, self::SITTING_ACTION_ID);
        }

        parent::spawnTo($player);
    }

    public function close(){
        if(!$this->closed){
            if($this->sittingEntity !== null){
                $this->standupSittingEntity();
            }
        }
        parent::close();
    }

    public function saveNBT(){
        parent::saveNBT();
        $this->namedtag->remove = new ByteTag("remove", 1);//remove flag
    }

    public function getSittingEntity(){
        return $this->sittingEntity;
    }

    public function sitEntity(Entity $entity){
        if($this->sittingEntity != null){
            return false;
        }

        $this->sittingEntity = $entity;

        $this->sendLinkPacketToAll(self::SITTING_ACTION_ID);

        if($this->sittingEntity instanceof Player){
            $this->sendLinkPacketToSittingPlayer(self::SITTING_ACTION_ID);
        }

        return true;
    }

    public function standupSittingEntity(){
        if($this->sittingEntity === null){
            return false;
        }
        $this->sendLinkPacketToAll(self::STAND_ACTION_ID);
        if($this->sittingEntity instanceof Player){
            $this->sendLinkPacketToSittingPlayer(self::STAND_ACTION_ID);
        }

        $this->sittingEntity = null;
        return true;
    }

    public function sendLinkPacket(Player $player, $type){
        if($this->sittingEntity === null){
            return false;
        }
        $pk = new SetEntityLinkPacket();
        $pk->from = $this->getId();
        $pk->to = $this->sittingEntity->getId();
        $pk->type = $type;

        $player->dataPacket($pk);
        return true;
    }

    public function sendLinkPacketToSittingPlayer($type){
        if($this->sittingEntity === null or !($this->sittingEntity instanceof Player)){
            return false;
        }

        $pk = new SetEntityLinkPacket();
        $pk->from = $this->getId();
        $pk->to = 0;
        $pk->type = $type;

        $this->sittingEntity->dataPacket($pk);
        return true;
    }

    public function sendLinkPacketToAll($type){
        if($this->sittingEntity === null){
            return false;
        }

        $players = $this->level->getPlayers();
        foreach($players as $player){
            $this->sendLinkPacket($player, $type);
        }
        return true;
    }
}
Entity::DATA_RIDER_SEAT_POSITION => [Entity::DATA_TYPE_VECTOR3F, [56]]

Правильно понял?

ясненько…

Вроде правильно, только добавь х, z и что такое 56?

на пм5

EntityMetadataCollection->setVector3(EntityMetadataProperties::RIDER_SEAT_POSITION, new Vector3(0, 0.3, 0));