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

Clear player effects/reset health when in specific world

Discussion in 'Plugin Help' started by EerieAlchemist, May 16, 2020.

  1. EerieAlchemist

    EerieAlchemist Spider Jockey

    Messages:
    36
    I am working on a plugin that clears a player's effects and resets their health upon entering a specific world, the server's lobby. Here's my attempt to far, but to no avail. Maybe I need to place it under a different function than onJoin()? I just want to make it so that whenever a player enters a world, their health and effects are reset. Any help would be greatly appreciated.

    PHP:
    public function onJoin(PlayerJoinEvent $event) {
            
    $player $event->getPlayer();
            
    $this->onItem($player);
            if(
    $player->getLevel()->getName() === "Lobby"){
                
    $player->removeAllEffects();
                
    $player $event->getPlayer();
                
    $player->getArmorInventory()->clearAll();
                
    $player->setHealth(20);
                
    $player->setFood(20);
                
    $player->setGamemode(0);
                
    $player->removeAllEffects(true);
            }
        }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    use EntityLevelChangeEvent, ensure $event->getEntity() is player and check that $event->getTarget() is the world you want
     
  3. EerieAlchemist

    EerieAlchemist Spider Jockey

    Messages:
    36
    Awesome, thanks for the help!
     
  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.