-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee37e9c
commit eef3316
Showing
8 changed files
with
121 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
src/main/java/de/oliver/fancynpcs/skins/cache/SkinCacheFake.java
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
src/main/java/de/oliver/fancynpcs/skins/cache/SkinCacheFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package de.oliver.fancynpcs.skins.cache; | ||
|
||
import de.oliver.fancylib.jdb.JDB; | ||
import de.oliver.fancynpcs.FancyNpcs; | ||
import de.oliver.fancynpcs.api.skins.SkinData; | ||
|
||
import java.io.IOException; | ||
|
||
public class SkinCacheFile implements SkinCache { | ||
|
||
private final JDB storage; | ||
|
||
public SkinCacheFile() { | ||
this.storage = new JDB("plugins/FancyNpcs/.skinCache"); | ||
} | ||
|
||
@Override | ||
public SkinCacheData getSkin(String identifier) { | ||
SkinCacheData skinCacheData = null; | ||
try { | ||
skinCacheData = this.storage.get("skins/" + identifier, SkinCacheData.class); | ||
} catch (IOException e) { | ||
FancyNpcs.getInstance().getFancyLogger().error("Failed to load skin cache"); | ||
FancyNpcs.getInstance().getFancyLogger().error(e); | ||
} | ||
|
||
if (skinCacheData == null) { | ||
return null; | ||
} | ||
|
||
if (skinCacheData.isExpired()) { | ||
this.storage.delete("skins/" + identifier); | ||
return null; | ||
} | ||
|
||
return skinCacheData; | ||
} | ||
|
||
@Override | ||
public void addSkin(SkinData skin) { | ||
SkinCacheData skinCacheData = new SkinCacheData(skin, System.currentTimeMillis(), CACHE_TIME); | ||
|
||
try { | ||
this.storage.set("skins/" + skin.identifier(), skinCacheData); | ||
} catch (IOException e) { | ||
FancyNpcs.getInstance().getFancyLogger().error("Failed to save skin cache"); | ||
FancyNpcs.getInstance().getFancyLogger().error(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeSkin(String identifier) { | ||
this.storage.delete("skins/" + identifier); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/de/oliver/fancynpcs/skins/cache/SkinCacheMemory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.oliver.fancynpcs.skins.cache; | ||
|
||
|
||
import de.oliver.fancynpcs.api.skins.SkinData; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class SkinCacheMemory implements SkinCache { | ||
|
||
private final Map<String, SkinCacheData> cache; | ||
|
||
public SkinCacheMemory() { | ||
this.cache = new ConcurrentHashMap<>(); | ||
} | ||
|
||
@Override | ||
public SkinCacheData getSkin(String identifier) { | ||
if(!cache.containsKey(identifier)) { | ||
return null; | ||
} | ||
|
||
SkinCacheData skinCacheData = cache.get(identifier); | ||
if(skinCacheData.isExpired()) { | ||
cache.remove(identifier); | ||
return null; | ||
} | ||
|
||
return skinCacheData; | ||
} | ||
|
||
@Override | ||
public void addSkin(SkinData skin) { | ||
SkinCacheData skinCacheData = new SkinCacheData(skin, System.currentTimeMillis(), CACHE_TIME); | ||
cache.put(skin.identifier(),skinCacheData); | ||
} | ||
|
||
@Override | ||
public void removeSkin(String identifier) { | ||
cache.remove(identifier); | ||
} | ||
} |
137 changes: 0 additions & 137 deletions
137
src/main/java/de/oliver/fancynpcs/skins/cache/SkinCacheYaml.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters