LogoLogo
JavaDocsVersions
  • Introduction
  • Getting started
    • Dependencies
    • Your first server
  • Feature
    • Adventure
    • Player capabilities
    • Events
      • Implementation
      • Server list ping
    • Items
    • Entities
      • AI
    • Tags
    • Schedulers
    • Commands
    • Inventories
    • Player UUID
    • Player skin
    • Permissions
    • Advancements
    • Map rendering
      • GLFWMapRendering
    • Query system
    • Open to LAN
  • Thread Architecture
    • Thread safety in the JVM
    • Acquirable API
      • The inside
  • World
    • Instances
    • Chunk management
      • Anvil Loader
    • Blocks
    • Coordinates
    • Generation
    • Batch
  • Extension System
    • Extensions
Powered by GitBook
On this page
  • How to retrieve skin data from Mojang
  • Using PlayerSkin methods
  • Retrieve texture value & signature manually
  • PlayerSkinInitEvent
  • Player#setSkin

Was this helpful?

Export as PDF
  1. Feature

Player skin

PreviousPlayer UUIDNextPermissions

Last updated 1 year ago

Was this helpful?

There are three ways of defining a player skin:

  • Setting your player UUID (see ) to their Mojang UUID, clients by default retrieve the skin based on this value. This is done automatically by MojangAuth.init()

  • Changing it in the PlayerSkinInitEvent event

  • Using the method Player#setSkin(PlayerSkin)

How to retrieve skin data from Mojang

Using PlayerSkin methods

PlayerSkin offers some utils methods to retrieve a skin using simple information such as a Mojang UUID or a Minecraft username

PlayerSkin skinFromUUID = PlayerSkin.fromUuid(MOJANG_UUID_AS_STRING);

PlayerSkin skinFromUsername = PlayerSkin.fromUsername("Notch");

Those methods make direct requests to the Mojang API, it is recommended to cache the values.

Retrieve texture value & signature manually

Most of what I will say is described here:

You firstly need to get your Mojang UUID, which can be done by a request based on your username:

 GET https://api.mojang.com/users/profiles/minecraft/<username>

Then, after getting your UUID:

 GET https://sessionserver.mojang.com/session/minecraft/profile/<uuid>?unsigned=false

You'll get here both the texture value and the signature. Those values are used to create a PlayerSkin.

PlayerSkinInitEvent

The event is called at the player connection and is used to define the skin to send to the player the first time. It is as simple as

GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
globalEventHandler.addListener(PlayerSkinInitEvent.class, event -> {
   PlayerSkin skin = new PlayerSkin(textureValue, signature);
   event.setSkin(skin);
});

Player#setSkin

PlayerSkin skin = new PlayerSkin(textureValue, signature);
player.setSkin(skin);
here
https://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time