mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Implemented a texture cache for contributors
This commit is contained in:
parent
88dfdfa560
commit
098304a1c4
@ -87,6 +87,8 @@
|
||||
* Fixed #2066
|
||||
* Fixed Rainbow Glass Panes not properly connecting to blocks
|
||||
* Fixed Androids turning in the wrong direction
|
||||
* Fixed contributors losing their texture after restarts
|
||||
* Fixed "korean" showing up as "null"
|
||||
|
||||
## Release Candidate 13 (16 Jun 2020)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13
|
||||
|
@ -13,6 +13,7 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.data.ComputedOptional;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||
|
||||
/**
|
||||
@ -132,7 +133,8 @@ public class Contributor {
|
||||
*/
|
||||
public String getTexture() {
|
||||
if (!headTexture.isComputed() || !headTexture.isPresent()) {
|
||||
return HeadTexture.UNKNOWN.getTexture();
|
||||
String cached = SlimefunPlugin.getGitHubService().getCachedTexture(githubUsername);
|
||||
return cached != null ? cached : HeadTexture.UNKNOWN.getTexture();
|
||||
}
|
||||
else {
|
||||
return headTexture.get();
|
||||
|
@ -15,6 +15,7 @@ import com.google.gson.JsonObject;
|
||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.localization.Translators;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
|
||||
/**
|
||||
@ -30,7 +31,9 @@ public class GitHubService {
|
||||
private final String repository;
|
||||
private final Set<GitHubConnector> connectors;
|
||||
private final ConcurrentMap<String, Contributor> contributors;
|
||||
|
||||
private final Config uuidCache = new Config("plugins/Slimefun/cache/github/uuids.yml");
|
||||
private final Config texturesCache = new Config("plugins/Slimefun/cache/github/skins.yml");
|
||||
|
||||
private boolean logging = false;
|
||||
|
||||
@ -196,18 +199,31 @@ public class GitHubService {
|
||||
}
|
||||
|
||||
/**
|
||||
* This will store the {@link UUID} of all {@link Contributor Contributors} in memory
|
||||
* in a {@link File} to save requests the next time we iterate over them.
|
||||
* This will store the {@link UUID} and texture of all {@link Contributor Contributors}
|
||||
* in memory in a {@link File} to save requests the next time we iterate over them.
|
||||
*/
|
||||
protected void saveUUIDCache() {
|
||||
protected void saveCache() {
|
||||
for (Contributor contributor : contributors.values()) {
|
||||
Optional<UUID> uuid = contributor.getUniqueId();
|
||||
|
||||
if (uuid.isPresent()) {
|
||||
uuidCache.setValue(contributor.getName(), uuid.get());
|
||||
}
|
||||
|
||||
if (contributor.hasTexture()) {
|
||||
String texture = contributor.getTexture();
|
||||
|
||||
if (!texture.equals(HeadTexture.UNKNOWN.getTexture())) {
|
||||
texturesCache.setValue(contributor.getName(), texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uuidCache.save();
|
||||
texturesCache.save();
|
||||
}
|
||||
|
||||
protected String getCachedTexture(String name) {
|
||||
return texturesCache.getString(name);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class GitHubTask implements Runnable {
|
||||
|
||||
// We only wanna save this if all Connectors finished already
|
||||
// This will run multiple times but thats okay, this way we get as much data as possible stored
|
||||
gitHubService.saveUUIDCache();
|
||||
gitHubService.saveCache();
|
||||
}
|
||||
|
||||
private int requestTexture(Contributor contributor, Map<String, String> skins) {
|
||||
|
@ -43,7 +43,7 @@ enum SupportedLanguage {
|
||||
CHINESE_CHINA("zh-CN", true, "7f9bc035cdc80f1ab5e1198f29f3ad3fdd2b42d9a69aeb64de990681800b98dc"),
|
||||
CHINESE_TAIWAN("zh-TW", true, "702a4afb2e1e2e3a1894a8b74272f95cfa994ce53907f9ac140bd3c932f9f"),
|
||||
JAPANESE("ja", true, "d640ae466162a47d3ee33c4076df1cab96f11860f07edb1f0832c525a9e33323"),
|
||||
KOREAN("kr", false, "fc1be5f12f45e413eda56f3de94e08d90ede8e339c7b1e8f32797390e9a5f"),
|
||||
KOREAN("ko", false, "fc1be5f12f45e413eda56f3de94e08d90ede8e339c7b1e8f32797390e9a5f"),
|
||||
HEBREW("he", false, "1ba086a2cc7272cf5ba49c80248546c22e5ef1bab54120e8a8e5d9e75b6a"),
|
||||
ARABIC("ar", true, "a4be759a9cf7f0a19a7e8e62f23789ad1d21cebae38af9d9541676a3db001572"),
|
||||
TURKISH("tr", true, "9852b9aba3482348514c1034d0affe73545c9de679ae4647f99562b5e5f47d09"),
|
||||
|
Loading…
Reference in New Issue
Block a user