aboutsummaryrefslogtreecommitdiff
path: root/loader/src/main/java
diff options
context:
space:
mode:
authorsyeyoung <cyoung06@naver.com>2022-11-20 00:10:52 +0900
committersyeyoung <cyoung06@naver.com>2022-11-20 00:10:52 +0900
commitcce3c344e3a2219cbafbef0a988304af9b5e2cb1 (patch)
tree3fd99d403c0ea37092c6e50fdaf358fd29f598c7 /loader/src/main/java
parent93517ec3723f93886f2869e50e95ffa51a65377e (diff)
downloadSkyblock-Dungeons-Guide-cce3c344e3a2219cbafbef0a988304af9b5e2cb1.tar.gz
Skyblock-Dungeons-Guide-cce3c344e3a2219cbafbef0a988304af9b5e2cb1.tar.bz2
Skyblock-Dungeons-Guide-cce3c344e3a2219cbafbef0a988304af9b5e2cb1.zip
- Convert streams to for-loop (because... well... jsonarray.toList returns array with hashmaps)
- Fix typos - Color dg not loaded notif - Add bouncycastel provider on preinit Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'loader/src/main/java')
-rwxr-xr-xloader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java5
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/branch/UpdateRetrieverUtil.java86
2 files changed, 49 insertions, 42 deletions
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
index 30518481..16adb3ad 100755
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java
@@ -45,8 +45,10 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
import java.io.*;
+import java.security.Security;
import java.util.*;
@Mod(modid = Main.MOD_ID, version = Main.VERSION)
@@ -89,6 +91,7 @@ public class Main
NotificationManager.INSTANCE.updateNotification(dgUnloaded, Notification.builder()
.title("Dungeons Guide Not Loaded")
+ .titleColor(0xFFFF0000)
.description("Click to try reloading....")
.onClick(() -> {
try {
@@ -150,6 +153,7 @@ public class Main
NotificationManager.INSTANCE.updateNotification(dgUnloaded, Notification.builder()
.title("Dungeons Guide Not Loaded")
+ .titleColor(0xFFFF0000)
.description("Click to try reloading....")
.onClick(() -> {
try {
@@ -280,6 +284,7 @@ public class Main
@EventHandler
public void preInit(FMLPreInitializationEvent preInitializationEvent) {
+ Security.addProvider(new BouncyCastleProvider());
// setup static variables
main = this;
dgInterface = null;
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/branch/UpdateRetrieverUtil.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/branch/UpdateRetrieverUtil.java
index abc0cff4..9db6c8bc 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/branch/UpdateRetrieverUtil.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/branch/UpdateRetrieverUtil.java
@@ -16,9 +16,7 @@ import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.time.Instant;
-import java.util.List;
-import java.util.Optional;
-import java.util.UUID;
+import java.util.*;
import java.util.stream.Collectors;
public class UpdateRetrieverUtil {
@@ -41,16 +39,16 @@ public class UpdateRetrieverUtil {
String payload = getResponse(connection);
try {
JSONArray jsonArray = new JSONArray(payload);
- return jsonArray.toList()
- .stream()
- .map(a -> (JSONObject) a)
- .map(a -> {
- UpdateBranch updateBranch = new UpdateBranch();
- updateBranch.setId(a.getLong("id"));
- updateBranch.setName(a.getString("name"));
- updateBranch.setMetadata(a.getJSONObject("metadata"));
- return updateBranch;
- }).collect(Collectors.toList());
+ List<UpdateBranch> branches = new ArrayList<>();
+ for (Object a_ : jsonArray) {
+ JSONObject a = (JSONObject) a_;
+ UpdateBranch updateBranch = new UpdateBranch();
+ updateBranch.setId(a.getLong("id"));
+ updateBranch.setName(a.getString("name"));
+ updateBranch.setMetadata(a.getJSONObject("metadata"));
+ branches.add(updateBranch);
+ }
+ return branches;
} catch (Exception e) {
throw new ResponseParsingException(payload, e);
}
@@ -67,28 +65,30 @@ public class UpdateRetrieverUtil {
String payload = getResponse(connection);
try {
JSONArray jsonArray = new JSONArray(payload);
- return jsonArray.toList()
- .stream()
- .map(a -> (JSONObject) a)
- .map(a -> {
- Update update = new Update();
- update.setId(a.getLong("id"));
- update.setBranchId(a.getLong("branchId"));
- update.setName(a.getString("name"));
- update.setUpdateLog(a.getString("updateLog"));
- update.setMetadata(a.getJSONObject("metadata"));
- update.setAssets(a.getJSONObject("assets").getJSONArray("assets").toList().stream().map(b -> (JSONObject) b)
- .map(b -> {
- Update.Asset asset = new Update.Asset();
- asset.setName(b.getString("name"));
- asset.setAssetId(UUID.fromString(b.getString("assetId")));
- asset.setSize(b.getLong("size"));
- asset.setObjectId(b.getString("objectId"));
- return asset;
- }).collect(Collectors.toList()));
- update.setReleaseDate(Instant.parse(a.getString("releaseDate")));
- return update;
- }).collect(Collectors.toList());
+ List<Update> updates = new ArrayList<>();
+ for (Object o_ : jsonArray) {
+ JSONObject a = (JSONObject) o_;
+
+ Update update = new Update();
+ update.setId(a.getLong("id"));
+ update.setBranchId(a.getLong("branchId"));
+ update.setName(a.getString("versionName"));
+ update.setUpdateLog(a.getString("updateLog"));
+ update.setMetadata(a.getJSONObject("metadata"));
+ update.setAssets(a.getJSONObject("assets").getJSONArray("assets")
+ .toList().stream().map(b -> (HashMap) b)
+ .map(b -> {
+ Update.Asset asset = new Update.Asset();
+ asset.setName((String) b.get("name"));
+ asset.setAssetId(UUID.fromString((String) b.get("assetId")));
+ asset.setSize((Integer) b.get("size"));
+ asset.setObjectId((String) b.get("objectId"));
+ return asset;
+ }).collect(Collectors.toList()));
+ update.setReleaseDate(Instant.parse(a.getString("releaseDate")));
+ updates.add(update);
+ }
+ return updates;
} catch (Exception e) {
throw new ResponseParsingException(payload, e);
}
@@ -104,21 +104,22 @@ public class UpdateRetrieverUtil {
String payload = getResponse(connection);
try {
- JSONObject a = new JSONObject();
+ JSONObject a = new JSONObject(payload);
Update update = new Update();
update.setId(a.getLong("id"));
update.setBranchId(a.getLong("branchId"));
- update.setName(a.getString("name"));
+ update.setName(a.getString("versionName"));
update.setUpdateLog(a.getString("updateLog"));
update.setMetadata(a.getJSONObject("metadata"));
- update.setAssets(a.getJSONObject("assets").getJSONArray("assets").toList().stream().map(b -> (JSONObject) b)
+ update.setAssets(a.getJSONObject("assets").getJSONArray("assets")
+ .toList().stream().map(b -> (HashMap) b)
.map(b -> {
Update.Asset asset = new Update.Asset();
- asset.setName(b.getString("name"));
- asset.setAssetId(UUID.fromString(b.getString("assetId")));
- asset.setSize(b.getLong("size"));
- asset.setObjectId(b.getString("objectId"));
+ asset.setName((String) b.get("name"));
+ asset.setAssetId(UUID.fromString((String) b.get("assetId")));
+ asset.setSize((Integer) b.get("size"));
+ asset.setObjectId((String) b.get("objectId"));
return asset;
}).collect(Collectors.toList()));
update.setReleaseDate(Instant.parse(a.getString("releaseDate")));
@@ -136,6 +137,7 @@ public class UpdateRetrieverUtil {
HttpURLConnection connection = (HttpURLConnection) new URL(Main.DOMAIN + "/updates/"+update.getBranchId()+"/"+update.getId()+"/"+asset.getAssetId()).openConnection();
connection.setRequestProperty("User-Agent", "DungeonsGuide/1.0");
connection.setRequestMethod("GET");
+ connection.setRequestProperty("Authorization", "Bearer "+ AuthManager.getInstance().getWorkingTokenOrThrow());
connection.setDoInput(true);
connection.setDoOutput(true);