Skip to content

Commit

Permalink
consider skin variants
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Nov 23, 2024
1 parent bbf1c98 commit 7fe99a1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/de/oliver/fancynpcs/skins/SkinManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public SkinData getByIdentifier(String identifier, SkinData.SkinVariant variant)

@Override
public SkinData getByUUID(UUID uuid, SkinData.SkinVariant variant) {
SkinData cached = tryToGetFromCache(uuid.toString());
SkinData cached = tryToGetFromCache(uuid.toString(), variant);
if (cached != null) {
return cached;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public SkinData getByUUID(UUID uuid, SkinData.SkinVariant variant) {
public SkinData getByUsername(String username, SkinData.SkinVariant variant) {
UUID uuid = UUIDFetcher.getUUID(username);

SkinData cached = tryToGetFromCache(uuid.toString());
SkinData cached = tryToGetFromCache(uuid.toString(), variant);
if (cached != null) {
return cached;
}
Expand All @@ -144,7 +144,7 @@ public SkinData getByUsername(String username, SkinData.SkinVariant variant) {

@Override
public SkinData getByURL(String url, SkinData.SkinVariant variant) {
SkinData cached = tryToGetFromCache(url);
SkinData cached = tryToGetFromCache(url, variant);
if (cached != null) {
return cached;
}
Expand Down Expand Up @@ -177,7 +177,7 @@ public SkinData getByURL(String url, SkinData.SkinVariant variant) {

@Override
public SkinData getByFile(String filePath, SkinData.SkinVariant variant) {
SkinData cached = tryToGetFromCache(filePath);
SkinData cached = tryToGetFromCache(filePath, variant);
if (cached != null) {
return cached;
}
Expand Down Expand Up @@ -242,14 +242,22 @@ private SkinInfo executeRequest(GenerateRequest req) {
return skinResp.join();
}

private SkinData tryToGetFromCache(String id) {
private SkinData tryToGetFromCache(String id, SkinData.SkinVariant variant) {
SkinCacheData data = memCache.getSkin(id);
if (data != null) {
if (data.skinData().getVariant() != variant) {
return null;
}

return data.skinData();
}

data = fileCache.getSkin(id);
if (data != null) {
if (data.skinData().getVariant() != variant) {
return null;
}

memCache.addSkin(data.skinData());
return data.skinData();
}
Expand Down

0 comments on commit 7fe99a1

Please sign in to comment.