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

PlayerRespawnEvent - Add Effects

Comments in 'Plugin Development' started by EschieEsh, Apr 28, 2016.

  1. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    public function onRespawn(PlayerRespawnEvent $event){
    $ent = $event->getPlayer();
    $ticks = 10000000;
    $amplifier = 0;
    $ent->addEffect(Effect::getEffect(1)->setDuration($ticks)->setAmplifier($amplifier));
    }

    I want people to be given effects when they respawn. This code WORKS for PlayerJoinEvent but it DOESN'T WORK for PlayerRespawnEvent. The effects are not being sent for some reason. Help?
    Last edited: Apr 28, 2016
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Because the player isn't alive yet.
  3. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    So you are trying to tell me that PlayerRespawnEvent is useless for adding effects to players? But what is the solution to this?
    Last edited: Apr 29, 2016
  4. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    How can I make it work when you respawn?
  5. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    PHP:
    $player $e->getPlayer();
    $speed Effect::getEffect(Effect::SPEED);
                    
    $speed->setDuration(PHP_INT_MAX);
                    
    $player->addEffect($speed);
    You are doing right
    Last edited: Apr 29, 2016
  6. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    But it is not working for some reason
  7. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    Are you checking console for errors?
  8. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    There are no errors in Console. The selected effect is just not being sent.
  9. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    That event called before player can get effect and etc
  10. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    I don't understand what is wrong
  11. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    You want add effects just after REspawn?
  12. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    That's correct. I want players to be given effects after they respawn.
  13. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    Hm,now I don't know how to do this normally ,but you can try that: in respawn event create task with 20 ticks duration and add effect to player from task
    Last edited: Apr 29, 2016
  14. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    Do I really have to do that? >.> No other ways?
  15. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    As @Primus said, the player is not alive yet. Create a delayed task which adds the effect
    Primus likes this.
  16. EschieEsh
    Offline

    EschieEsh Active Member

    Joined:
    Jun 28, 2014
    Posts:
    69
    Minecraft User:
    Escherion
    I think it was obvious that I didn't want to do it with tasks (my previous reply)
    Plus, to be honest, tasks are not really needed here. I found a much easier way to do it without creating tasks.
    Why creating tasks when you can simply replace PlayerRespawnEvent with PlayerDeathEvent? It worked for me (somehow). But I am not done yet.

    PlayerRespawnEvent should be called after you press the respawn button so I do not really understand why 'the player is not alive' and why delayed tasks are even needed here. Also I don't understand why does this work on PlayerDeathEvent (when the player is not alive), lol.

    The problem is you both are not specific enough. If the people who created threads in this forum had known everything they wouldn't have actually asked for help. I didn't want the code, all I wanted was proper explainations. 'Because the player is not alive yet' doesn't answer this question 'But why?'. And it also doesn't answer THIS question 'Why does it work on PlayerDeathEvent (lmao) and it doesn't work on PlayerRespawnEvent (lol)'. Events are completely messed up, yes?
    udwarf likes this.
  17. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    The PlayerRespawnEvent is actually called when player press 'Respawn' button but the code to process the respawn is executed after event.

Share This Page

Advertisement