mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 09:59:49 -05:00
Ahh, refactor
Former-commit-id: 24028c9ec4dab55e336529619ef5eb591a34284e
This commit is contained in:
1 parent
580308daaa
commit
85fdb60acf
4 files changed
+698
-794
No files matched your search
@@ -98,9 +98,13 @@ public class GameLanguage {
|
||||
String json = null;
|
||||
if (cachingLanguageHash != null) {
|
||||
json = Util.readToString(new File(Util.getCacheFolder(), cachingLanguageHash));
|
||||
}else{
|
||||
Util.debugLog("Caching LanguageHash is null");
|
||||
}
|
||||
if (json != null && !json.isEmpty()) {
|
||||
lang = new JsonParser().parse(json).getAsJsonObject();
|
||||
}else{
|
||||
Util.debugLog("json is null");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -115,13 +119,9 @@ public class GameLanguage {
|
||||
return name;
|
||||
}
|
||||
try {
|
||||
JsonObject obj = lang.get("item").getAsJsonObject().get("minecraft").getAsJsonObject();
|
||||
String jsonName = obj.get(material.name().toLowerCase()).getAsString();
|
||||
if (jsonName == null || jsonName.isEmpty()) {
|
||||
return name;
|
||||
}
|
||||
return jsonName;
|
||||
return lang.get("item.minecraft."+material.name().toLowerCase()).getAsString();
|
||||
} catch (NullPointerException npe) {
|
||||
npe.printStackTrace();
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -133,12 +133,7 @@ public class GameLanguage {
|
||||
return name;
|
||||
}
|
||||
try {
|
||||
JsonObject obj = lang.get("block").getAsJsonObject().get("minecraft").getAsJsonObject();
|
||||
String jsonName = obj.get(material.name().toLowerCase()).getAsString();
|
||||
if (jsonName == null || jsonName.isEmpty()) {
|
||||
return name;
|
||||
}
|
||||
return jsonName;
|
||||
return lang.get("block.minecraft."+material.name().toLowerCase()).getAsString();
|
||||
} catch (NullPointerException e) {
|
||||
return name;
|
||||
}
|
||||
@@ -151,12 +146,7 @@ public class GameLanguage {
|
||||
return name;
|
||||
}
|
||||
try {
|
||||
JsonObject obj = lang.get("entity").getAsJsonObject().get("minecraft").getAsJsonObject();
|
||||
String jsonName = obj.get(material.name().toLowerCase()).getAsString();
|
||||
if (jsonName == null || jsonName.isEmpty()) {
|
||||
return name;
|
||||
}
|
||||
return jsonName;
|
||||
return lang.get("entity.minecraft."+material.name().toLowerCase()).getAsString();
|
||||
} catch (NullPointerException e) {
|
||||
return name;
|
||||
}
|
||||
@@ -169,12 +159,7 @@ public class GameLanguage {
|
||||
return name;
|
||||
}
|
||||
try {
|
||||
JsonObject obj = lang.get("effect").getAsJsonObject().get("minecraft").getAsJsonObject();
|
||||
String jsonName = obj.get(effect.getName().toLowerCase()).getAsString();
|
||||
if (jsonName == null || jsonName.isEmpty()) {
|
||||
return name;
|
||||
}
|
||||
return jsonName;
|
||||
return lang.get("effect.minecraft."+effect.getName().toLowerCase()).getAsString();
|
||||
} catch (NullPointerException e) {
|
||||
return name;
|
||||
}
|
||||
@@ -187,12 +172,7 @@ public class GameLanguage {
|
||||
return name;
|
||||
}
|
||||
try {
|
||||
JsonObject obj = lang.get("enchantment").getAsJsonObject().get("minecraft").getAsJsonObject();
|
||||
String jsonName = obj.get(enchantmentName.toLowerCase()).getAsString();
|
||||
if (jsonName == null || jsonName.isEmpty()) {
|
||||
return name;
|
||||
}
|
||||
return jsonName;
|
||||
return lang.get("enchantment.minecraft."+enchantmentName.toLowerCase()).getAsString();
|
||||
} catch (NullPointerException e) {
|
||||
return name;
|
||||
}
|
||||
@@ -203,21 +183,8 @@ public class GameLanguage {
|
||||
if (lang == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
node = node.toLowerCase();
|
||||
String[] nodes = node.split(".");
|
||||
JsonObject obj = null;
|
||||
for (String s : nodes) {
|
||||
if (obj == null) {
|
||||
obj = lang.get(s).getAsJsonObject();
|
||||
} else {
|
||||
obj = obj.get(s).getAsJsonObject();
|
||||
}
|
||||
}
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
return obj.getAsString();
|
||||
try{
|
||||
return lang.get(node).getAsString();
|
||||
} catch (NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.maxgamer.quickshop.Util.MojangAPI;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
@@ -56,7 +57,7 @@ public class AssetJson {
|
||||
Util.debugLog("Cannot find request path.");
|
||||
return null;
|
||||
}
|
||||
JsonObject hashObj = langObj.getAsJsonObject("hash");
|
||||
JsonPrimitive hashObj = langObj.getAsJsonPrimitive("hash");
|
||||
if(hashObj == null || hashObj.isJsonNull()){
|
||||
Util.debugLog("Cannot get hash.");
|
||||
return null;
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
package org.maxgamer.quickshop.Util.MojangAPI;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.maxgamer.quickshop.NonQuickShopStuffs.com.sk89q.worldedit.util.net.HttpRequest;
|
||||
@@ -43,12 +46,12 @@ public class MojangAPI {
|
||||
*/
|
||||
@Nullable
|
||||
public String getVersionManifest() throws IOException {
|
||||
QuickShop.instance.getLogger().info("Downloading version manifest...");
|
||||
return HttpRequest.get(new URL(versionManifestUrl))
|
||||
.execute()
|
||||
.expectResponseCode(200)
|
||||
.returnContent()
|
||||
.asString("UTF-8").trim();
|
||||
QuickShop.instance.getLogger().info("Downloading version manifest...");
|
||||
return HttpRequest.get(new URL(versionManifestUrl))
|
||||
.execute()
|
||||
.expectResponseCode(200)
|
||||
.returnContent()
|
||||
.asString("UTF-8").trim();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -72,26 +75,26 @@ public class MojangAPI {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAssetIndexJson(@NotNull String mcVer) throws IOException{
|
||||
public String getAssetIndexJson(@NotNull String mcVer) throws IOException {
|
||||
String versionJson = getVersionJson(mcVer);
|
||||
if(versionJson == null){
|
||||
if (versionJson == null) {
|
||||
return null;
|
||||
}
|
||||
PerVersionJson perVersionList = gson.fromJson(versionJson, PerVersionJson.class);
|
||||
String url = null;
|
||||
if(perVersionList == null){
|
||||
JsonObject rootObj = new JsonParser().parse(versionJson).getAsJsonObject();
|
||||
JsonObject assetIndex = rootObj.getAsJsonObject("assetIndex");
|
||||
if (assetIndex == null) {
|
||||
Util.debugLog("Cannot get assetIndex obj.");
|
||||
return null;
|
||||
}
|
||||
for (PerVersionJson.PatchesBean bean:
|
||||
perVersionList.getPatches()) {
|
||||
if(!"game".equals(bean.getId())){
|
||||
continue;
|
||||
}
|
||||
url = bean.getAssetIndex().getUrl();
|
||||
break;
|
||||
JsonPrimitive urlObj = assetIndex.getAsJsonPrimitive("url");
|
||||
if (urlObj == null) {
|
||||
Util.debugLog("Cannot get asset url obj.");
|
||||
return null;
|
||||
}
|
||||
if(url == null){
|
||||
String url = urlObj.getAsString();
|
||||
if (url == null) {
|
||||
Util.debugLog("Cannot get asset url.");
|
||||
return null;
|
||||
}
|
||||
@@ -105,18 +108,17 @@ public class MojangAPI {
|
||||
|
||||
@Nullable
|
||||
public String downloadTextFileFromMojang(@NotNull String hash) throws IOException {
|
||||
File cacheFile = new File(Util.getCacheFolder(),hash);
|
||||
if(cacheFile.exists()){
|
||||
File cacheFile = new File(Util.getCacheFolder(), hash);
|
||||
if (cacheFile.exists()) {
|
||||
return Util.readToString(cacheFile);
|
||||
}
|
||||
String data;
|
||||
QuickShop.instance.getLogger().info("Downloading assets file...");
|
||||
data = HttpRequest.get(new URL(this.assetsUrl + hash.substring(0, 2)))
|
||||
.execute()
|
||||
.expectResponseCode(200)
|
||||
.returnContent()
|
||||
.asString("UTF-8").trim();
|
||||
|
||||
data = HttpRequest.get(new URL(this.assetsUrl + hash.substring(0, 2) + "/" + hash))
|
||||
.execute()
|
||||
.expectResponseCode(200)
|
||||
.returnContent()
|
||||
.asString("UTF-8").trim();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user