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

Giving Player effect and Items

Comments in 'Plugin Development' started by Sensej, Jun 7, 2015.

  1. Sensej
    Offline

    Sensej New Member

    Joined:
    Aug 5, 2014
    Posts:
    64
    Hey Guys,

    When a Player dies on my server my PlayerDeathListener calls a function which gives the Player an effect + items and more but he will get this on the death screen and not after. Is it possible to make this in the death event instad of respawn event?
  2. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    I would do it on the PlayerRespawnEvent so here is how to give item now as for Potion Effects i don't know.
    PHP:
    public function PlayerRespawnEvent(PlayerRespawnEvent $ev){
            
    $item Item::DIAMOND;
            
    $ev->getPlayer()->getInventory()->setItem($ev->getPlayer()->getInventory()->firstEmpty(), $item);
        }
    Sorry that i do not know effects but i still hope this was of help. :) If anyone knows how to set effects i would also like to know.

    Edit:
    I Figured it out i think as i haven't had time to test it but just add
    PHP:
    $ev->getPlayer()->addEffect(Effect::SPEED);
    You can change the effect to waterever the different ones are here
    Last edited: Jun 7, 2015
    Marcelo234 likes this.
  3. Sensej
    Offline

    Sensej New Member

    Joined:
    Aug 5, 2014
    Posts:
    64
    Thanks but i already know the methode, my goal is it to managa this in thePlayerDeathEvent :(
  4. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Its the same no? just changed to PlayerDeathEvent?
  5. Sensej
    Offline

    Sensej New Member

    Joined:
    Aug 5, 2014
    Posts:
    64
    its since the 0.11.0 no longer possible to do it there directly
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No, when the player is dead, his new things aren't set up yet. The setup at respawn (before PlayerRespawnEvent is fired) will override most changes.
  7. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    So when is it better to run it or add effects?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    As they said, PlayerRespawnEvent.
    BalAnce likes this.
  9. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    And how we can edit how long the player have this effect?
  10. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Mentioning doesn't show alerts to me.
    Effect->setDuration
    E.g. Effect::getEffect($effectId)->setDuration($durationInTicks)
    Vaivez66 and luca28pet like this.
  12. XWITHERHEROX
    Offline

    XWITHERHEROX Active Member

    Joined:
    Jun 4, 2015
    Posts:
    57
    Minecraft User:
    ReDaRWiTheR
    ok nice but how do this with player random
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What do you mean by random? Random what?
  14. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    PHP:
    $item Item::DIAMOND;
    $sender->getPlayer()->getInventory()->setItem($ev->getPlayer()->getInventory()->firstEmpty(), $item);
    should be
    PHP:
    $item Item::get(Item::DIAMOND);
    $sender->getInventory()->setItem($sender->getInventory()->firstEmpty(), $item);
    since you checked that $sender is instance of Player, you do not need to getPlayer() on sender
    XWITHERHEROX likes this.
  15. XWITHERHEROX
    Offline

    XWITHERHEROX Active Member

    Joined:
    Jun 4, 2015
    Posts:
    57
    Minecraft User:
    ReDaRWiTheR
    ok this is rigt i add PrimedTNT
  16. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    An entity cannot be used like a block, take a look at Entity::createEntity()

Share This Page

Advertisement