Skip to content

Commit

Permalink
Encode skin identifiers in Base64 for storage consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Nov 23, 2024
1 parent d0fd7e1 commit 4e66e44
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/de/oliver/fancynpcs/skins/cache/SkinCacheFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.oliver.fancynpcs.api.skins.SkinData;

import java.io.IOException;
import java.util.Base64;

public class SkinCacheFile implements SkinCache {

Expand All @@ -16,9 +17,11 @@ public SkinCacheFile() {

@Override
public SkinCacheData getSkin(String identifier) {
String b64ID = Base64.getEncoder().encodeToString(identifier.getBytes());

SkinCacheData skinCacheData = null;
try {
skinCacheData = this.storage.get("skins/" + identifier, SkinCacheData.class);
skinCacheData = this.storage.get("skins/" + b64ID, SkinCacheData.class);
} catch (IOException e) {
FancyNpcs.getInstance().getFancyLogger().error("Failed to load skin cache");
FancyNpcs.getInstance().getFancyLogger().error(e);
Expand All @@ -29,7 +32,7 @@ public SkinCacheData getSkin(String identifier) {
}

if (skinCacheData.isExpired()) {
this.storage.delete("skins/" + identifier);
this.storage.delete("skins/" + b64ID);
return null;
}

Expand All @@ -41,7 +44,8 @@ public void addSkin(SkinData skin) {
SkinCacheData skinCacheData = new SkinCacheData(skin, System.currentTimeMillis(), CACHE_TIME);

try {
this.storage.set("skins/" + skin.getIdentifier(), skinCacheData);
String b64ID = Base64.getEncoder().encodeToString(skin.getIdentifier().getBytes());
this.storage.set("skins/" + b64ID, skinCacheData);
} catch (IOException e) {
FancyNpcs.getInstance().getFancyLogger().error("Failed to save skin cache");
FancyNpcs.getInstance().getFancyLogger().error(e);
Expand All @@ -50,6 +54,7 @@ public void addSkin(SkinData skin) {

@Override
public void removeSkin(String identifier) {
this.storage.delete("skins/" + identifier);
String b64ID = Base64.getEncoder().encodeToString(identifier.getBytes());
this.storage.delete("skins/" + b64ID);
}
}

0 comments on commit 4e66e44

Please sign in to comment.