Skip to content

Commit e295cbb

Browse files
committed
getmods in profile
1 parent 6e3948a commit e295cbb

File tree

6 files changed

+202
-5
lines changed

6 files changed

+202
-5
lines changed

dependency-reduced-pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</profile>
8484
</profiles>
8585
<properties>
86-
<maven.compiler.target>21</maven.compiler.target>
87-
<maven.compiler.source>21</maven.compiler.source>
86+
<maven.compiler.target>25</maven.compiler.target>
87+
<maven.compiler.source>25</maven.compiler.source>
8888
</properties>
8989
</project>

src/main/java/com/benjamin538/index/IndexProfile.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
// config
77
import com.benjamin538.config.ConfigGet;
88

9+
// mods
10+
import com.benjamin538.index.mods.GetMods;
11+
12+
// developer
13+
import com.benjamin538.index.mods.Developer;
14+
915
// logging
1016
import com.benjamin538.util.Logging;
1117

@@ -60,14 +66,17 @@ public void run() {
6066
profile = new JSONObject(Files.readString(tempPath));
6167
}
6268
String username = profile.getString("username");
69+
int id = profile.getInt("id");
6370
String displayName = profile.getString("display_name");
6471
boolean isVerified = profile.getBoolean("verified");
6572
boolean isAdmin = profile.getBoolean("admin");
73+
Developer dev = new Developer(username, displayName, id, isVerified, isAdmin);
6674
anim.stop();
6775
while (true) {
68-
Files.write(tempPath, profile.toString().getBytes());
76+
Files.write(tempPath, dev.exportJSON().toString().getBytes());
6977
logger.clearTerminal();
7078
System.out.println("Your profile:");
79+
System.out.println("---------------");
7180
System.out.println("Username: " + username);
7281
System.out.println("Display name: " + displayName);
7382
if (!isVerified) {
@@ -79,7 +88,8 @@ public void run() {
7988
}
8089
System.out.println("Admin");
8190
System.out.println("---------------");
82-
System.out.println("Actions:\n1.Change display name");
91+
System.out.println("Actions:\n1.Change display name\n2.View your pending mods\n3.View your published mods");
92+
System.out.println("---------------");
8393
String action = logger.askValue("Type action (q to exit)", "", true);
8494
if (action.toLowerCase().equals("q")) break;
8595
try {
@@ -90,8 +100,15 @@ public void run() {
90100
HttpRequest nameRequest = HttpRequest.newBuilder().uri(URI.create(ConfigGet.getIndexUrl() + "/v1/me")).PUT(HttpRequest.BodyPublishers.ofString("{\"display_name\": \"" + newName + "\"}")).header("User-Agent", "GeodeCLI").header("Authorization", "Bearer " + ConfigGet.getIndexToken()).header("Content-Type", "application/json").build();
91101
HttpResponse<String> nameResponse = client.send(nameRequest, HttpResponse.BodyHandlers.ofString());
92102
if (nameResponse.statusCode() != 200) logger.fatal("Unable to change name: status code " + nameResponse.statusCode());
93-
profile.put("display_name", newName);
103+
dev.setDisplayName(newName);
94104
logger.done("Changed display name to " + newName);
105+
Thread.sleep(1500);
106+
break;
107+
case 2:
108+
GetMods.getMods(client, logger, false);
109+
break;
110+
case 3:
111+
GetMods.getMods(client, logger, true);
95112
break;
96113
default:
97114
logger.warn("Wrong action");
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.benjamin538.index.mods;
2+
3+
// json
4+
import org.json.JSONObject;
5+
6+
public class Developer {
7+
private String username;
8+
private String displayName;
9+
private int id;
10+
private boolean verified;
11+
private boolean admin;
12+
13+
public Developer(String username, String displayName, int id, boolean verified, boolean admin) {
14+
this.username = username;
15+
this.displayName = displayName;
16+
this.id = id;
17+
this.verified = verified;
18+
this.admin = admin;
19+
}
20+
21+
public String getUsername() {
22+
return username;
23+
}
24+
25+
public String getDisplayName() {
26+
return displayName;
27+
}
28+
29+
public int getID() {
30+
return id;
31+
}
32+
33+
public boolean getVerified() {
34+
return verified;
35+
}
36+
37+
public boolean getAdmin() {
38+
return admin;
39+
}
40+
41+
public void setDisplayName(String newDisplayName) {
42+
this.displayName = newDisplayName;
43+
}
44+
45+
public JSONObject exportJSON() {
46+
JSONObject developerJSON = new JSONObject();
47+
developerJSON.put("id", id);
48+
developerJSON.put("username", username);
49+
developerJSON.put("display_name", displayName);
50+
developerJSON.put("verified", verified);
51+
developerJSON.put("admin", admin);
52+
return developerJSON;
53+
}
54+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.benjamin538.index.mods;
2+
3+
// logging
4+
import com.benjamin538.util.Logging;
5+
6+
// config
7+
import com.benjamin538.config.ConfigGet;
8+
9+
// http
10+
import java.net.http.HttpClient;
11+
import java.net.http.HttpRequest;
12+
import java.net.URI;
13+
import java.net.http.HttpResponse;
14+
15+
// json
16+
import org.json.JSONObject;
17+
import org.json.JSONArray;
18+
19+
public abstract class GetMods {
20+
public static void getMods(HttpClient client, Logging logger, boolean published) {
21+
String status = (published ? "accepted" : "pending");
22+
try {
23+
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(ConfigGet.getIndexUrl() + "/v1/me/mods?status=" + status)).GET().header("User-Agent", "GeodeCLI").header("Authorization", "Bearer " + ConfigGet.getIndexToken()).build();
24+
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
25+
JSONArray responseJSON = new JSONObject(response.body()).getJSONArray("payload");
26+
logger.clearTerminal();
27+
if (responseJSON.isEmpty()) {
28+
logger.done("You have no " + status + " mods");
29+
Thread.sleep(1500);
30+
return;
31+
}
32+
logger.askValue("Press any key to leave", "", false);
33+
} catch(Exception ex) {
34+
logger.fatal("Something went wrong: " + ex.getMessage());
35+
}
36+
}
37+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.benjamin538.index.mods;
2+
3+
// list
4+
import java.util.List;
5+
6+
public class Mod {
7+
private String version;
8+
private String name;
9+
private String id;
10+
private List<ModDeveloper> developers;
11+
private int downloadCounts;
12+
private boolean validated;
13+
14+
public Mod(String version, String name, String id, List<ModDeveloper> developers, int downloadCounts, boolean validated) {
15+
this.version = version;
16+
this.name = name;
17+
this.id = id;
18+
this.developers = developers;
19+
this.downloadCounts = downloadCounts;
20+
this.validated = validated;
21+
}
22+
23+
public String getVersion() {
24+
return version;
25+
}
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public int getDownloadCounts() {
32+
return downloadCounts;
33+
}
34+
35+
public boolean getValidated() {
36+
return validated;
37+
}
38+
39+
public String getID() {
40+
return id;
41+
}
42+
43+
public List<ModDeveloper> getDevelopers() {
44+
return developers;
45+
}
46+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.benjamin538.index.mods;
2+
3+
// json
4+
import org.json.JSONObject;
5+
6+
public class ModDeveloper {
7+
private String username;
8+
private String displayName;
9+
private int id;
10+
private boolean isOwner;
11+
12+
public ModDeveloper(String username, String displayName, int id, boolean isOwner) {
13+
this.username = username;
14+
this.displayName = displayName;
15+
this.id = id;
16+
this.isOwner = isOwner;
17+
}
18+
19+
public String getUsername() {
20+
return username;
21+
}
22+
23+
public String displayName() {
24+
return displayName;
25+
}
26+
27+
public int getID() {
28+
return id;
29+
}
30+
31+
public boolean getIsOwner() {
32+
return isOwner;
33+
}
34+
35+
public JSONObject exportJSON() {
36+
JSONObject profile = new JSONObject();
37+
profile.put("id", id);
38+
profile.put("username", username);
39+
profile.put("display_name", displayName);
40+
profile.put("is_owner", isOwner);
41+
return profile;
42+
}
43+
}

0 commit comments

Comments
 (0)