1
1
package me .robertlit .spigotresources .api ;
2
2
3
- import com .google .gson .annotations .JsonAdapter ;
4
- import me .robertlit .spigotresources .internal .AuthorJsonAdapter ;
5
- import me .robertlit .spigotresources .internal .HttpRequester ;
6
- import org .jetbrains .annotations .NotNull ;
7
- import org .jetbrains .annotations .Nullable ;
3
+ import com .google .gson .annotations .SerializedName ;
8
4
9
- import java .awt .image .BufferedImage ;
10
5
import java .util .Objects ;
11
6
12
7
/**
13
8
* Represents a resource author
14
9
*/
15
- @ JsonAdapter (AuthorJsonAdapter .class )
16
10
public class Author {
11
+
17
12
private final int id ;
18
13
private final String username ;
14
+ @ SerializedName ("resource_count" )
19
15
private final int resourceCount ;
20
16
private final Identities identities ;
21
- private final BufferedImage avatar ;
22
-
23
- private static final String AVATAR_URL = "https://www.spigotmc.org/data/avatars/l/%d/%d.jpg" ;
24
- private static final String DEFAULT_AVATAR_URL = "https://static.spigotmc.org/styles/spigot/xenforo/avatars/avatar_male_l.png" ;
25
- private static final BufferedImage DEFAULT_AVATAR = HttpRequester .requestImage (DEFAULT_AVATAR_URL );
17
+ @ SerializedName ("avatar" )
18
+ private final String avatarLink ;
26
19
27
20
/**
28
21
* Constructs an Author with the given parameters
29
22
* <p>
30
23
* This should only be used internally
31
24
* </p>
32
- * @param id user id
33
- * @param username username
25
+ *
26
+ * @param id user id
27
+ * @param username username
34
28
* @param resourceCount amount of resources
35
- * @param identities social media identities
29
+ * @param identities social media identities
30
+ * @param avatarLink link to avatar
36
31
*/
37
- public Author (int id , @ NotNull String username , int resourceCount , @ NotNull Identities identities ) {
32
+ private Author (int id , String username , int resourceCount , Identities identities , String avatarLink ) {
38
33
this .id = id ;
39
34
this .username = username ;
40
35
this .resourceCount = resourceCount ;
41
36
this .identities = identities ;
42
- BufferedImage image = HttpRequester .requestImage (String .format (AVATAR_URL , id / 1000 , id ));
43
- if (image == null ) {
44
- image = DEFAULT_AVATAR ;
45
- }
46
- this .avatar = image ;
37
+ this .avatarLink = avatarLink ;
47
38
}
48
39
49
40
/**
50
41
* Gets this author's id
42
+ *
51
43
* @return id
52
44
*/
53
45
public int getId () {
@@ -56,15 +48,17 @@ public int getId() {
56
48
57
49
/**
58
50
* Gets this author's username
51
+ *
59
52
* @return username
60
53
*/
61
- @ NotNull
54
+
62
55
public String getUsername () {
63
56
return username ;
64
57
}
65
58
66
59
/**
67
60
* Gets the amount of resources this author has published
61
+ *
68
62
* @return amount of resources this author has published
69
63
*/
70
64
public int getResourceCount () {
@@ -73,36 +67,29 @@ public int getResourceCount() {
73
67
74
68
/**
75
69
* Gets this author's social media identities
70
+ *
76
71
* @return social media identities
77
72
*/
78
- @ NotNull
73
+
79
74
public Identities getIdentities () {
80
75
return identities ;
81
76
}
82
77
83
- /**
84
- * Gets this author's avatar
85
- * @return author's avatar
86
- */
87
- @ NotNull
88
- public BufferedImage getAvatar () {
89
- return avatar ;
78
+ public String getAvatarLink () {
79
+ return avatarLink ;
90
80
}
91
81
92
82
@ Override
93
83
public boolean equals (Object o ) {
94
84
if (this == o ) return true ;
95
85
if (o == null || getClass () != o .getClass ()) return false ;
96
86
Author author = (Author ) o ;
97
- return id == author .id &&
98
- resourceCount == author .resourceCount &&
99
- username .equals (author .username ) &&
100
- identities .equals (author .identities );
87
+ return id == author .id && resourceCount == author .resourceCount && username .equals (author .username ) && identities .equals (author .identities ) && avatarLink .equals (author .avatarLink );
101
88
}
102
89
103
90
@ Override
104
91
public int hashCode () {
105
- return Objects .hash (id , username , resourceCount , identities );
92
+ return Objects .hash (id , username , resourceCount , identities , avatarLink );
106
93
}
107
94
108
95
@ Override
@@ -112,33 +99,36 @@ public String toString() {
112
99
", username='" + username + '\'' +
113
100
", resourceCount=" + resourceCount +
114
101
", identities=" + identities +
102
+ ", avatarLink='" + avatarLink + '\'' +
115
103
'}' ;
116
104
}
117
105
118
106
/**
119
107
* Represents an Author's social media identities
120
108
*/
121
109
public static class Identities {
110
+
122
111
private final String discord , youtube , aim , icq , msn , yahoo , skype , gtalk , facebook , twitter , github ;
123
112
124
113
/**
125
114
* Constructs an Identities object with the given parameters
126
115
* <p>
127
116
* This should only be used internally
128
117
* </p>
129
- * @param discord discord identity
130
- * @param youtube youtube identity
131
- * @param aim aim identity
132
- * @param icq icq identity
133
- * @param msn msn identity
134
- * @param yahoo yahoo identity
135
- * @param skype skype identity
136
- * @param gtalk google talk identity
118
+ *
119
+ * @param discord discord identity
120
+ * @param youtube youtube identity
121
+ * @param aim aim identity
122
+ * @param icq icq identity
123
+ * @param msn msn identity
124
+ * @param yahoo yahoo identity
125
+ * @param skype skype identity
126
+ * @param gtalk google talk identity
137
127
* @param facebook facebook identity
138
- * @param twitter twitter identity
139
- * @param github github identity
128
+ * @param twitter twitter identity
129
+ * @param github github identity
140
130
*/
141
- public Identities (@ Nullable String discord , @ Nullable String youtube , @ Nullable String aim , @ Nullable String icq , @ Nullable String msn , @ Nullable String yahoo , @ Nullable String skype , @ Nullable String gtalk , @ Nullable String facebook , @ Nullable String twitter , @ Nullable String github ) {
131
+ public Identities (String discord , String youtube , String aim , String icq , String msn , String yahoo , String skype , String gtalk , String facebook , String twitter , String github ) {
142
132
this .discord = discord ;
143
133
this .youtube = youtube ;
144
134
this .aim = aim ;
@@ -155,87 +145,87 @@ public Identities(@Nullable String discord, @Nullable String youtube, @Nullable
155
145
/**
156
146
* @return discord identity
157
147
*/
158
- @ Nullable
148
+
159
149
public String getDiscord () {
160
150
return discord ;
161
151
}
162
152
163
153
/**
164
154
* @return youtube identity
165
155
*/
166
- @ Nullable
156
+
167
157
public String getYoutube () {
168
158
return youtube ;
169
159
}
170
160
171
161
/**
172
162
* @return AIM identity
173
163
*/
174
- @ Nullable
164
+
175
165
public String getAim () {
176
166
return aim ;
177
167
}
178
168
179
169
/**
180
170
* @return ICQ identity
181
171
*/
182
- @ Nullable
172
+
183
173
public String getIcq () {
184
174
return icq ;
185
175
}
186
176
187
177
/**
188
178
* @return MSN identity
189
179
*/
190
- @ Nullable
180
+
191
181
public String getMsn () {
192
182
return msn ;
193
183
}
194
184
195
185
/**
196
186
* @return yahoo identity
197
187
*/
198
- @ Nullable
188
+
199
189
public String getYahoo () {
200
190
return yahoo ;
201
191
}
202
192
203
193
/**
204
194
* @return skype identity
205
195
*/
206
- @ Nullable
196
+
207
197
public String getSkype () {
208
198
return skype ;
209
199
}
210
200
211
201
/**
212
202
* @return google talk identity
213
203
*/
214
- @ Nullable
204
+
215
205
public String getGoogleTalk () {
216
206
return gtalk ;
217
207
}
218
208
219
209
/**
220
210
* @return facebook identity
221
211
*/
222
- @ Nullable
212
+
223
213
public String getFacebook () {
224
214
return facebook ;
225
215
}
226
216
227
217
/**
228
218
* @return twitter identity
229
219
*/
230
- @ Nullable
220
+
231
221
public String getTwitter () {
232
222
return twitter ;
233
223
}
234
224
235
225
/**
236
226
* @return github identity
237
227
*/
238
- @ Nullable
228
+
239
229
public String getGithub () {
240
230
return github ;
241
231
}
0 commit comments