#changing player skin through packets

1 messages ยท Page 1 of 1 (latest)

grim pumice
#

^

lament zenith
#

I've worked out so far ClientboundRespawnPacket packet = new ClientboundRespawnPacket(nmsLevel.dimensionTypeId(), nmsLevel.dimension(), nmsLevel.getSeed(), npc.gameMode.getGameModeForPlayer(), null, false, false, true, null);

lament zenith
#

No clue how the respawn packet does anything. It has no reference to the player at all

#

@grim pumice ^

grim pumice
#

wow thank you very much!

grim pumice
lament zenith
#

ah ok

grim pumice
#

so that would do 4)

lament zenith
#

in that case, the packet above shoudl do it

#

npc is ServerPlayer

grim pumice
#

oki

#

nmsLevel?

lament zenith
#

ServerLevel taken from World

#

I use my own utils to avoid CraftBukkit imports, so for me it ServerLevel nmsWorld = (ServerLevel) NMSUtils.getServerLevel(location.getWorld());

grim pumice
#

thank you so much !! i'll try and tell you

grim pumice
#

cuz yeah they advise to send 2 respawn packets to prevent bugs

lament zenith
#

give me a sec to test

grim pumice
#

(i'm doing animated skin)

#

yeah sure

lament zenith
#

I'm getting a null error, but I am doing it in the join event, well 20 ticks delayed

#

ah seems it requires the last field

grim pumice
lament zenith
#

well I logged in but my skin didn;t change#

#

I may have used an invalid one

grim pumice
# lament zenith well I logged in but my skin didn;t change#

this is how u must change skin

    public static void changeSkin(ServerPlayer player, String texture, String signature){
        GameProfile profile = player.getGameProfile();
        profile.getProperties().removeAll("textures");
        profile.getProperties().put("textures", new Property("textures", texture, signature));
    }```
#

texture + sig

#

the PlayerTextures.setSkin(...) is for npc

lament zenith
#

yeah I was trying a quick way and giving a url

grim pumice
#

yeah someone confirmed me that PlayerTextures.setSkin(URL) will not put a signed skin whatever url u put

#

don't forget: before changing skin, playerinfopacket 'remove' ur player, after changing skin, playerinfopack "add" ur player

lament zenith
#

that shouldn;t be required just for yourself

grim pumice
#

ah yeah

#

all that is very confusing ๐Ÿ˜„
Tell me if u got sth working, i'm trying to fix my compiler once again lmao

lament zenith
#

got it working

grim pumice
#

gg!

#

is it instant?

#

or does it take some ms to change skin

lament zenith
#

was teh instant I logged in. I just did it in the join event

#

it should be instant

#

its literally 1 packet

grim pumice
#

can u try to change it while already connected? (so u can see ur skin change live)

lament zenith
#

yep

grim pumice
#

tysm

grim pumice
lament zenith
#

yes

grim pumice
#

i see

lament zenith
#

I'm going to put a delay on applying the skin for 100 ticks so I can log in first

grim pumice
#

uh

#

could u rather make a trigger?

#

like when u move

#

or send a msg

lament zenith
#

I'm doing a broadcast when it tries to set it

grim pumice
#

oki

#

i feel like "playerjoinevent" is part of "preparing the player instance" and therefore it works

lament zenith
#

could be

#

ok skin didnt; change, but oddly it did give me a different inventory

grim pumice
#

hmmm

lament zenith
#

I just have to find the packet I'm missing

grim pumice
#

new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, player)

lament zenith
#

I'm trying just add

grim pumice
#

yeah

lament zenith
#

see if it overwrites

#

that works, but I do get a different inventory

grim pumice
#

not ServerPlayer but bukkit player

#

it's what they did in the 2nd link of the first post of this thread

lament zenith
#

testing now

#

yep works. and I got my inventory back

grim pumice
#

amazing

#

if u have an axe in hand (or whatever tool with cooldown)
While it sends the respawn packet, does your tool refresh?

#

like do some kind of animation off cooldown

#

(cuz as i'm planning for animated skin, that would be a bit offsetting to have constantly cooldown animation xd)

lament zenith
#

I was in 3rd person view and it does flash teh screen once

#

no idea on animations though

grim pumice
#

aha

lament zenith
#

this is everything to change your own skin. It won;t update for others though```java
public void changeSkin(Player player, String[] skin) {

    Bukkit.broadcastMessage("Setting Skin for " + player.getName());

    ServerPlayer serverPlayer = (ServerPlayer) NMSUtils.getServerPlayer(player);
    ServerLevel nmsLevel = serverPlayer.getLevel();
    GlobalPos pos = GlobalPos.of(nmsLevel.dimension(), serverPlayer.blockPosition());

    setSkin(serverPlayer, skin);

    ClientboundPlayerInfoPacket playerInfoAdd = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, serverPlayer);
    ClientboundRespawnPacket respawn = new ClientboundRespawnPacket(nmsLevel.dimensionTypeId(), nmsLevel.dimension(), nmsLevel.getSeed(), serverPlayer.gameMode.getGameModeForPlayer(), null, false, false, true, Optional.of(pos));

    serverPlayer.connection.send(playerInfoAdd);
    serverPlayer.connection.send(respawn);

    player.updateInventory();
}

private void setSkin(ServerPlayer player, String[] skin) {

    String texture = skin[0];
    String signature = skin[1];

    player.getGameProfile().getProperties().removeAll("textures");
    player.getGameProfile().getProperties().put("textures", new Property("textures", texture, signature));

}```
grim pumice
#

yeah yeah

#

thanks very much buddy

#

that's very nice u did all the testing for me

lament zenith
#

๐Ÿ™‚

grim pumice
#

it's irritating to do blind coding xd (having hard time with fken gradle)

lament zenith
#

Yeah I have so many test projects setup for this purpose but I also use Maven so simpler

grim pumice
lament zenith
#

It also helps I only finished yesterday messing about with NPC/fake player creation

grim pumice
#

oh niice

#

yeah it's a fun project too

#

i'd love doing that one day

lament zenith
#

I have the head pitch wrong at teh moment, but thats all

grim pumice
#

i basically love doing hacky stuff xd, my previous project (which finished successfully btw) was animated map arts

#

like gif into mc

#

i see i see

#

well, have a great evening my friend!