Skip to content

Commit

Permalink
fix: skin
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 13, 2023
1 parent 4dfa320 commit 6bd9a9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,14 @@ private void refreshStateForPlayer(@Nullable Player player, @NotNull DisplayPara
{
if (gameProfile == null)
{
scheduleRefreshPlayerDisplay(player, parameters.playerDisguiseName());
gameProfile = new GameProfile(Util.NIL_UUID, parameters.playerDisguiseName());
var cachedProfile = PlayerSkinProvider.getInstance().getCachedProfile(parameters.playerDisguiseName());
if (cachedProfile == null)
{
scheduleRefreshPlayerDisplay(player, parameters.playerDisguiseName());
gameProfile = new GameProfile(Util.NIL_UUID, parameters.playerDisguiseName());
}
else
gameProfile = cachedProfile;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.players.GameProfileCache;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.Nullable;
import xiamomc.morph.MorphPluginObject;
import xiamomc.morph.misc.NmsRecord;
import xiamomc.pluginbase.Annotations.Initializer;
Expand Down Expand Up @@ -60,6 +61,12 @@ public CompletableFuture<Optional<GameProfile>> fetchSkinFromProfile(GameProfile

private final Map<String, GameProfile> profileCache = new Object2ObjectOpenHashMap<>();

@Nullable
public GameProfile getCachedProfile(String profileName)
{
return profileCache.getOrDefault(profileName, null);
}

public CompletableFuture<Optional<GameProfile>> fetchSkin(String profileName)
{
var player = Bukkit.getPlayerExact(profileName);
Expand All @@ -69,7 +76,7 @@ public CompletableFuture<Optional<GameProfile>> fetchSkin(String profileName)
return CompletableFuture.completedFuture(Optional.of(NmsRecord.ofPlayer(player).gameProfile));
}

var cachedSkin = profileCache.getOrDefault(profileName, null);
var cachedSkin = getCachedProfile(profileName);
if (cachedSkin != null)
return CompletableFuture.completedFuture(Optional.of(cachedSkin));

Expand Down

0 comments on commit 6bd9a9b

Please sign in to comment.