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

Erreur BufferEffectSet

Discussion in 'Development' started by jason54, May 12, 2018.

  1. jason54

    jason54 Creeper

    Messages:
    3
    GitHub:
    jason54pe
    how i can fix this?

    Code:
    [Server thread/CRITICAL]: ErrorException: "Non-static method pocketmine\entity\EffectInstance::getId() should not be called statically" (EXCEPTION) in "BlackEffect/src/BlackEffect/sets/BuffEffectSet" at line 41
    Code:
    <?php
    
    namespace BlackEffect\sets;
    
    use pocketmine\entity\Effect;
    use pocketmine\entity\EffectInstance;
    use pocketmine\Player;
    
    class BuffEffectSet extends EffectSet {
    
        /**
         * Apply the buffs to a player
         *
         * @param Player $player
         */
        public function applyBuffs(Player $player) {
            foreach($this->effects as $e) {
                $effect = clone $e;
                $player->addEffect(20 * 30);
            }
        }
    
        /**
         * Remove all buffs from a player
         *
         * @param Player $player
         */
        public function removeBuffs(Player $player) {
            foreach($this->effects as $e) {
                $player->removeEffect($e->getId());
            }
        }
    
        /**
         * Read buff data from config and parse effects into an array
         *
         * @param array $data
         */
        protected function parseEffects(array $data) {
            for($i = 0; $i < count($data); $i++) {
                $this->effects[] = EffectInstance::getId($data[$i]["id"]($data[$i]["amplifier"](20 * 30)));
            }
        }
    
    }
    
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You need to create a new instance of EffectInstance, what do you expect EffectInstance::getId() to return?
    PHP:
    $effect Effect::getEffect($data[$i]["id"]);
    $duration 20 30;
    $amplifier $data[$i]["amplifier"];
    $effectInstance = new EffectInstance($effect$duration$amplifier);
    Anyway, this should be helpful for you: http://php.net/manual/en/functions.arguments.php
     
  3. jason54

    jason54 Creeper

    Messages:
    3
    GitHub:
    jason54pe
    I managed to fix my now I have this error
    PHP:
    [Server thread/CRITICAL]: Error"Call to undefined function night_vision()" (EXCEPTIONin "BlackEffect/src/BlackEffect/sets/BuffEffectSet" at line 41

    PHP:
    <?php

    namespace BlackEffect\sets;

    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\entity\EffectInstance;
    use 
    pocketmine\Player;

    class 
    BuffEffectSet extends EffectSet {

        public function 
    applyBuffs(Player $player) {
            foreach(
    $this->effects as $e) {
                
    $effect = clone $e;
                
    $player->addEffect(20 30);
            }
        }

        public function 
    removeBuffs(Player $player) {
            foreach(
    $this->effects as $e) {
                
    $player->removeEffect($e->getId());
            }
        }

        protected function 
    parseEffects(array $data) {
            for(
    $i 0$i count($data); $i++) {
                
    $this->effects[] = Effect::getEffectByName($data[$i]["id"]($data[$i]["amplifier"](20 30)));
            }
        }

    }
     
  4. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    I think you have a code who you dont understand.
    You are getting an effect by his name so why are you using amplifier??
    In you array
    PHP:
    //getEffect  in PMMP
    public static function getEffectByName(string $name) : ?Effect{
            
    $const self::class . "::" strtoupper($name);
            if(\
    defined($const)){
                return 
    self::getEffect(\constant($const));
            }
            return 
    null;
        }
    You have to insert a name not anything else..
    And the error go with that, use correctly the function and it will work.
    Or just use a code who you understand
     
  5. jason54

    jason54 Creeper

    Messages:
    3
    GitHub:
    jason54pe

    peux tu juste me dire ou le mettre stp ? je parle aussi français
     
  6. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Go mp i will explain it to you we cant talk in french here
     
  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.