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

Solved Problem with changing the gamemode of a player

Comments in 'Plugin Development' started by BlubberBoy333, Apr 10, 2016.

  1. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Hey guys, I'm trying to make a plugin that changes a player's game mode when he/she goes to a certain world. But when they go to the world that is supposed to change them to creative, it changes them to survival. Anyone have any ideas? Here's the plugin:
    PHP:
    use pocketmine\level\Level;
    use 
    pocketmine\event\entity\EntityLevelChangeEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\Entity;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
       
        public function 
    onEntityLevelChangeEvent(EntityLevelChangeEvent $event){
            
    $player $event->getEntity();
            if(
    $player instanceof Player){
                if(!(
    $player->isOp())){
                    
    $target $event->getTarget();
                    if(
    $target == "Creative"){
                        
    $player->setGamemode(1);
                    }elseif(
    $target == "PixelCity"){
                        
    $player->setGamemode(2);
                    }else{
                        
    $player->setGamemode(0);
                    }
                }
            }
        }
    }
  2. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    $event->getTarget() doesn't return a string.
    PEMapModder likes this.
  3. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Would
    $event->getTarget()->getName()
    work?
  4. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    yep that worked.
    Thanks @MCPEPIG

Share This Page

Advertisement