Lan Server Properties

Lan Server Properties

3M Downloads

Add "Preserve UUID in offline mode" feature

rikka0w0 opened this issue ยท 1 comments

commented

If offline mode is enabled, the game uses locally calculated UUIDs for identifying players. If the server owner changes the offline mode during the gameplay (either enable or disable), the UUIDs won't match. This causes loss of inventories and ender chest.

  1. In offline mode, Minecraft uses net.minecraft.world.entity.player.Player.createPlayerUUID(String) to generate a local UUID for each player, including those who logged in with Microsoft account. Its implementation ensures each player name will have its unique corresponding UUID: return UUID.nameUUIDFromBytes(("OfflinePlayer:" + p_36284_).getBytes(StandardCharsets.UTF_8));.
  2. Upon start-up, Minecraft checks if the launch argument contains a UUID, if not, it will use the above method to generate a local one.
  3. When a second player joins the game, Minecraft calls net.minecraft.world.entity.player.Player.createPlayerUUID(GameProfile) to map his UUID:
   public static UUID createPlayerUUID(GameProfile p_36199_) {
      UUID uuid = p_36199_.getId();
      if (uuid == null) {
         uuid = createPlayerUUID(p_36199_.getName());
      }

      return uuid;
   }

   public static UUID createPlayerUUID(String p_36284_) {
      return UUID.nameUUIDFromBytes(("OfflinePlayer:" + p_36284_).getBytes(StandardCharsets.UTF_8));
   }

To address this issue, the author proposed a new way of generating the UUID:

  1. Call https://api.mojang.com/users/profiles/minecraft/<username>
  2. If succeeded, use the returned UUID from the previous API.
  3. If not, falls back to the local UUID.

See:
https://bukkit.org/threads/how-to-convert-uuid-to-name-and-name-to-uuid-uising-mojang-api.460828/

commented

Properly implemented since:

57fbd36