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

Worlds

Comments in 'Plugin Development' started by Vaivez66, Nov 4, 2015.

  1. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Hello, guys. Im still newbie on coding, and I'm develop PvP plugin now... My question is, I want to make it with multi world support, and I want my config.yml looks like this

    Code:
    worlds: pvp, parkour, survival
    How can I make that in array?
    Sorry for my bad English
  2. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Your config would have to look like this:
    Code:
    worlds: "world1, world2, etc"
    
    PHP:
    //$worlds is the Configs worlds key (do this yourself :P)
    $parts explode(" "str_replace(","""$worlds));
    foreach(
    $parts as $wName) {
        
    array_push($this->worlds$server->getLevelByName($wName));
    }
    This should add all the worlds to a variable called $this->worlds.
    Vaivez66 likes this.
  3. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Thanks
  4. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    Use
    Code:
    worlds:
    - pvp
    - parkour
    - survival
    
    and in the code:
    Code:
    $worlds = $this->getConfig()->get("worlds");
    $worlds will be an array with ["pvp", "parkour", "survival"] in it.
  5. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    $worlds[0], $world[1], etc.
  6. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    array_push will save them on an array. To save on config `$this->getConfig()->set("Worlds", $world);`
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    $array[] = $value;
    Is much faster.
    PEMapModder and CrazedMiner like this.
  8. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Will this work?
    PHP:
    $worlds $this->getConfig()->get("worlds");
    if(
    in_array($level$worlds)){
      
    //code
    }
    Of course I was define $level
  9. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Yes. $level = $this->getServer()->getLevelByName("level name here");
    Vaivez66 likes this.
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I don't think so. $level = "level name";
    PEMapModder likes this.
  11. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    getLevelByName() returns an object...
  12. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Parameters
    $name
    Returns
    Level
    Definition at line 944 of file Server.php.
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    ??? Unless you have an object serialized and saved into the config, a string would not be equal to a object.
    PEMapModder likes this.
  14. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Making a string would be the easiest. But you can strill use the '__toString()' function.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you have already got the level name, why do you try to get the level object and get the level name from the search again?

Share This Page

Advertisement