Skip to content

Commit

Permalink
[MAJOR] migrated to v2 api
Browse files Browse the repository at this point in the history
  • Loading branch information
kane50613 committed May 16, 2021
1 parent 18a9d3c commit f529170
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 72 deletions.
15 changes: 2 additions & 13 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tw.kane</groupId>
<artifactId>osu4j</artifactId>
<version>v1.2</version>
<version>v2</version>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>tw.kane.osu4j.Osu</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
Expand All @@ -39,7 +28,7 @@
</repository>
</distributionManagement>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
</properties>
</project>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>tw.kane</groupId>
<artifactId>osu4j</artifactId>
<version>v1.2</version>
<version>v2</version>

<distributionManagement>
<repository>
Expand Down
50 changes: 8 additions & 42 deletions src/main/java/tw/kane/osu4j/Base/Score.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package tw.kane.osu4j.Base;

import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.json.JSONObject;
import tw.kane.osu4j.Exception.InvalidTokenException;
import tw.kane.osu4j.Exception.NotFoundException;
import tw.kane.osu4j.OsuClient;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

public class Score {
private final JSONObject object;
private final DocumentContext object;

public String mapId, userId, scoreId;
public long score;
Expand All @@ -23,46 +19,16 @@ public class Score {

public Count counts;

public Score(JSONObject object) {
this.object = object;

isPerfect = !object.isNull("perfect") && Boolean.parseBoolean(object.getString("perfect"));
mapId = object.isNull("beatmap_id") ? null : object.getString("beatmap_id");
userId = object.isNull("user_id") ? null : object.getString("user_id");
scoreId = object.isNull("score_id") ? null : object.getString("score_id");
rank = object.isNull("rank") ? null : Rank.valueOf(object.getString("rank"));
score = object.isNull("score") ? 0 : Long.parseLong(object.getString("score"));

try {
playAt = object.isNull("date") ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(object.getString("date"));
} catch (ParseException e) {
playAt = null;
}

long _mods = object.isNull("enabled_mods") ? 0 : Long.parseLong(object.getString("enabled_mods"));
mods = Mod.parse(_mods);
public Score(JSONObject json) {
this.object = JsonPath.parse(json.toString());

counts = new Count();
}

public Beatmap getBeatmap() {
//TODO return beatmap
return null;
}

// public User getUser() throws NotFoundException, InvalidTokenException, IOException {
// return OsuClient.client.getUser(userId, true);
// }

private class Count {
long _300, _100, _50, miss, maxCombo;
public class Count {
public long _300, _100, _50, miss, maxCombo;

public Count() {
_300 = object.isNull("count300") ? 0 : Long.parseLong(object.getString("count300"));
_100 = object.isNull("count100") ? 0 : Long.parseLong(object.getString("count100"));
_50 = object.isNull("count50") ? 0 : Long.parseLong(object.getString("count50"));
miss = object.isNull("countmiss") ? 0 : Long.parseLong(object.getString("countmiss"));
maxCombo = object.isNull("maxcombo") ? 0 : Long.parseLong(object.getString("maxcombo"));

}
}

Expand Down
50 changes: 34 additions & 16 deletions src/main/java/tw/kane/osu4j/Base/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import java.util.Date;

public class User {
private DocumentContext object;
private final DocumentContext object;

public String id, name, country;
public String id, name, country, avatarUrl;
public int level;
public float accuracy;
public Date joinAt;
Expand All @@ -26,17 +26,24 @@ public class User {

public User(JSONObject json) {
object = JsonPath.parse(json.toString());
id = String.valueOf(JSON.get(object, "id", Integer.class, null));
name = JSON.get(object, "username", String.class, null);
country = JSON.get(object, "country.name", String.class,
JSON.get(object, "country_code", String.class, null)
id = String.valueOf(JSON.get(object, "$.id", Integer.class, null));
avatarUrl = JSON.get(object, "$.avatar_url", String.class, null);
name = JSON.get(object, "$.username", String.class, null);
country = JSON.get(object, "$.country.name", String.class,
JSON.get(object, "$.country_code", String.class, null)
);
level = JSON.get(object, "$.statistics.level.current", Integer.class, 0);
accuracy = JSON.get(object, "$.hit_accuracy", Float.class, 0f);

level = JSON.get(object, "statistics.level.current", Integer.class, 0);
accuracy = JSON.get(object, "hit_accuracy", Float.class, 0f);
isActive = JSON.get(object, "$.is_active", Boolean.class, false);
isBot = JSON.get(object, "$.is_bot", Boolean.class, false);
isDeleted = JSON.get(object, "$.is_deleted", Boolean.class, false);
isOnline = JSON.get(object, "$.is_online", Boolean.class, false);
isSupporter = JSON.get(object, "$.is_supporter", Boolean.class, false);
hasSupported = JSON.get(object, "$.has_supported", Boolean.class, false);

try {
joinAt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(JSON.get(object, "$.join_date", String.class, null));
joinAt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").parse(JSON.get(object, "$.join_date", String.class, null));
} catch (ParseException | NullPointerException e) {
joinAt = null;
}
Expand All @@ -46,25 +53,36 @@ public User(JSONObject json) {
pp = new PerformancePoint();
}

private class Count {
long _50, _100, _300, SSH, SS, SH, S, A, plays, secondPlayed;
public class Count {
public long SSH, SS, SH, S, A, plays, secondPlayed;

public Count() {
SSH = JSON.get(object, "$.statistics.grade_counts.ssh", Long.class, 0L);
SH = JSON.get(object, "$.statistics.grade_counts.sh", Long.class, 0L);
SS = JSON.get(object, "$.statistics.grade_counts.ss", Long.class, 0L);
S = JSON.get(object, "$.statistics.grade_counts.s", Long.class, 0L);
A = JSON.get(object, "$.statistics.grade_counts.a", Long.class, 0L);
plays = JSON.get(object, "$.statistics.play_count", Long.class, 0L);
secondPlayed = JSON.get(object, "$.statistics.play_time", Long.class, 0L);
}
}

private class PlayScore {
long ranked, total;
public class PlayScore {
public long ranked, total;

public PlayScore() {
ranked = JSON.get(object, "$.statistics.rank.ranked_score", Long.class, 0L);
total = JSON.get(object, "$.statistics.rank.total_score", Long.class, 0L);
}
}

private class PerformancePoint {
float pp;
long rank, countryRank;
public class PerformancePoint {
public long rank, countryRank, pp;

public PerformancePoint() {
pp = JSON.get(object, "$.statistics.pp", Long.class, 0L);
rank = JSON.get(object, "$.statistics.rank.global", Long.class, 0L);
countryRank = JSON.get(object, "$.statistics.rank.country", Long.class, 0L);
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/tw/kane/osu4j/OsuClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public OsuClient(String clientId, String secret) {
/**
* get user info
* @param id user's name or id
* @param mode get user specify mode's info
* @param allowCached allow cached for faster response
* @return User
* @throws InvalidTokenException if token provided to OsuClient wrong
* @throws NotFoundException if user not found
Expand Down Expand Up @@ -58,6 +60,9 @@ public User getUser(String id, Mode mode, boolean allowCached) throws IOExceptio
/**
* get user's recent plays in 24hrs
* @param id user's name or id
* @param type score type best or recent
* @param includeFails whether include failed scores
* @param mode get specify mode's score
* @return User
* @throws InvalidTokenException if token provided to OsuClient wrong
* @throws NotFoundException if user not found
Expand Down

0 comments on commit f529170

Please sign in to comment.