Refresh Player


#1

Hello! Is there any way to refresh / recreate Player Entity? I am currently facing a problem where i am setting “textures” property for GameProfile but the changes are not visible for player itself until he travel between worlds.
For other players i simply toggle Keys.VANISH and the others will see his new skin.

Currently i am “recreating” player this way:

Location<World> oldLocation = player.getLocation();
Vector3d rotation = player.getRotation();
World receiverWorld = player.getWorld();
Sponge.getServer().getWorlds()
.stream()
.filter(world -> !world.equals(receiverWorld))
.findFirst()
.ifPresent(world -> {
player.setLocation(world.getSpawnLocation());
player.setLocationAndRotation(oldLocation, rotation);
});

But i can’t use this in final product because it shows loading screen for a while.
So… Is there anyone who knows how to bypass that problem or encountered similar?


#2

Nevermind. I ended up using NMS and packets.


#3

I forgot to post solution for my problem :disappointed_relieved:
There it is(It needs use of NMS or even can be better done using Mixins):

Location<World> location = player.getLocation();

EntityPlayerMP playerMP = (EntityPlayerMP)player;

playerMP.connection.sendPacket(new SPacketRespawn(
       playerMP.dimension,
       playerMP.getServerWorld().getDifficulty(),
       playerMP.getServerWorld().getWorldInfo().getTerrainType(),
       playerMP.interactionManager.getGameType()));

player.setLocation(location);