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

Solved Set Skin

Comments in 'Plugin Development' started by Cristalix, Aug 9, 2016.

  1. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    I would like to create a 'Top Player's' on Human's (Human have a top player's skin)

    When player join, I save his skin:
    PHP:
       public function UpdateSkin($player){

           
    file_put_contents($this->getDataFolder().'/skin/'.strtolower($player->getName()).'.skin'$player->getSkinData());
           
    file_put_contents($this->getDataFolder().'/skin/'.strtolower($player->getName()).'.name'$player->getSkinName());
       }
    When server update statistic:
    PHP:
       public function onUpdate()
           
    $TOP $this->mysqli->query("/*get top player name")->fetch_assoc();
           
    //We have $TOP = array('login' = $PlayerName)
           
    foreach ($this->getServer()->getLevelByName('hub')->getEntities() as $Ent) {
               if (
    $Ent instanceof Human && $Ent->== 50 && $Ent->== 50 && $Ent->== 50){
                        
    $Ent->setSkin$this->GetSkin($TOP['login']), $this->GetSkinName($TOP['login']) );
                        
    $Ent->setNameTag$TOP['login'] );
               }
           }
       }
    PHP:
    public function GetSkin($PlayerName){
           
    file_get_contents($this->getDataFolder().'/skin/'.strtolower($PlayerName).'.skin');
       }
    After this, all Human's have not correct skin :(
    Is my code rigth?)
    Last edited: Aug 9, 2016
    thebigsmileXD likes this.
  2. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    What is your logic on the second part? "$TOP" variable is even defined. And what is "$TOP['login']"? If we do not know what is the index "login" how are we supposed to guess what the problem is?
  3. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    In plugin's datafolder/skin/ will be saved as <name>.skin and .name. PocketMine don't really understand .name and .skin extensions for skin files.
    Read this maybe it'll help
  4. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    Ok, I rewrite thread :3
  5. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Code:
    /*get top player name
    
    What?

    I don't recommend saving two files per player. This is probably unnecessarily slow. What about like this?

    PHP:
    public function savePlayer(Player $player){
      
    $data = ["name" => $player->getSkinName(), "data" => $player->getSkinData()];
      
    file_put_contents($this->getDataFolder() . "skins/" strtolower($player->getName()) . ".sl"zlib_encode(serialize($data), ZLIB_ENCODING_DEFLATE));
    }

    public function 
    loadPlayerSkin(string $playerName, &$skinName, &$skinData) : bool{
      
    $path $this->getDataFolder() . "skins/" strtolower($playerName) . ".sl";
      if(
    is_file($path)){
        
    $data unserialize(zlib_decode(file_get_contents($path)));
        
    $skinName $data["name"];
        
    $skinData $data["data"];
        return 
    true;
      }
      return 
    false;
    }
    About the & operator in front of parameters:http://stackoverflow.com/documentat...rguments-by-reference#t=201608100413050813685
    Last edited: Aug 10, 2016
  6. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    You should also compress it.


    That's not what I mean. I mean , what is the value of $TOP['login'']? Each index has a value. E.g.: $array["index"] = "value";
    SOFe likes this.
  7. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    Need return in GetSkin
    thebigsmileXD and SOFe like this.
  8. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Did they have your skin always?
  9. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    :D okay, thats funny. Good luck though


    And remeber @Intyre changed skinName to skinId
  10. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I really like this idea. the file extension doesn't need to be .sl, right?
  11. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Nope, but that's useful if you use the Config class instead.
  12. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    okay. Another question: when i set a skin on a human (npc or player), it still doesn't show up. Any idea how i may fix this?

Share This Page

Advertisement