From 098304a1c44856aaa5534ae9dbd944141b435c69 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 5 Jul 2020 15:07:28 +0200 Subject: [PATCH] Implemented a texture cache for contributors --- CHANGELOG.md | 2 ++ .../core/services/github/Contributor.java | 4 +++- .../core/services/github/GitHubService.java | 22 ++++++++++++++++--- .../core/services/github/GitHubTask.java | 2 +- .../localization/SupportedLanguage.java | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec3e8674..027d72e9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/Contributor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/Contributor.java index 58251cb7c..9c1be58d5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/Contributor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/Contributor.java @@ -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(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java index 72a48028e..1942eeb52 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java @@ -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 connectors; private final ConcurrentMap 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 = 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); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java index 1f36dcc52..d7d9a9186 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubTask.java @@ -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 skins) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java index 63be7dcf6..f10df2e3f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SupportedLanguage.java @@ -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"),