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

How to save to config when command is ran

Comments in 'Plugin Development' started by Radix, Jul 31, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    How can I do lets say this..

    /hvset <name> - Saves the players cords in config

    Code:
    player: name
    - coords
    - - 45 , 6 , 90
    - name
    
    Lets say I want to tp player to those coords?...
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    It's possible but config won't look how you wrote:
    PHP:
    public function onCommand(CommandSender $sdCommand $cmd$label, array $args){
    if (
    $cmd->getName() == "hvset"){
    if (
    $sd instanceof Player){
    $coords = array([$sd->getFloorX(),$sd->getFloorY(),$sd->getFloorZ(),$sd->getLevel()->getName()
    ]);
    $this->getConfig()->set($sd->getName(),$coords);
    }
    }
    }
    //how teleport player
    $coords $this->getConfig()->get($player->getName());
    $player->teleport(new Position($coords[0],$coords[1],$coords[2],$coords[3]);
    Config will look like that:
    Code:
    kvetinac97:
    - 245
    - 23
    - -346
    radix:
    - -35
    - 18
    - 124
    
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    This is for the player who executed command, if you wan't write other players, use:
    PHP:
     if ( isset($args[0])){
     
    //Don't forget to define coords like:
     
    $sd $this->getServer()->getPlayerExact($args[0]);
      if (
    $sd instanceof Player){
      
    $coords = array($sd->getFloorX().......
      
    $this->getConfig()->set($args[0],$coords);
    TheKofola12 and Minecrafter9203 like this.
  4. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Thank you so very much ,
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It seems you have a mistake.
    PHP:
    array([])
    is same as
    PHP:
    array(array())
    is same as
    PHP:
    [array()]
    is same as
    PHP:
    [[]]
  6. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Oooops, Netbeans wrote me something is wrong with arrays. Now I know what. I used array([]) instead of array() or []
    TheKofola12 and Minecrafter9203 like this.

Share This Page

Advertisement