Solved What im doing wrong?

Discussion in 'Development' started by IvanCraft623, Oct 13, 2020.

  1. IvanCraft623

    IvanCraft623 Spider Jockey

    Messages:
    42
    GitHub:
    IvanCraft623
    Hello, I am practically new to Pocketmine, I have only been with this one year, which I have always used poggit plugins but I do not always find what I need so I have ventured into trying to create plugins for my own server, my knowledge in php It is null.

    I have tried to get the nametag of a player with the rank of PurePerms / PureChat but I have run into this error I have looked in several pages but I have not found a solution.

    Error:
    Code:
    [Server thread/CRITICAL]: ErrorException: "Array to string conversion" (EXCEPTION) in "plugins/EnderCore/src/Core/Core" at line 61
    Code:
    PHP:
    public function onJoin(PlayerJoinEvent $event){
        
    $player $event->getPlayer();
        
    $rank $this->getServer()->getPluginManager()->getPlugin("PurePerms")->getUserDataMgr($player)->getGroup($player);
        
    $nametag $this->getServer()->getPluginManager()->getPlugin("PureChat")->getConfig()->get("groups"$rank"nametag");
        
    $event->setJoinMessage("");
        
    $this->getServer()->broadcastMessage($nametag ."§r§7 has joined the server");
    }
     
    Last edited: Oct 13, 2020
  2. Kygekraqmak

    Kygekraqmak Witch

    Messages:
    57
    GitHub:
    Kygekraqmak
    You are giving the error backtrace. Give the text above that.
     
  3. IvanCraft623

    IvanCraft623 Spider Jockey

    Messages:
    42
    GitHub:
    IvanCraft623
    Sorry I had not realized xD

    Is:
    Code:
    [Server thread/CRITICAL]: ErrorException: "Array to string conversion" (EXCEPTION) in "plugins/EnderCore/src/Core/Core" at line 61
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    460
    $nametag is not string, but array instead
    do
    PHP:
    var_dump($nametag);
    to see exact contents of that variable. Perhaps the value you're looking for is inside that array.
     
  5. IvanCraft623

    IvanCraft623 Spider Jockey

    Messages:
    42
    GitHub:
    IvanCraft623
    Now this error:
    Code:
    array(4) {
      ["Guest"]=>
      array(3) {
        ["chat"]=>
        string(61) "&7[Guest] &f{fac_rank}{fac_name}&a {display_name} &7> &f{msg}"
        ["nametag"]=>
        string(26) "&7[Guest] &f{display_name}"
        ["worlds"]=>
        array(0) {
        }
      }
      ["Admin"]=>
      array(3) {
        ["chat"]=>
        string(61) "&c[Admin] &7{fac_rank}{fac_name}&6 {display_name} &d>&b {msg}"
        ["nametag"]=>
        string(49) "&a[Admin]&e {fac_rank}{fac_name} &6{display_name}"
        ["worlds"]=>
        array(0) {
        }
      }
      ["Owner"]=>
      array(3) {
        ["chat"]=>
        string(64) "&d[Owner] &c{fac_rank}{fac_name} &b{display_name} &c>&6> &b{msg}"
        ["nametag"]=>
        string(49) "&d[Owner]&c {fac_rank}{fac_name} &b{display_name}"
        ["worlds"]=>
        array(0) {
        }
      }
      ["OP"]=>
      array(3) {
        ["chat"]=>
        string(77) "&a[OP] &5{fac_rank}{fac_name}&b {prefix}{display_name}{suffix} &c>&6> &f{msg}"
        ["nametag"]=>
        string(46) "&a[OP] &c{fac_rank}{fac_name} &b{display_name}"
        ["worlds"]=>
        array(0) {
        }
      }
    }
    [08:14:54] [Server thread/CRITICAL]: ErrorException: "Array to string conversion" (EXCEPTION) in "plugins/EnderCore/src/Core/Core" at line 62
    Code:
    PHP:
    public function onJoin(PlayerJoinEvent $event){
        
    $player $event->getPlayer();
        
    $rank $this->getServer()->getPluginManager()->getPlugin("PurePerms")->getUserDataMgr($player)->getGroup($player);
        
    $nametag $this->getServer()->getPluginManager()->getPlugin("PureChat")->getConfig()->get("groups"$rank"nametag");
        
    var_dump($nametag);
        
    $event->setJoinMessage("");
        
    $this->getServer()->broadcastMessage($nametag ."§r§7 has joined the server");
    }
    Error line:
    PHP:
    $this->getServer()->broadcastMessage($nametag ."§r§7 has joined the server");
     
  6. Primus

    Primus Zombie Pigman

    Messages:
    460

    PHP:
    $this->getServer()->broadcastMessage($nametag[$rank] ."§r§7 has joined the server");
    I won't go into details.
     
  7. IvanCraft623

    IvanCraft623 Spider Jockey

    Messages:
    42
    GitHub:
    IvanCraft623
    Code:
    [Server thread/CRITICAL]: ErrorException: "Illegal offset type" (EXCEPTION) in "plugins/EnderCore/src/Core/Core" at line 62
     
  8. Primus

    Primus Zombie Pigman

    Messages:
    460
    Now dump the $rank variable, I was just assuming that $nametag contains all registered groups and $rank is the group the player is assigned to.

    $nametag could also be array of the inheritance tree. Getting the last element from the array might resolve this.
     
    minijaham likes this.
  9. Kygekraqmak

    Kygekraqmak Witch

    Messages:
    57
    GitHub:
    Kygekraqmak
    Try to use this:
    PHP:
    $this->getServer()->broadcastMessage($nametag[$rank]["nametag"]."§r§7 has joined the server");
     
  10. IvanCraft623

    IvanCraft623 Spider Jockey

    Messages:
    42
    GitHub:
    IvanCraft623
    Hi guys I found the solution by looking at the PureChat code.
    For those who want to know how I got the nametag...
    I have used these variables:
    PHP:
    $player $event->getPlayer();
    $levelName  $this->getServer()->getPluginManager()->getPlugin("PureChat")->getConfig()->get("enable-multiworld-chat") ? $player->getLevel()->getName() : null;
    $nametag $this->getServer()->getPluginManager()->getPlugin("PureChat")->getNametag($player$levelName);
    An example where I use the nametag that pureperms assigns you:
    PHP:
    public function onJoin(PlayerJoinEvent $event){
        
    $player $event->getPlayer();
        
    $levelName  $this->getServer()->getPluginManager()->getPlugin("PureChat")->getConfig()->get("enable-multiworld-chat") ? $player->getLevel()->getName() : null;
        
    $nametag $this->getServer()->getPluginManager()->getPlugin("PureChat")->getNametag($player$levelName);
        
    $event->setJoinMessage("");
        
    $this->getServer()->broadcastMessage($nametag ."§r§7 has joined the server");
    }
     
    Primus likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.