18
18
*/
19
19
package com .andre601 .javabotblockapi ;
20
20
21
- import net .dv8tion .jda .bot .sharding .ShardManager ;
22
- import net .dv8tion .jda .core .JDA ;
23
21
import org .apache .commons .lang3 .ObjectUtils ;
24
22
import org .jetbrains .annotations .NotNull ;
25
23
26
24
import java .util .HashMap ;
27
25
import java .util .Map ;
28
26
29
27
public class BotBlockAPI {
30
- private Map <String , String > authTokens = new HashMap <>();
31
-
28
+ private Map <String , String > authTokens ;
32
29
private int updateInterval ;
33
- private boolean jdaDisabled ;
34
- private JDA jda ;
35
- private ShardManager shardManager ;
36
30
37
31
/**
38
32
* Creates an instance of BotBlockAPI with the provided api tokens (as Map) and update interval.
@@ -45,65 +39,12 @@ public class BotBlockAPI{
45
39
public BotBlockAPI (@ NotNull Map <String , String > authTokens , int updateInterval ){
46
40
this .authTokens = authTokens ;
47
41
this .updateInterval = updateInterval ;
48
- this .jdaDisabled = true ;
49
- this .jda = null ;
50
- this .shardManager = null ;
51
- }
52
-
53
- /**
54
- * Creates an instance of BotBlockAPI with the provided api tokens (as Map), update interval and
55
- * {@link net.dv8tion.jda.core.JDA JDA instance}.
56
- *
57
- * @param authTokens
58
- * A Map of sites and their tokens. May not be null.
59
- * @param updateInterval
60
- * The update interval to set.
61
- * @param jda
62
- * An instance of {@link net.dv8tion.jda.core.JDA JDA}. May not be null.
63
- */
64
- public BotBlockAPI (@ NotNull Map <String , String > authTokens , int updateInterval , @ NotNull JDA jda ){
65
- this .authTokens = authTokens ;
66
- this .updateInterval = updateInterval ;
67
- this .jdaDisabled = false ;
68
- this .jda = jda ;
69
- this .shardManager = null ;
70
- }
71
-
72
- /**
73
- * Creates an instance of BotBlockAPI with the provided api tokens (as Map), update interval and
74
- * {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager instance}.
75
- *
76
- * @param authTokens
77
- * A Map of sites and their tokens. May not be null.
78
- * @param updateInterval
79
- * The update interval to set.
80
- * @param shardManager
81
- * An instance of {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager}.
82
- */
83
- public BotBlockAPI (@ NotNull Map <String , String > authTokens , int updateInterval , @ NotNull ShardManager shardManager ){
84
- this .authTokens = authTokens ;
85
- this .updateInterval = updateInterval ;
86
- this .jdaDisabled = false ;
87
- this .jda = null ;
88
- this .shardManager = shardManager ;
89
42
}
90
43
91
44
Map <String , String > getAuthTokens (){
92
45
return authTokens ;
93
46
}
94
47
95
- boolean isJdaDisabled (){
96
- return jdaDisabled ;
97
- }
98
-
99
- JDA getJDA (){
100
- return jda ;
101
- }
102
-
103
- ShardManager getShardManager (){
104
- return shardManager ;
105
- }
106
-
107
48
int getUpdateInterval (){
108
49
return updateInterval ;
109
50
}
@@ -113,37 +54,13 @@ int getUpdateInterval(){
113
54
*/
114
55
public static class Builder {
115
56
private Map <String , String > authTokens = new HashMap <>();
116
-
117
57
private int updateInterval = 30 ;
118
- private boolean jdaDisabled = false ;
119
- private JDA jda = null ;
120
- private ShardManager shardManager = null ;
121
58
122
59
/**
123
60
* Empty Builder class
124
61
*/
125
62
public Builder (){}
126
63
127
- /**
128
- * Constructor that also sets the {@link net.dv8tion.jda.core.JDA JDA instance}.
129
- *
130
- * @param jda
131
- * The instance of {@link net.dv8tion.jda.core.JDA JDA}.
132
- */
133
- public Builder (JDA jda ){
134
- this .jda = jda ;
135
- }
136
-
137
- /**
138
- * Constructor that also sets the {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager instance}.
139
- *
140
- * @param shardManager
141
- * The instance of {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager}.
142
- */
143
- public Builder (ShardManager shardManager ){
144
- this .shardManager = shardManager ;
145
- }
146
-
147
64
/**
148
65
* Adds the provided Site name and token to the Map.
149
66
* <br>If there is already an entry with the same key, it will be overwritten.
@@ -210,100 +127,13 @@ public Builder setUpdateInteval(int updateInterval){
210
127
return this ;
211
128
}
212
129
213
- /**
214
- * Sets if an instance of {@link net.dv8tion.jda.core.JDA JDA} or {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager}
215
- * need to be set.
216
- * <br>{@code true} means that it is *NOT* required to set. Default is false.
217
- *
218
- * <p><b>This will be ignored when either {@link #setJDA(JDA)} or {@link #setShardManager(ShardManager)} are set!</b>
219
- *
220
- * @param disable
221
- * The boolean to set if JDA/ShardManager is required. True means it's *NOT* required.
222
- *
223
- * @return The Builder after the boolean was set. Useful for chaining.
224
- */
225
- public Builder disableJDA (boolean disable ){
226
- this .jdaDisabled = disable ;
227
-
228
- return this ;
229
- }
230
-
231
- /**
232
- * Sets the instance of {@link net.dv8tion.jda.core.JDA JDA}. This will be ignored when {@link #setShardManager(ShardManager)}
233
- * is used!
234
- * <br>It will also disable {@link #disableJDA(boolean)} (set it to false) when it was set.
235
- *
236
- * <p>You can as an alternative define JDA directly through the constructor.
237
- *
238
- * <p><b>Example:</b>
239
- * <pre><code>
240
- * JDA jda = // Getting the JDA from somewhere
241
- *
242
- * BotBlockAPI api = new BotBlockAPI.Builder(jda) // Setting the JDA
243
- * // Adding sites through addAuthToken(String, String) and the build it with build()
244
- * </code></pre>
245
- *
246
- * @param jda
247
- * The instance of {@link net.dv8tion.jda.core.JDA JDA} to use. May not be null.
248
- *
249
- * @return The Builder after JDA was set. Useful for chaining.
250
- */
251
- public Builder setJDA (@ NotNull JDA jda ){
252
- if (jdaDisabled )
253
- jdaDisabled = false ;
254
-
255
- this .jda = jda ;
256
-
257
- return this ;
258
- }
259
-
260
- /**
261
- * Sets the instance of {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager}.
262
- * <br>This will disable {@link #disableJDA(boolean)} (set it to false) when it was set.
263
- *
264
- * <p>You can as an alternative define ShardManager directly through the constructor.
265
- *
266
- * <p><b>Example:</b>
267
- * <pre><code>
268
- * ShardManager shardManager = // Getting the ShardManager from somewhere
269
- *
270
- * BotBlockAPI api = new BotBlockAPI.Builder(shardManager) // Setting the ShardManager.
271
- * // Adding sites through addAuthToken(String, String) and the build it with build()
272
- * </code></pre>
273
- *
274
- * @param shardManager
275
- * The instance of {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager} to use. May not be null.
276
- *
277
- * @return The Builder after ShardManager was set. Useful for chaining.
278
- */
279
- public Builder setShardManager (@ NotNull ShardManager shardManager ){
280
- if (jdaDisabled )
281
- jdaDisabled = false ;
282
-
283
- this .shardManager = shardManager ;
284
-
285
- return this ;
286
- }
287
-
288
130
/**
289
131
* Builds the instance of {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI}.
290
132
*
291
- * @throws NullPointerException
292
- * When JDA nor ShardManager are set (null) and {@link #disableJDA(boolean)} is false.
293
- *
294
133
* @return The built, usable {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI}.
295
134
*/
296
135
public BotBlockAPI build (){
297
- if (shardManager != null )
298
- return new BotBlockAPI (authTokens , updateInterval , shardManager );
299
- else
300
- if (jda != null )
301
- return new BotBlockAPI (authTokens , updateInterval , jda );
302
- else
303
- if (jdaDisabled )
304
- return new BotBlockAPI (authTokens , updateInterval );
305
- else
306
- throw new NullPointerException ("disableJDA(Boolean) is false and JDA as-well as ShardManager are null!" );
136
+ return new BotBlockAPI (authTokens , updateInterval );
307
137
}
308
138
}
309
139
}
0 commit comments