Fixed #1321, fixed QuickShop won't update the cache files when server upgraded

This commit is contained in:
Ghost_chu committed 2021-07-28 01:21:54 +08:00
1 parent bcddea2e3c
commit 687a232ce2
1 file changed
+10 -7
@@ -227,7 +227,7 @@ public class MojangGameLanguageImpl extends BukkitGameLanguageImpl implements Ga
YamlConfiguration yamlConfiguration = new YamlConfiguration();
yamlConfiguration.load(cacheFile);
/* The cache data, if it all matches, we doesn't need connect to internet to download files again. */
//String cacheVersion = yamlConfiguration.getString("ver");
String cacheVersion = yamlConfiguration.getString("ver", "ERROR");
String cacheSha1 = yamlConfiguration.getString("sha1", "ERROR");
String cacheCode = yamlConfiguration.getString("lang");
/* If language name is default, use computer language */
@@ -239,12 +239,15 @@ public class MojangGameLanguageImpl extends BukkitGameLanguageImpl implements Ga
if (languageCode.equals(cacheCode)) { //Language same
if (cachedFile.exists()) { //File exists
if (DigestUtils.sha1Hex(new FileInputStream(cachedFile)).equals(cacheSha1)) { //Check if file broken
isLatest = true;
try (FileReader reader = new FileReader(cachedFile)) {
lang = new JsonParser().parse(reader).getAsJsonObject();
return; //We doesn't need to update it
} catch (Exception e) {
//Keep it empty so continue to update files
//noinspection EqualsWithItself
if (cacheVersion.equals(cacheVersion)) {
isLatest = true;
try (FileReader reader = new FileReader(cachedFile)) {
lang = new JsonParser().parse(reader).getAsJsonObject();
return; //We doesn't need to update it
} catch (Exception e) {
//Keep it empty so continue to update files
}
}
}
}