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

Why isn't this working?

Comments in 'Plugin Development' started by ImagicalGamer, Mar 28, 2016.

  1. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    This is my code:
    PHP:
    public function onJoin(PlayerJoinEvent $event){
    $config $this->getConfig();
    $player $event->getPlayer();
    $x $config->get("x");
    $y $config->get("y");
    $z $config->get("z");
    $text $config->get("text");
    $position = new Vector3($x$y 0.5$z);
    $player->getLevel()->addParticle(new FloatingTextParticle($position$text));
    }
    The data is in the config but on PlayerJoinEvent isn't adding the particle, there's no errors or issues. Any ideas why it isn't working.
    Primus likes this.
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Show to Config probably 'Y' key isn't found
  3. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    This is the config:
    Code:
    ---
    Texter:
      x: 132.276382
      y: 126.156151
      z: 126.156151
      text: test
    ...
    
    @Primus
    Primus likes this.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Yup, do:
    Code:
    ---
    Texter:
      x: 132.276382
      'y': 126.156151
      z: 126.156151
      text: test
    ...
    
    ImagicalGamer likes this.
  5. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    It's still not working. It will save everything to the config but it isn't spawning the particle like it should.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Try outputting $config->getAll();
  7. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    This is my first time making a data saving config xD.
    Where would I put that? :p
  8. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    it should be a string, " "
    Primus likes this.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    After
    PHP:
    $config $this->getConfig();
    Add
    PHP:
    var_dump($config->getAll());
    Survingo likes this.
  10. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    Added that and it looks like:
    PHP:
    public function onJoin(PlayerJoinEvent $event){
    $config $this->getConfig();
    var_dump($config->getAll());
    $player $event->getPlayer();
    $x $config->get("x");
    $y $config->get("y");
    $z $config->get("z");
    $text $config->get("text");
    $position = new Vector3($x$y 0.5$z);
    $player->getLevel()->addParticle(new FloatingTextParticle($position$text));
    }
    I get this on my console:
    Code:
    array(1) {
      ["Texter"]=>
      array(4) {
        ["x"]=>
        float(135.09642)
        ["y"]=>
        float(121.664162)
        ["z"]=>
        float(121.664162)
        ["text"]=>
        string(4) "test"
      }
    }
    
    Notice: Array to string conversion in phar://C:/Users/Jake/Downloads/ImagicalMine/ImagicalMine.phar/src/pocketmine/level/particle/FloatingTextParticle.php on line 99
    
  11. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    Should it be:
    PHP:
    public function onJoin(PlayerJoinEvent $event){
    $config $this->getConfig();
    var_dump($config->getAll());
    $player $event->getPlayer();
    $x $config->get(["x"]);
    $y $config->get(["y"]);
    $z $config->get(["z"]);
    $text $config->get(["text"]);
    $position = new Vector3($x$y 0.5$z);
    $player->getLevel()->addParticle(new FloatingTextParticle($position$text));
    }
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you use $config->get("x"), the config has to be like:
    Code:
    ---
    x: 123
    y: 456
    z: 789
    ...
    If your config is like what you posted, you should be using $config->getNested("Texter.x"). Otherwise, what do you think the Texter is there for?
    Of course not. Do you know what get(["x"]) means? It means to use an array as the key type, which is invalid. Can you not post if you are completely wild guessing?
    ImagicalGamer and PocketKiller like this.

Share This Page

Advertisement