1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

putVector3Obj Packet error

Discussion in 'Development' started by rektpixel, Oct 24, 2017.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    Hello this plugin has an error, something to do with putVector3Obj
    this is the code:
    PHP:
        public function onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool{
            switch(
    $cmd->getName()) {
                case 
    "music":
                    if(isset(
    $args[0])){
                        switch(
    $args[0]){
                            case 
    "next":
                                
    $this->StartNewTask();
                                
    $sender->sendMessage(TextFormat::GREEN."Switched to next song");
                                return 
    true;
                                break;
                            case 
    "stop":
                                if(
    $sender->isOp()){
                                    
    $this->getServer()->getScheduler()->cancelTasks($this);
                                    
    $sender->sendMessage(TextFormat::GREEN."Song Stopped");
                                }else{
                                    
    $sender->sendMessage(TextFormat::RED."No Permission");
                                }
                                return 
    true;
                                break;   
                            case 
    "start":
                                if(
    $sender->isOp()){
                                    
    $this->StartNewTask();
                                    
    $sender->sendMessage(TextFormat::GREEN."Song Started");
                                }else{
                                    
    $sender->sendMessage(TextFormat::RED."No Permission");
                                }
                                return 
    true;
                                break;   
                        }
                    }else{
                        
    $sender->sendMessage(TextFormat::RED."Usage:/music <start|stop|next>");
                    }
                break;       
            }
        }
        
        public function 
    CheckMusic(){
            if(
    $this->getDirCount($this->getPluginDir()) > and $this->RandomFile($this->getPluginDir(),"nbs")){
                return 
    true;
            }
            return 
    false;
        }
        
        public function 
    getDirCount($PATH){
                  
    $num sizeof(scandir($PATH));
                  
    $num = ($num>2)?$num-2:0;
            return 
    $num;
        }
        
        public function 
    getPluginDir(){
            return 
    $this->getServer()->getDataPath()."plugins/songs/";
        }
        
        public function 
    getRandomMusic(){
            
    $dir $this->RandomFile($this->getPluginDir(),"nbs");
            if(
    $dir){
                
    $api = new NoteBoxAPI($this,$dir);
                return 
    $api;
            }
            return 
    false;
        }
        
        Public function 
    RandomFile($folder=''$extensions='.*'){
            
    $folder trim($folder);
            
    $folder = ($folder == '') ? './' $folder;
            if (!
    is_dir($folder)){
                return 
    false;
            }
            
    $files = array();
            if (
    $dir = @opendir($folder)){
                while(
    $file readdir($dir)){
                    if (!
    preg_match('/^\.+$/'$file) and
                        
    preg_match('/\.('.$extensions.')$/'$file)){
                        
    $files[] = $file;       
                    }     
                }   
                
    closedir($dir); 
            }else{
                return 
    false;
            }
            if (
    count($files) == 0){
                return 
    false;
            }
            
    mt_srand((double)microtime()*1000000);
            
    $rand mt_rand(0count($files)-1);
            if (!isset(
    $files[$rand])){
                return 
    false;
            }
            if(
    function_exists("iconv")){
                
    $rname iconv('gbk','UTF-8',$files[$rand]);
            }else{
                
    $rname $files[$rand];
            }
            
    $this->name str_replace('.nbs'''$rname);
            return 
    $folder $files[$rand];
        }
        
        public function 
    getNearbyNoteBlock($x,$y,$z,$world){
            
    $nearby = [];
            
    $minX $x 5;
            
    $maxX $x 5;   
            
    $minY $y 5;
            
    $maxY $y 5;
            
    $minZ $z 2;
            
    $maxZ $z 2;
            
            for(
    $x $minX$x <= $maxX; ++$x){
                for(
    $y $minY$y <= $maxY; ++$y){
                    for(
    $z $minZ$z <= $maxZ; ++$z){
                        
    $v3 = new Vector3($x$y$z);
                        
    $block $world->getBlock($v3);
                        if(
    $block->getID() == 25){
                            
    $nearby[] = $block;
                        }
                    }
                }
            }
            return 
    $nearby;
        }
        
        public function 
    getFullBlock($x$y$z$level){
            return 
    $level->getChunk($x >> 4$z >> 4false)->getFullBlock($x 0x0f$y 0x7f$z 0x0f);
        }
     
        public function 
    Play($sound,$type 0,$blo 0){
            if(
    is_numeric($sound) and $sound 0){
                foreach(
    $this->getServer()->getOnlinePlayers() as $p){
                    
    $noteblock $this->getNearbyNoteBlock($p->x,$p->y,$p->z,$p->getLevel());
                    
    $noteblock1 $noteblock;
                    if(!empty(
    $noteblock)){
                        if(
    $this->song->name != ""){
                            
    $p->sendPopup("§b|->§6Now Playing: §a".$this->song->name."§b<-|");
                        }else{   
                            
    $p->sendPopup("§b|->§6Now Playing: §a".$this->name."§b<-|");
                        }
                        
    $i 0;
                        while (
    $i $blo){
                            if(
    current($noteblock)){
                                
    next($noteblock);
                                
    $i ++;
                            }else{
                                
    $noteblock $noteblock1;
                                
    $i ++;
                            }
                        }
                        
    $block current($noteblock);
                        if(
    $block){
                            
    $pk = new BlockEventPacket();
                            
    $pk->$block->x;
                            
    $pk->$block->y;
                            
    $pk->$block->z;
                            
    $pk->case1 $type;
                            
    $pk->case2 $sound;
                            
    $p->dataPacket($pk);
                            
    $pk = new LevelSoundEventPacket();
                            
    $pk->sound LevelSoundEventPacket::SOUND_NOTE;
                            
    $pk->$block->x;
                            
    $pk->$block->y;
                            
    $pk->$block->z;
                            
    $pk->volume $type;
                            
    $pk->pitch $sound;
                            
    $pk->unknownBool true;
                            
    $pk->unknownBool2 true;
                            
    $p->dataPacket($pk);
                        }
                    }
                }
            }
        }
            
        public function 
    onDisable(){
            
    $this->getLogger()->info("ZMusicBox Unload Success!");
        }
        
        public function 
    StartNewTask(){
            
    $this->song $this->getRandomMusic();
            
    $this->getServer()->getScheduler()->cancelTasks($this);
            
    $this->MusicPlayer = new MusicPlayer($this);
            
    $this->getServer()->getScheduler()->scheduleRepeatingTask($this->MusicPlayer2990 $this->song->speed );
        }
        
    }
    class 
    MusicPlayer extends PluginTask{
        public function 
    __construct(ZMusicBox $plugin){
            
    parent::__construct($plugin);
            
    $this->plugin $plugin;
        }
        
        public function 
    onRun($CT){
            if(isset(
    $this->plugin->song->sounds[$this->plugin->song->tick])){
                
    $i 0;
                foreach(
    $this->plugin->song->sounds[$this->plugin->song->tick] as $data){
                    
    $this->plugin->Play($data[0],$data[1],$i);
                    
    $i++;
                }
            }
            
    $this->plugin->song->tick++;
            if(
    $this->plugin->song->tick $this->plugin->song->length){
                
    $this->plugin->StartNewTask();
            }
        }
    }
    this is the error:
    Code:
    [18:12:19] [Server thread/CRITICAL]: Could not execute task ZMusicBox\MusicPlayer: Argument 1 passed to pocketmine\network\mcpe\protocol\DataPacket::putVector3Obj() must be an instance of pocketmine\math\Vector3, null given, called in phar://C:/Users/Admin/Creative Cloud Files/Desktop/MusicalChairsServer/MusicalChairs - DEV/PocketMine-MP.phar/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php on line 220
    [18:12:19] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\network\mcpe\protocol\DataPacket::putVector3Obj() must be an instance of pocketmine\math\Vector3, null given, called in phar://C:/Users/Admin/Creative Cloud Files/Desktop/MusicalChairsServer/MusicalChairs - DEV/PocketMine-MP.phar/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php on line 220" (EXCEPTION) in "src/pocketmine/network/mcpe/protocol/DataPacket" at line 446
    
    could someone help me fix this?:eek:
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Some packets had their $x, $y and $z properties switched with a Vector3 "$position" due to... you know.. obvious reasons.
    Reference: https://github.com/pmmp/PocketMine-...ne/network/mcpe/protocol/LevelEventPacket.php
    Commit: https://github.com/pmmp/PocketMine-...8427abb#diff-73068e8c4753a400021b12737fa4a45f
     
    jasonwynn10 and rektpixel like this.
  3. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    so would it be..
    PHP:
                            $pk = new BlockEventPacket();
                            
    //$pk->x = $block->x;
                            
    $pk->position = new Vector3($block->x);
                            
    //$pk->y = $block->y;
                            
    $pk->position = new Vector3($block->y);
                            
    //$pk->z = $block->z;
                            
    $pk->position = new Vector3($block->z);
                            
    $pk->case1 $type;
                            
    $pk->case2 $sound;
                            
    $p->dataPacket($pk);
                            
    $pk = new LevelSoundEventPacket();
                            
    $pk->sound LevelSoundEventPacket::SOUND_NOTE;
                            
    //$pk->x = $block->x;
                            
    $pk->position = new Vector3($block->x);
                            
    //$pk->y = $block->y;
                            
    $pk->position = new Vector3($block->y);
                            
    //$pk->z = $block->z;
                            
    $pk->position = new Vector3($block->z);
                            
    $pk->volume $type;
                            
    $pk->pitch $sound;
                            
    $pk->unknownBool true;
                            
    $pk->unknownBool2 true;
                            
    $p->dataPacket($pk);
    ?:eek:
     
  4. SleepSpace9

    SleepSpace9 Slime

    Messages:
    78
    GitHub:
    sleepspace9
    You could use:
    Code:
    $pk->position = $block->asVector3();
     
    MC ATECH and jasonwynn10 like this.
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    wth is this logic?? Look at the constructor parameters of the Vector3 class
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.