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

Teleporting doesn't work?

Comments in 'Plugin Development' started by minebuilder0110, Dec 7, 2015.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I have coded a plugin so that it teleports to a certain location upon changing the world, but it doesn't do anything. Any help?
    Note: The plugin have displayed the debug message with correct coordinate, but it just doesn't teleport.
    PHP:
            public function onLevelChange(EntityLevelChangeEvent $event) {
            
    $player $event->getEntity();
            if (
    $player instanceof Player) {
                
    $world $event->getOrigin()->getName();
                
    $name $player->getName();
                
    $x $player->getX();
                
    $y $player->getY();
                
    $z $player->getZ();
                
    $targetWorld $event->getTarget();
                
    $targetWorldName $targetWorld->getName();
                
    $saveCoords = array($x$y$z);
                
    $this->yml->setNested($name '.' $world$saveCoords);
                
    $this->yml->save();
                
    $loadCoords $this->yml->getNested($name "." $targetWorldName);
                
    $lx $loadCoords[0];
                
    $ly $loadCoords[1];
                
    $lz $loadCoords[2];
                if(!isset(
    $loadCoords)) $loadCoords $targetWorld->getSpawnLocation();
                
    $player->sendMessage("Loading your last location $lx $ly $lz");
                
    $player->teleport(new Position($lx$ly$lz));
            }
        }
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Try to
    PHP:
    $player->setLevel($level); // Level
    $player->teleport($x$y$z); // Flaot|Integer
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Cancel the event then teleport the player. @aliuly told me a year ago it was better practice.
  4. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    What's this?
    PHP:
    $player->sendMessage("Loading your last location $lx$ly$lz");
    Maybe you mean
    PHP:
    $player->sendMessage("Loading your last location " $lx " " $ly " " $lz);
  5. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    And you forgot "{}" on your if...
    Lol I think you have lot of syntactic errors in that code
  6. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    They both work completely fine. Go an have a look in the manual. These are not syntax error.
  7. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Sure? I think that this if will not work and your message is fully a string, I think that it will show:
    "Loading your last location $lx$ly$lz"

    * Or it's not PHP 5.4?
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Learn PHP. Double quotes process variables, but single quotes don't.
    AndrewBit likes this.
  9. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Sorry, Codecademy don't tell me this :p
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    It did. How come I learned it then?
  11. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    When I learned PHP from codecademy, it doesn't tell me any. I'm pretty sure :p
  12. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    I didn't learn at codecademy anymore. I learn directly at php.net :p

Share This Page

Advertisement