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

LoadWorld help me

Comments in 'Plugin Development' started by mrfoxvolt, Oct 3, 2014.

  1. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    hello, this is the code scr of my plugin and i would to know how i do for load all my worlds.when the server start i would like my 2 world load. how i had this in my plugin

    <?php

    namespace rirititi\LoadWorld;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\Server;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\level\Level;
    use pocketmine\entity\Entity;
    use pocketmine\tile\Tile;
    use pocketmine\utils\Config;

    class Main extends PluginBase implements Listener{
    private $api, $server, $path;

    public function onEnable(){
    $this->getServer()->loadLevel(level);
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function onCommand(CommandSender $sender, Command $command, $label, array $args){

    switch($command->getName()){

    case "loading":
    if(isset($args[0])){
    if(Server::getInstance()->loadLevel($args[0])){
    $sender->sendMessage("[LoadWorld] Loading map ...");
    }
    }else{
    $sender->sendMessage("Usage /loading <worldname>");
    }
    return true;

    case "generate":
    if(isset($args[0])){
    Server::getInstance()->generateLevel($args[0]);
    $sender->sendMessage("[LoadWorld] World ".$args[0]." is being generated");
    }else{
    $sender->sendMessage("Usage /generate <worldname>");
    }
    return true;
    default:
    return false;
    }
    }
    }
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Do you want to generate or load worlds?
  3. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    If you want to load worlds, PocketMine automatically loads worlds.
    If you want to generate worlds use this code:
    PHP:
    $this->getServer()->generateLevel($name$seed$generator$options);
    Where:
    - $name is the world name
    - $seed is the world seed (you can also set it null)
    - $generator is the world generator ("DEFAULT"=Normal world, "FLAT"=Flat world)
    - $options are the world presets (optional, but required for flat worlds)

    Please Like if I helped you :)
    PixelGuy75 likes this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use $this->getServer() instead of Server::getInstance(). It is bad practice.
  5. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    i would like pocketmine load all worlds
  6. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    i try this but it doesn't good:

    public function loadLevel ($name){
    $name = worldd;
    $this->getServer()->loadLevel($name);
    }
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Run this in onEnable():
    PHP:
    foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getServer()->getDataPath() . "worlds/")) as $dir){
        
    $this->getServer()->loadLevel($dir);
    }
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Learn PHP. Strings must be contained in "quotes".
  9. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    it do only that:
    [NOTICE] Level "/Users/*********/worlds/." not found
    [NOTICE] Level "/Users/**********/worlds/.." not found
    etc .......
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oops
    Add this at the beginning inside the foreach loop:
    PHP:
    if(trim($dir"./\\") === "") continue;
    64FF00 likes this.
  11. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    sorry but i m very bad. i start to write in PHP. i do that:

    foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getServer()->getDataPath() . "worlds/")) as $dir){
    if(trim($dir, "./\\") === "") continue;
    $this->getServer()->loadLevel($dir);
    }
    Last edited: Oct 4, 2014
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes. I don't remember the iterator function exactly, so if it goes wrong, please tell me what $dir is by logging it to console. ($this->getLogger()->info($dir))
  13. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    that do=
    [NOTICE] Level "/Users/***********/worlds/." not found

    14:09:03 [INFO] [LoadWorld] /Users/***********/worlds/.

    14:09:03 [NOTICE] Level "/Users/***********/worlds/.." not found

    14:09:03 [INFO] [LoadWorld] /Users/***********/worlds/..
  14. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    [INFO] [LoadWorld] /Users/*******/worlds/world/stats/a4d9d2a9-27a4-451f-ab56-02c42b62495f.json
    with ($this->getLogger()->info($dir))
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oops sorry. I have no idea why I wanted to do it recursively -_-"

    PHP:
    foreach(scandir($path $this->getServer()->getDataPath() . "worlds/") as $dir){
        if(
    is_dir($path.$dir) and trim($dir"./\\") !== ""){
            
    $this->getServer()->loadLevel(rtrim($dir"/\\"));
        }
    }
    Falk likes this.
  16. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    but i can't use

    public function loadWorld ($name)

    ..........
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You just gave the function signature... Giving the function signature is equal to showing me the filename of a file and ask me if there are any typos inside.
  18. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    I world like to add a teleportation. Dir exemple ./tp [name] [level]
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $player->teleport($level->getSpawnLocation());

    I don't remember if it is getSpawnLocation or getSpawn. One is deprecated, and I can't remember which.
  20. mrfoxvolt
    Offline

    mrfoxvolt Active Member Plugin Developer

    Joined:
    Jan 26, 2014
    Posts:
    52
    Plugins:
    1
    Minecraft User:
    rirititi
    i try that but it doesn't work:
    case"tpw":

    if(isset($args[0])){
    $player->teleport($level->getSpawnLocation($args[0]));
    $sender->sendMessage("[LoadWorld] Teleport to ".$args[0]." ");
    }else{
    $sender->sendMessage("Usage /tpw <worldname>");
    }

    return true;

Share This Page

Advertisement