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

Join Point

Comments in 'Plugin Development' started by Marcelo234, Jan 21, 2016.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys....::player should spawn at special coordinates in a special world! So I wrote this code!::
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
    $data = new Config($this->getDataFolder() . "config.yml" strtolower($player->getName()), Config::YAML, array());
           
    $player->teleport(new Position($this->$data->get("lobby_spawn_x"), $this->$data->get("lobby_spawn_y"), $this->$data->get("lobby_spawn_z"), $this->getServer()->getLevelByName($this->$data->get("lobby_spawn_world"))));     
    }
    ::But i don't understand why it won't work! INFO:: The "config.yml" alreday exist! And insert the config.yml it looks like that:
    Code:
    ---
    loby_spawn_world: McKaff
    lobby_spawn_x: 134.400000
    lobby_spawn_y: 4.000000
    lobby_spawn_z: 124.600000
    ...
    __________
    This is the Error from the Console when a player join:
    Code:
    [18:47:37] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'McKaff_Settings v0.1.0': Object of class pocketmine\utils\Config could not be converted to string on McKaff_Settings\Main
    [18:47:37] [Server thread/NOTICE]: ClassCastException: "Object of class pocketmine\utils\Config could not be converted to string" (E_RECOVERABLE_ERROR) in "/McKaff_Settings/src/McKaff_Settings/Main" at line 668
    
    _________
    Hope you can help..Thx
  2. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    $data = new Config($this->getDataFolder() . "config.yml" strtolower($player->getName()), Config::YAML, array());
    ^Do you even know what you're trying to do with this?
    use this instead:
    PHP:
    $data = new Config($this->getDataFolder() . "config.yml"Config::YAML, array());
    Also,
    PHP:
    $this->$data
    would give a syntax error. You could simply just use $data directly.
    PocketKiller likes this.
  3. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Ok...now I changed a few things,but it won't work....
    New Code:
    PHP:
    $data = new Config($this->getDataFolder() . "config.yml"Config::YAML, array());
           
    $player->teleport(new Position($data->get("lobby_spawn_x"), $data->get("lobby_spawn_y"), $data->get("lobby_spawn_z"), $data->getServer()->getLevelByName($this->$data->get("lobby_spawn_world"))));
           
    Error in the console when a player join:
    Code:
    [19:30:02] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'McKaff_Settings v0.1.0': Object of class pocketmine\utils\Config could not be converted to string on McKaff_Settings\Main
    [19:30:02] [Server thread/NOTICE]: ClassCastException: "Object of class pocketmine\utils\Config could not be converted to string" (E_RECOVERABLE_ERROR) in "/McKaff_Settings/src/McKaff_Settings/Main" at line 668
    
    Hope you can help.Thx
  4. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    You still use $this->data instead of $data
  5. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    And, what is this?
    PHP:
    $data->getServer()
    ?
  6. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Just use $this->getConfig()->get("lobby_spawn_x");
    Make you you save it too. $this->saveDefaultConfig();
  7. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
    $player $event->getPlayer();
    $this->config = new Config($this->getDataFolder() . "config.yml" Config::YAML, array());
    $player->teleport(new Position($this->config->get("lobby_spawn_x"), $this->config->get("lobby_spawn_y"), $this->config->get("lobby_spawn_z"), $this->getServer()->getLevelByName($this->config->get("lobby_spawn_world")))); 
    }
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually, it doesn't cause a syntax error. PHP will attempt to convert $data into a string, then resolve a class property from $this. This is why it shows the message about conversion to string.
    However, this is not what you are trying to do anyway.

    Also, not "could simply just use", but you mustn't relate it to $this at all.

    He is not using a config.yml from the plugin resource folder!
    Last edited: Jan 22, 2016
  9. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    I didn't do that. I mean, he should use $data instead of $this->data because he still use $this->data in his code. Sorry, my English might be bad, so you didn't understand what I mean
    PEMapModder likes this.
  10. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Now it Works and there are no ERRORS but it didn't work corectly! The Server Take the false coordinates.... What to Do?

Share This Page

Advertisement