Skip to content

Commit

Permalink
should close #15
Browse files Browse the repository at this point in the history
  • Loading branch information
xxAROX committed Jul 12, 2024
1 parent 36c4014 commit ad211b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/main/java/xxAROX/PresenceMan/Nukkit/PresenceMan.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public static void setActivity(@NonNull Player player, @Nullable ApiActivity act
put("xuid", Utils.retrievePlayerData_xuid(player));
put("server", PresenceMan.server);
}}.forEach(body::addProperty);
if (activity != null) activity.setClient_id(Long.getLong(client_id));
if (activity == null) body.addProperty("api_activity", (String)null);
else body.add("api_activity", activity.serialize());

Expand Down
26 changes: 7 additions & 19 deletions src/main/java/xxAROX/PresenceMan/Nukkit/entity/ApiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import lombok.experimental.Accessors;
import xxAROX.PresenceMan.Nukkit.PresenceMan;

import javax.annotation.Nullable;

@NoArgsConstructor
@NoArgsConstructor @AllArgsConstructor
@ToString
@Getter @Setter @Accessors(chain = true)
public class ApiActivity {
private Long client_id;
public ActivityType type;
public String state;
public String details;
Expand All @@ -38,18 +36,7 @@ public class ApiActivity {
public Integer party_max_player_count = null;
public Integer party_player_count = null;

public ApiActivity(ActivityType type, String state, String details, Long end, String large_icon_key, String large_icon_text, Integer party_max_player_count, Integer party_player_count){
this.type = type;
this.state = state;
this.details = details;
this.end = end;
this.large_icon_key = large_icon_key;
this.large_icon_text = large_icon_text;
this.party_max_player_count = party_max_player_count;
this.party_player_count = party_player_count;
}

public ApiActivity(ActivityType type, String state, String details, Long end, String large_icon_key, String large_icon_text){
public ApiActivity(ActivityType type, String state, String details, Long end, String large_icon_key, String large_icon_text) {
this.type = type;
this.state = state;
this.details = details;
Expand All @@ -60,7 +47,7 @@ public ApiActivity(ActivityType type, String state, String details, Long end, St

public JsonObject serialize(){
JsonObject json = new JsonObject();
json.addProperty("client_id", PresenceMan.client_id);
json.addProperty("client_id", client_id);
json.addProperty("type", type.toString());
json.addProperty("state", state);
json.addProperty("details", details);
Expand All @@ -74,6 +61,7 @@ public JsonObject serialize(){

public static ApiActivity deserialize(String input){
JsonObject json = new Gson().fromJson(input, JsonObject.class);
Long client_id = json.has("client_id") && !json.get("client_id").isJsonNull() ? json.get("client_id").getAsLong() : null;
String __type = (json.has("type") && !json.get("type").isJsonNull() ? json.get("type").getAsString() : ActivityType.PLAYING.toString()).toUpperCase();
ActivityType type = ActivityType.valueOf(__type);
String state = (json.has("state") && !json.get("state").isJsonNull() ? json.get("state").getAsString() : null);
Expand All @@ -83,7 +71,7 @@ public static ApiActivity deserialize(String input){
String large_icon_text = (json.has("large_icon_text") && !json.get("large_icon_text").isJsonNull() ? json.get("large_icon_text").getAsString() : null);
Integer party_max_player_count = (json.has("party_max_player_count") && !json.get("party_max_player_count").isJsonNull() ? json.get("party_max_player_count").getAsInt() : null);
Integer party_player_count = (json.has("'party_player_count'") && !json.get("'party_player_count'").isJsonNull() ? json.get("'party_player_count'").getAsInt() : null);
return new ApiActivity(type, state, details, end, large_icon_key, large_icon_text, party_max_player_count, party_player_count);
return new ApiActivity(client_id, type, state, details, end, large_icon_key, large_icon_text, party_max_player_count, party_player_count);
}

public final static class Defaults {
Expand Down

0 comments on commit ad211b1

Please sign in to comment.