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

Solved Using arrays [Config]

Comments in 'Plugin Development' started by Kvetinac97, Jul 20, 2015.

  1. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Hi.

    Should this code work?

    PHP:
    if ($cmd->getName() == "sethome"){
     if (isset(
    $args[0]) and !( isset($args[1]))){
      if (
    $sender->hasPermission("homes.sethome." $args[0]) || $sender->hasPermission("homes") || $sender->hasPermission("homes.sethome")){
       
    $name $args[0];
       
    $info = array($sender->getX(), $sender->getY(), $sender->getZ(), $sender->getLevel());
        
    $this->cfg->set($name$info);
        }
     else {
    $sender->sendMessage(TextFormat::DARK_RED "You haven't got permission");
    }
    return 
    false;
    }
    break;
    if (
    $cmd->getName() == "home"){
     if (isset(
    $args[0] and !(isset($args[1]))){
      if (
    $sender->hasPermission("homes") || $sender->hasPermission("homes.home") || $sender->hasPermission("homes.home.".$args[0])){
       
    $name $args[0];
       
    $a $this->cfg->get($name);
       
    $sender->setLevel($a[3]);
       
    $sender->teleport(new Vector3($a[0], $a[1], $a[2]);
    }
    else {
    $sender->sendMessage(TextFormat::DARK_RED."You haven't got permission");
    }
    return 
    false;
    }
    break;
    }
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    +How will look config? Like this?:

    myhome:
    - 12
    - 34
    - -246
    - world
  3. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    havenĀ“t got xD
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You should save the level name. The level is an object and cannot be correctly written into YAML.
  5. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    So "replace":
    PHP:
    $lv $sender->getLevel()->getName():
    $sender->setLevel($this->getServer()->getLevelByName($lv));
    ?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't use setLevel. Use teleport instead, with the first parameter being a Position object containing the target level.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Also, what are you doing? You are setting the player's level to the player's current level? What's the point of that?
  8. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    It's home plugin. onCommand /sethome <home>, I get players level and x,y,z and write it into config (homes.yml). onCommand /home <home> player is teleported to x,y,z,level from config
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then why did you use $sender->getLevel()?

    I asked you to save the name in the config, not to search levels by name -_-
    Creeperface likes this.
  10. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    These are how I do to my code to save something into array
    PHP:
    $tmp $this->getConfig()->getAll();
    $tmp[$name]["x"] = $player->x;
    $tmp[$name]["y"] = $player->y;
    $tmp[$name]["z"] = $player->z;
    $tmp[$name]["world"] = $player->getLevel()->getName();
    $this->getConfig()->setAll($tmp);
    $this->getConfig()->save();
    To get 'x',
    PHP:
    $tmp $this->getConfig()->getAll();
    return 
    $tmp[$name]["x"];
  11. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    This will do:

    homes:
    - myhome:
    - 23
    - 37
    - kvetinac:
    - 10
    - 35
  12. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Or something like this?
  13. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Code:
    hoyinm14mc:
      x: 123
      y: 123
      z: 123
      world: survival
    Pemapmodder:
      x: 256
      y: 0
      z: 256
      world: survival
    KelvinKamHK:
      x: 0
      y: 1
      z: 2
      world: Factions
    GBernard2000:
      x: 3
      y: 2
      z: 1
      world: Creative
    ...
    Last edited: Jul 21, 2015

Share This Page

Advertisement