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

Solved The perfect way to set a skin

Comments in 'Plugin Development' started by Inta, Jul 24, 2016.

  1. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Whenever i set the skin, the server will upload that data of skin and waiting for Player Viewers to download it.
    That means i can't just do the respawn for the player in < 1 tick.
    What is the most efficient way to do this ?
  2. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Put the spawn on hold (let him respawn, but don't spawn to other players) and only spawn to all when all players supposedly downloaded the new skin?
  3. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    I just wonder if there is any packet that would be sent when the player downloaded the skin ?
  4. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    @Inta Packets are ordered and sent async, so you don't need to worry about how much time will take to upload/download a packet, or if the player have received it since they arrive at the destination and are ordered at the destination. Yes when the player "downloaded the skin" an ACK is sent but you don't need to worry about it, the raklib will manage it...

    The skin is sent to other players using the PlayerListPacket and you can use the pocketmine api to send it

    PHP:
        //If the skin is slim (alex's arm) or not (steve's arm)
        
    $slim false;
        
    //Set the skin locally, $p is an instanceof Player
        
    $p->setSkin('SkinBytes'$slim 'Standard_CustomSlim' 'Standard_Custom');
        
    //Despawn the player
        
    $p->despawnFromAll();
        
    //This will send a PlayerListPacket::TYPE_REMOVE to everyone
        
    $p->getServer()->removeOnlinePlayer($p);
        
    //This will send a PlayerListPacket::TYPE_ADD to everyone. This packet contains the new skin
        
    $p->getServer()->sendFullPlayerListData($p);
        
    //Spawn the player
        
    $p->spawnToAll();
    You don't need to wait for the player to download the skin befor spawning it , the raklib will handle it.

    http://www.jenkinssoftware.com/raknet/manual/reliabilitytypes.html
    Inta likes this.
  5. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Packets should theoretically be sent in the proper order as dataPacket() is called, although not always true if it is really laggy.
  6. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Your code have a problem.
    If you're trying to remove an Online Player from the server, it will pernamently Unset the player from the "playerList".
    Since "addOnlinePlayer" contains almost all the function used in sendFullPlayerListData, there're no reason not using this instead.
    Thanks for the code, it is ok though.

    PHP:
        //If the skin is slim (alex's arm) or not (steve's arm)
        
    $slim false;
        
    //Set the skin locally, $p is an instanceof Player
        
    $p->setSkin('SkinBytes'$slim 'Standard_CustomSlim' 'Standard_Custom');
        
    //Despawn the player
        
    $p->despawnFromAll();
        
    //This will send a PlayerListPacket::TYPE_REMOVE to everyone
        
    $p->getServer()->removeOnlinePlayer($p);
        
    //This will send a PlayerListPacket::TYPE_ADD to everyone. This packet contains the new skin
        
    $p->getServer()->addOnlinePlayer($p);
        
    //Spawn the player
        
    $p->spawnToAll();
    Svile likes this.
  7. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    right but be sure you are not using clearsky since they changed the updatePlayerListData
  8. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Sorry, bump.
    @Svile 's Code doesn't work. Viewers of the Player $p will see THEIR skin, not the 'SkinBytes' skin.
    Add a little 4 ticks delay on the spawnToAll(), works well.
    Need another solution.
  9. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    There is no reason why delaying the spawnToAll() will fix
  10. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    But you can try. I was tried on localhost with no lag, 4 ticks or 2-3 ticks maybe and it works.
  11. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    ok i will try later and i will post a solution if i find one
  12. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Yes. Im using Windows 10 for PocketMine and Minecraft Windows 10 Edition for client, with 1 more Android phone for the viewer.
    SOFe likes this.
  13. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    @Inta

    This is working for genisys (tested on it) , the server will spawn the player automatically (once he moves a bit) :
    PHP:
        //If the skin is slim (alex's arm) or not (steve's arm)
        
    $slim false;
        
    //Set the skin locally, $p is an instanceof Player
        
    $p->setSkin('SkinBytes'$slim 'Standard_CustomSlim' 'Standard_Custom');
        
    //Despawn the player
        
    $p->despawnFromAll();
    If not working for you, add the below part
    PHP:
        foreach ($p->getServer()->getOnlinePlayers() as $player)
            
    $p->getServer()->removePlayerListData($player->getUniqueId());
        foreach (
    $p->getServer()->getOnlinePlayers() as $player)
            
    $p->getServer()->sendFullPlayerListData($player);
        
    //Spawn the player
        
    $p->spawnToAll();
    Last edited: Jul 27, 2016
    Inta likes this.
  14. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    High five, 10/10.
    I want instantly. After adding the code below, all works fluently. Thank you.
  15. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    This shouldn't cause any problem.

    Adittion: Genisys uses the same code
    Last edited: Aug 29, 2016
  16. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Actually,
    PHP:
        foreach ($p->getServer()->getOnlinePlayers() as $player)
            
    $p->getServer()->removePlayerListData($player->getUniqueId());
        foreach (
    $p->getServer()->getOnlinePlayers() as $player)
            
    $p->getServer()->sendFullPlayerListData($player);
        
    //Spawn the player
        
    $p->spawnToAll();
    is an exact copy of the clearsky stuff

Share This Page

Advertisement