1717
1818
1919public class Event extends EAObject {
20+ // BUILDER/CUSTOM
21+ @ NotNull public final ObjectId id ;
22+ @ NotNull public final String type ;
23+ public final long channel ;
24+ @ Nullable public final Long message ;
25+ @ Nullable public final Long controlPanel ;
2026 public final boolean custom ;
21- @ NotNull public final String host ;
22- @ Nullable public final ObjectId server ;
27+ @ NotNull public final Date created ;
2328 @ Nullable public final String title ;
29+ public final long host ;
2430 @ Nullable public final String description ;
31+ @ Nullable public final Set <Long > roles ;
32+ @ Nullable public final Set <String > rolesNamed ;
33+ @ Nullable public final ObjectId server ;
34+ @ Nullable public final CachedMedia media ;
2535 // BUILDER
2636 @ Nullable public final String ip ;
2737 @ Nullable public final String platform ;
2838 @ Nullable public final String version ;
2939 @ Nullable public final String prize ;
40+ @ Nullable public final Integer maxPlayers ;
3041 /**
3142 * The time the event starts
3243 */
3344 @ Nullable public final Date time ;
34- // WEBSOCKET
35- @ NotNull public final Set <String > rolesNamed ;
45+ @ Nullable public final Set <Long > subscribers ;
3646
3747 public Event (@ NotNull JsonObject json ) {
3848 super (json );
49+ id = new ObjectId (json .get ("id" ).getAsString ());
50+ type = json .get ("type" ).getAsString ();
51+ channel = json .get ("channel" ).getAsLong ();
52+ message = json .has ("message" ) ? json .get ("message" ).getAsLong () : null ;
53+ controlPanel = json .has ("controlPanel" ) ? json .get ("controlPanel" ).getAsLong () : null ;
3954 custom = json .get ("custom" ).getAsBoolean ();
40- server = json .has ("server" ) ? new ObjectId (json .get ("server" ).getAsString ()) : null ;
41- host = json .get ("host" ).getAsString ();
55+ created = new Date (json .get ("created" ).getAsLong ());
4256 title = json .has ("title" ) ? json .get ("title" ).getAsString () : null ;
57+ host = json .get ("host" ).getAsLong ();
4358 description = json .has ("description" ) ? json .get ("description" ).getAsString () : null ;
59+ if (json .has ("roles" )) {
60+ roles = new HashSet <>();
61+ for (final JsonElement element : json .getAsJsonArray ("roles" )) roles .add (element .getAsLong ());
62+ } else {
63+ roles = null ;
64+ }
65+ if (json .has ("rolesNamed" )) {
66+ rolesNamed = new HashSet <>();
67+ for (final JsonElement element : json .getAsJsonArray ("rolesNamed" )) rolesNamed .add (element .getAsString ());
68+ } else {
69+ rolesNamed = null ;
70+ }
71+ server = json .has ("server" ) ? new ObjectId (json .get ("server" ).getAsString ()) : null ;
72+ media = json .has ("media" ) ? new CachedMedia (json .getAsJsonObject ("media" )) : null ;
4473 ip = json .has ("ip" ) ? json .get ("ip" ).getAsString () : null ;
4574 platform = json .has ("platform" ) ? json .get ("platform" ).getAsString () : null ;
4675 version = json .has ("version" ) ? json .get ("version" ).getAsString () : null ;
4776 prize = json .has ("prize" ) ? json .get ("prize" ).getAsString () : null ;
77+ maxPlayers = json .has ("maxPlayers" ) ? json .get ("maxPlayers" ).getAsInt () : null ;
4878 time = json .has ("time" ) ? new Date (json .get ("time" ).getAsLong ()) : null ;
49-
50- // roles
51- rolesNamed = new HashSet <>();
52- if (json .has ("rolesNamed" )) for (final JsonElement element : json .getAsJsonArray ("rolesNamed" )) rolesNamed .add (element .getAsString ());
79+ if (json .has ("subscribers" )) {
80+ subscribers = new HashSet <>();
81+ for (final JsonElement element : json .getAsJsonArray ("subscribers" )) subscribers .add (element .getAsLong ());
82+ } else {
83+ subscribers = null ;
84+ }
5385 }
5486
5587 @ Nullable
@@ -59,11 +91,20 @@ public Long getTimeUntil() {
5991
6092 @ NotNull
6193 public Set <PingRole > getPingRoles () {
94+ if (rolesNamed == null ) return Set .of ();
6295 final Set <PingRole > pingRoles = new HashSet <>();
6396 for (final String role : rolesNamed ) {
6497 final PingRole pingRole = EventAlertsIntegration .getEnum (PingRole .class , role );
6598 if (pingRole != null ) pingRoles .add (pingRole );
6699 }
67100 return pingRoles ;
68101 }
102+
103+ public static class CachedMedia {
104+ @ NotNull public final String name ;
105+
106+ public CachedMedia (@ NotNull JsonObject json ) {
107+ this .name = json .get ("name" ).getAsString ();
108+ }
109+ }
69110}
0 commit comments