Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

BUG: addEffect()

Comments in 'Plugin Development' started by Muqsit, Sep 10, 2016.

  1. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    PHP:
    public function onEquip(\pocketmine\event\entity\EntityArmorChangeEvent $e){
    $p $e->getEntity();
    if(!
    $p instance of \pocketmine\Player) return;
    $p->addEffect(\pocketmine\entity\Effect::getEffect(Effect::SPEED)->setDuration(4000));
    }
    This does work. But when you rejoin, it gives you an error?
    PHP:
    Call to....function getValue() on null
    (getValue() in \pocketmine\entity\Attribute.php)

    I have a feeling that I'm doing it wrong. Even tho it works smooth when the player changes armor or anything whlist fully connected. This error happens only when player joins.
  2. JUZEXMOD
    Offline

    JUZEXMOD New Member

    Joined:
    May 28, 2016
    Posts:
    19
    Minecraft User:
    JUZEXMOD
    PHP:
    use pocketmine\entity\effect;


            
    $effect Effect::getEffect(2);  /* Efeect id */
            
    $effect->setAmplifier(2);    /* Effect Power */
            
    $effect->setVisible(true);
            
    $effect->setDuration(10000000000);  /* Effect Time */
            
    $player->addEffect($effect); /*give player effect */
  3. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
  4. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    PHP:
    !$p instanceof Player 
    will always return false as !$p will be false,maybe the effect gets added to other entities too?
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    This isn't Java where '!' affects next value on right. It means that `!false` and `!(false)` are both the same.

    Try to set all Effect attributes - amplifier, visible, duration etc. Use code what @JUZEXMOD provided above, if that doesn't work then it's PocketMine issue.
    Muqsit likes this.
  6. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Yup, PocketMine's issue. But adding a .00001% load (by checking if player has permission) helped me get rid of the console error. This is even more weird...

    PHP:
    if(!$p instance of \pocketmine\Player) return;
    if(
    $p->hasPermission("some.permission"$p->addEffect(\pocketmine\entity\Effect::getEffect(Effect::SPEED)->setDuration(4000));
    }
    plugin.yml
    PHP:
    permissions:
      
    some.permission:
        default: 
    false
    By using a permissio plugin (PurePerms), I added that permission to all groups. And now it works.

    Setting the permission's default value to true didn't help too. SOO weird.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Perhaps there is some delay? Like you know how the kick message issue...
    Muqsit likes this.

Share This Page

Advertisement