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

How to fix must be compatible with fast

Discussion in 'Plugin Help' started by Ayush, Mar 27, 2021.

  1. Ayush

    Ayush Witch

    Messages:
    62
    So I' really want to fix this error
    Spoiler;)
    Code:
     Error: Declaration of particle\Main::__construct(pocketmine\level\Location &$location, bool $sphere) 
    
    must be compatible with pocketmine\plugin\Plugin::__construct(pocketmine\plugin\PluginLoader $loader, pocketmine\Server $server, pocketmine\plugin\PluginDescription $description, string $dataFolder, string $file)
    
    File: plugins/SpawnParticlesByAotGamerz.phar/src/particle/Main
    Line: 50
    Type: E_COMPILE_ERROR
    Code is
    PHP:
    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmind\level\Level;
    use 
    pocketmine\level\Location;
    use 
    pocketmine\level\particle\FlameParticle;;

    class 
    Main extends PluginBase {

        private 
    $radius 3;
        private 
    $particles 50;
        private 
    $location$level;
        private 
    $sphere false;

        public function 
    __construct(Location &$locationbool $sphere)
        {
            
    $this->level $location->getLevel();
            
    $this->location = &$location;
            
    $this->sphere $sphere;
        }

        private static function 
    getRandomVector() : Vector3
        
    {
            
    $x 0$y 0$z 0;
            
    $x rand()/getrandmax() * 1;
            
    $y rand()/getrandmax() * 1;
            
    $z rand()/getrandmax() * 1;
            
    $v = new Vector3($x$y$z);
            return 
    $v->normalize();
        }

        public function 
    onRun($tick) {
            for (
    $i 0$i $this->particles; ++$i) {
                
    $vector self::getRandomVector()->multiply($this->radius);
                if (!
    $this->sphere) {
                    
    $vector->abs($vector->getY());
                }
                
    $this->level->addParticle(new FlameParticle($this->location->add($vector->x$vector->y$vector->z)));
                
    $this->location->add($vector->x$vector->y$vector->z);
            }
        }

    }
    Pls try to do fast:(:oops:
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    Don't override the __construct method. That is reserved for internal use. Move those properties elsewhere. Or simply initialize them onEnable()
     
    Ayush and minijaham like this.
  3. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Are you sure you are extending the right class? This structure seems more like a Task than a plugin (you are extending PluginBase)
     
    Ayush likes this.
  4. Ayush

    Ayush Witch

    Messages:
    62
    Like this?
    PHP:

    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmind\level\Level;
    use 
    pocketmine\level\Location;
    use 
    pocketmine\level\particle\FlameParticle;;

    class 
    Main extends PluginBase {

        private 
    $radius 3;
        private 
    $particles 50;
        private 
    $location$level;
        private 
    $sphere false;

         private static function 
    getRandomVector() : Vector3
        
    {
            
    $x 0$y 0$z 0;
            
    $x rand()/getrandmax() * 1;
            
    $y rand()/getrandmax() * 1;
            
    $z rand()/getrandmax() * 1;
            
    $v = new Vector3($x$y$z);
            return 
    $v->normalize();
        }

        public function 
    onRun($tick) {
            for (
    $i 0$i $this->particles; ++$i) {
                
    $vector self::getRandomVector()->multiply($this->radius);
                if (!
    $this->sphere) {
                    
    $vector->abs($vector->getY());
                }
                
    $this->level->addParticle(new FlameParticle($this->location->add($vector->x$vector->y$vector->z)));
                
    $this->location->add($vector->x$vector->y$vector->z);
            }
        }

    }
     
  5. Ayush

    Ayush Witch

    Messages:
    62
    I tried to fix alot of time is gone waste mein wasted{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}
     
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Im not sure where you get those code from, but I would imagine it to be used in this way, you get the idea
    PHP:
    class Main extends PluginBase{
       function 
    onEnable(){
    $l $this->getServer()->getDefaultLevel()->getSpawnLocation();
          
    $this->getScheduler()->scheduleRepeatingTask(new Draw(Location::fromObject($l,$l->getLevel()),true),1);
       }
    }
    class 
    Draw extends Task {
        private 
    $radius 3;
        private 
    $particles 50;
        private 
    $location$level;
        private 
    $sphere false;

        public function 
    __construct(Location &$locationbool $sphere)
        {
            
    $this->level $location->getLevel();
            
    $this->location = &$location;
            
    $this->sphere $sphere;
        }

        private static function 
    getRandomVector() : Vector3
        
    {
            
    $x 0$y 0$z 0;
            
    $x rand()/getrandmax() * 1;
            
    $y rand()/getrandmax() * 1;
            
    $z rand()/getrandmax() * 1;
            
    $v = new Vector3($x$y$z);
            return 
    $v->normalize();
        }

        public function 
    onRun($tick) {
            for (
    $i 0$i $this->particles; ++$i) {
                
    $vector self::getRandomVector()->multiply($this->radius);
                if (!
    $this->sphere) {
                    
    $vector->abs($vector->getY());
                }
                
    $this->level->addParticle(new FlameParticle($this->location->add($vector->x$vector->y$vector->z)));
                
    $this->location->add($vector->x$vector->y$vector->z);
            }
        }

    }
     
    Ayush, DavyCraft648 and Primus like this.
  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.