1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Illegal string offset

Discussion in 'Help' started by NutXzG, Aug 25, 2020.

  1. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    Hi, i use array get data in array but has problem is Illegal string offset
    Code:
    PHP:
    <?php


    namespace NutzatvchZ\Skin;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utlis\Config;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    NutzatvchZ\libs\jojoe77777\FormAPI\CustomForm;

    class 
    Skin extends PluginBase implements Listener
    {
      
    /**
       * urlskin = https://crafatar.com/skins/uuid
       * url = ttpss://api.mojang.com/users/profiles/minecraft/
       ***/
       
    public function onEnable (){
        
    $this->getServer()->getPluginManager ()->registerEvents ($this$this);
        @
    mkdir($this->getDataFolder () . "skins");
       }
      public function 
    fetchuuid($input){
       
    $url "https://api.mojang.com/users/profiles/minecraft/" $input;
       
    $ch curl_init($url);
       
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
       
    $result curl_exec($ch);
       
    var_dump($result);
       
    curl_close($ch);
       return 
    $result;
      }
      public function 
    fetchskin($uuid$input){
       
    $json json_encode($uuid);
       
    $id $json["id"];
       
    print_r($id);
       
    /***
       $url = "https://crafatar.com/skins/$id'";
     curl_setopt($start, CURLOPT_URL, $url);
      curl_setopt($start, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($start, CURLOPT_SSLVERSION, 3);
      $file_data = curl_exec($start);
      curl_close($start);
      $file_path = $this->getDataFolder () .  "skins/" . $input . ".png";
      $file = fopen($file_path, "w+");
      fputs($file, $file_data);
      fclose($file);
      **/
      
    }
       public function 
    onCommand(CommandSender $pCommand $cmdstring $label, array $args) : bool {
         switch (
    $cmd->getName()) {
          case 
    "skin":
             if (
    $p instanceof Player) {
              
    $this->Form($p);
             }else{
              
    $p->sendMessage("§cUse comamnd in game only!!");
              return 
    true;
             }
           break;
         }
         return 
    true;
        }
      public function 
    Form(Player $p){
       
    $form = new CustomForm(function (Player $p$data){
        if(
    $data === null){
         return 
    true;
        }
        
    $input $data[0];
        if(
    $data[0] === null){
         
    $p->sendMessage($this->getConfig()->get("data-null"));
        }else{
            
    $this->Mulitly($p$input);
        }
       });
       
    $form->setTitle($this->getConfig ()->get("title"));
       
    $form->addInput($this->getConfig ()->get("input-title"), "Steve");
       
    $form->sendToPlayer($p);
       return 
    $form;
      }
      public function 
    Mulitly(Player $p$input){
       if (!
    file_exists($this->getDataFolder () . "skins/" $input ".png")) {
        
        
    $uuid $this->fetchuuid($input);
        
    $this->fetchskin($uuid$input);
        
    $skin $player->getSkinn();
        if(!
    $json["error"] === null){
    $path $this->getDataFolder () . "skins/" $input ".png";
    $img = @imagecreatefrompng($path);
    $skinbytes "";
    $s = (int)@getimagesize($path)[1];

    for(
    $y 0$y $s$y++){
    for(
    $x 0$x 64$x++){
    $colorat = @imagecolorat($img$x$y);
    $a = ((~((int)($colorat >> 24))) << 1) & 0xff;
    $r = ($colorat >> 16) & 0xff;
    $g = ($colorat >> 8) & 0xff;
    $b $colorat 0xff;
    $skinbytes .= chr($r) . chr($g) . chr($b) . chr($a);
    }
    }
    @
    imagedestroy($img);

    $p->setSkin(new Skin($skin->getSkinId(), $skinbytes));
    $p->sendSkin();
    $p->sendMessage($this->getConfig()->get("success-change"));
    }else{
     
    $p->sendMessage($this->getConfig->get("not-found-player"));
    }
       }else{
        
    $skin $player->getSkin();
    $path $this->getDataFolder () . "skins/" $input ".png";
    $img = @imagecreatefrompng($path);
    $skinbytes "";
    $s = (int)@getimagesize($path)[1];

    for(
    $y 0$y $s$y++){
    for(
    $x 0$x 64$x++){
    $colorat = @imagecolorat($img$x$y);
    $a = ((~((int)($colorat >> 24))) << 1) & 0xff;
    $r = ($colorat >> 16) & 0xff;
    $g = ($colorat >> 8) & 0xff;
    $b $colorat 0xff;
    $skinbytes .= chr($r) . chr($g) . chr($b) . chr($a);
    }
    }
    @
    imagedestroy($img);

    $p->setSkin(new Skin($skin->getSkinId(), $skinbytes));
    $p->sendSkin();
    $p->sendMessage($this->getConfig()->get("success -change"));
        }
       }
      }
    Error:
    Code:
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: ErrorException: "Illegal string offset 'id'" (EXCEPTION) in "plugins/Skin/src/NutzatvchZ/Skin/Skin" at line 36
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #0 plugins/Skin/src/NutzatvchZ/Skin/Skin(36): pocketmine\utils\Utils::errorExceptionHandler(integer 2, string[26] Illegal string offset 'id', string[62] /home/mc_51381/10934/plugins/Skin/src/NutzatvchZ/Skin/Skin.php, integer 36, array[3])
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #1 plugins/Skin/src/NutzatvchZ/Skin/Skin(81): NutzatvchZ\Skin\Skin->fetchskin(string[63] {"name":"lolizapotter","id":"168a34ced1124489974b0a81b2ec4713"}, string[12] lolizapotter)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #2 plugins/Skin/src/NutzatvchZ/Skin/Skin(69): NutzatvchZ\Skin\Skin->Mulitly(object pocketmine\Player, string[12] lolizapotter)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #3 plugins/Skin/src/NutzatvchZ/libs/jojoe77777/FormAPI/Form(46): NutzatvchZ\Skin\Skin->NutzatvchZ\Skin\{closure}(object pocketmine\Player, array[1])
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #4 src/pocketmine/Player(3603): NutzatvchZ\libs\jojoe77777\FormAPI\Form->handleResponse(object pocketmine\Player, array[1])
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #5 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(264): pocketmine\Player->onFormSubmit(integer 2, array[1])
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #6 src/pocketmine/network/mcpe/protocol/ModalFormResponsePacket(49): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleModalFormResponse(object pocketmine\network\mcpe\protocol\ModalFormResponsePacket)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(110): pocketmine\network\mcpe\protocol\ModalFormResponsePacket->handle(object pocketmine\network\mcpe\PlayerNetworkSessionAdapter)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #8 src/pocketmine/network/mcpe/protocol/BatchPacket(127): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(object pocketmine\network\mcpe\protocol\ModalFormResponsePacket)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #9 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(110): pocketmine\network\mcpe\protocol\BatchPacket->handle(object pocketmine\network\mcpe\PlayerNetworkSessionAdapter)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #10 src/pocketmine/Player(3250): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(object pocketmine\network\mcpe\protocol\BatchPacket)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #11 src/pocketmine/network/mcpe/RakLibInterface(169): pocketmine\Player->handleDataPacket(object pocketmine\network\mcpe\protocol\BatchPacket)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #12 vendor/pocketmine/raklib/src/server/ServerHandler(99): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string[19] 171.4.226.138 41689, object raklib\protocol\EncapsulatedPacket, integer 0)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #13 src/pocketmine/network/mcpe/RakLibInterface(109): raklib\server\ServerHandler->handlePacket()
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #14 src/pocketmine/network/mcpe/RakLibInterface(99): pocketmine\network\mcpe\RakLibInterface->process()
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #15 vendor/pocketmine/snooze/src/SleeperHandler(123): pocketmine\network\mcpe\RakLibInterface->pocketmine\network\mcpe\{closure}()
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #16 vendor/pocketmine/snooze/src/SleeperHandler(85): pocketmine\snooze\SleeperHandler->processNotifications()
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #17 src/pocketmine/Server(2157): pocketmine\snooze\SleeperHandler->sleepUntil(double 1598351668.5241)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #18 src/pocketmine/Server(1994): pocketmine\Server->tickProcessor()
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #19 src/pocketmine/Server(1588): pocketmine\Server->start()
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #20 src/pocketmine/PocketMine(273): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[21] /home/mc_51381/10934/, string[29] /home/mc_51381/10934/plugins/)
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #21 src/pocketmine/PocketMine(304): pocketmine\server()
    2020-08-25 [17:34:29] [Server thread/CRITICAL]: #22 (11): require(string[90] phar:///usr/share/shareport/exec/mcpe/PocketMine-MP-16
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Illegal string offset means that you are using string as an array. For example

    PHP:
    $string "Text";
    $a $string["stringOffset"]; // error on this line

    // If you use integer, it returns char on that position, for example
    $firstLetter $string[0]; // = T
    $secondLetter $string[1]; // = e
     
    RicardoMilos384 likes this.
  3. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    I can't sovled it
     
  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.