Skip to content

Commit

Permalink
weave loader download
Browse files Browse the repository at this point in the history
  • Loading branch information
zszfympx committed Jan 7, 2024
1 parent 227e324 commit 6721cef
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/main/java/org/cubewhy/celestial/entities/Assets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2024 json.cn
*/
package org.cubewhy.celestial.entities;
import lombok.Data;

import java.util.Date;

/**
* Auto-generated: 2024-01-07 19:7:0
*
* @author json.cn (i@json.cn)
* @website http://www.json.cn/java2pojo/
*/
@Data
public class Assets {

private String url;
private long id;
private String node_id;
private String name;
private String label;
private Uploader uploader;
private String content_type;
private String state;
private long size;
private int download_count;
private Date created_at;
private Date updated_at;
private String browser_download_url;

}
35 changes: 35 additions & 0 deletions src/main/java/org/cubewhy/celestial/entities/Author.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2024 json.cn
*/
package org.cubewhy.celestial.entities;

import lombok.Data;

/**
* Auto-generated: 2024-01-07 19:7:0
*
* @author json.cn (i@json.cn)
* @website http://www.json.cn/java2pojo/
*/
@Data
public class Author {

private String login;
private long id;
private String node_id;
private String avatar_url;
private String gravatar_id;
private String url;
private String html_url;
private String followers_url;
private String following_url;
private String gists_url;
private String starred_url;
private String subscriptions_url;
private String organizations_url;
private String repos_url;
private String events_url;
private String received_events_url;
private String type;
private boolean site_admin;
}
37 changes: 37 additions & 0 deletions src/main/java/org/cubewhy/celestial/entities/Uploader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright 2024 json.cn
*/
package org.cubewhy.celestial.entities;

import lombok.Data;

/**
* Auto-generated: 2024-01-07 19:7:0
*
* @author json.cn (i@json.cn)
* @website http://www.json.cn/java2pojo/
*/
@Data
public class Uploader {

private String login;
private long id;
private String node_id;
private String avatar_url;
private String gravatar_id;
private String url;
private String html_url;
private String followers_url;
private String following_url;
private String gists_url;
private String starred_url;
private String subscriptions_url;
private String organizations_url;
private String repos_url;
private String events_url;
private String received_events_url;
private String type;
private boolean site_admin;


}
38 changes: 38 additions & 0 deletions src/main/java/org/cubewhy/celestial/entities/releaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2024 json.cn
*/
package org.cubewhy.celestial.entities;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
* Auto-generated: 2024-01-07 19:7:0
*
* @author json.cn (i@json.cn)
* @website http://www.json.cn/java2pojo/
*/
@Data
public class releaseEntity {

private String url;
private String assets_url;
private String upload_url;
private String html_url;
private long id;
private Author author;
private String node_id;
private String tag_name;
private String target_commitish;
private Date name;
private boolean draft;
private boolean prerelease;
private Date created_at;
private Date published_at;
private List<Assets> assets;
private String tarball_url;
private String zipball_url;
private String body;

}
3 changes: 1 addition & 2 deletions src/main/java/org/cubewhy/celestial/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public Event call() {
final ArrayList<EventData> dataList = EventManager.get(this.getClass());

if (dataList != null) {
for (int i = 0; i < dataList.size(); i++) {
EventData data = dataList.get(i);
for (EventData data : dataList) {
try {
data.target.invoke(data.source, this);
} catch (Exception e) {
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

package org.cubewhy.celestial.game.addon;

import com.google.gson.Gson;
import lombok.Getter;
import okhttp3.Response;
import org.cubewhy.celestial.entities.Assets;
import org.cubewhy.celestial.entities.releaseEntity;
import org.cubewhy.celestial.game.BaseAddon;
import org.cubewhy.celestial.utils.RequestUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -53,4 +58,37 @@ public static List<WeaveMod> findAll() {
public String toString() {
return this.file.getName();
}

public boolean downloadWeaveLoader(@Nullable String loaderUrl){
if(loaderUrl == null){
String api_json;
try(Response response = RequestUtils.get("https://api.github.com/repos/Weave-MC/Weave-Loader/releases/latest").execute()){
assert response.body() != null;
api_json = response.body().string();
} catch (IOException e) {
return false;
}
releaseEntity releaseEntity = JsonToObj(api_json, org.cubewhy.celestial.entities.releaseEntity.class);
if (releaseEntity != null) {
Assets[] assets = releaseEntity.getAssets().toArray(new Assets[0]);
for(Assets i:assets){
if(i.getName().endsWith(".jar")){
//TODO: download i.browser_download_url() to ~/.cubewhy/addon/Weave-<%s>.jar, releaseEntity.getName()
}
}
}
}
return true;
}

public static <T> T JsonToObj(String json, Class<T> clz){
Gson gson = new Gson();
if(Objects.isNull(json)) return null;
T obj = gson.fromJson(json, clz);
if(Objects.isNull(obj)){
return null;
}else{
return obj;
}
}
}

0 comments on commit 6721cef

Please sign in to comment.