-
-
Notifications
You must be signed in to change notification settings - Fork 724
/
RoleManager.java
374 lines (355 loc) · 19.3 KB
/
RoleManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
* Copyright 2015-2017 Austin Keener & Michael Ritter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dv8tion.jda.core.managers;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.requests.restaction.AuditableRestAction;
import java.awt.Color;
import java.util.Arrays;
import java.util.Collection;
/**
* Facade for a {@link net.dv8tion.jda.core.managers.RoleManagerUpdatable RoleManagerUpdatable} instance.
* <br>Simplifies managing flow for convenience.
*
* <p>This decoration allows to modify a single field by automatically building an update {@link net.dv8tion.jda.core.requests.RestAction RestAction}
*/
public class RoleManager
{
protected final RoleManagerUpdatable updatable;
/**
* Creates a new RoleManager instance
*
* @param role
* {@link net.dv8tion.jda.core.entities.Role Role} that should be modified
*/
public RoleManager(Role role)
{
this.updatable = new RoleManagerUpdatable(role);
}
/**
* The {@link net.dv8tion.jda.core.JDA JDA} instance of this Manager
*
* @return the corresponding JDA instance
*/
public JDA getJDA()
{
return updatable.getJDA();
}
/**
* The {@link net.dv8tion.jda.core.entities.Guild Guild} this Manager's
* {@link net.dv8tion.jda.core.entities.Role Role} is in.
* <br>This is logically the same as calling {@code getRole().getGuild()}
*
* @return The parent {@link net.dv8tion.jda.core.entities.Guild Guild}
*/
public Guild getGuild()
{
return updatable.getGuild();
}
/**
* The target {@link net.dv8tion.jda.core.entities.Role Role} for this
* manager
*
* @return The target Role
*/
public Role getRole()
{
return updatable.getRole();
}
/**
* Sets the <b><u>name</u></b> of the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link RoleManagerUpdatable#getNameField()}
*
* <p>A role name <b>must not</b> be {@code null} nor less than 1 characters or more than 32 characters long!
*
* @param name
* The new name for the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
* @throws IllegalArgumentException
* If the provided name is {@code null} or not between 1-32 characters long
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getNameField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
*/
public AuditableRestAction<Void> setName(String name)
{
return updatable.getNameField().setValue(name).update();
}
/**
* Sets the {@link net.dv8tion.jda.core.Permission Permissions} of the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link net.dv8tion.jda.core.managers.fields.PermissionField#setValue(Long) RoleManagerUpdatable#getPermissionField().setValue(Long)}
*
* <p>Permissions may only include already present Permissions for the currently logged in account.
* <br>You are unable to give permissions you don't have!
*
* @param perms
* The new raw permission value for the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* <br>or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
* <br>or does not have permission to apply one of the specified permissions
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getPermissionField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
* @see #setPermissions(Collection)
* @see #setPermissions(Permission...)
*/
public AuditableRestAction<Void> setPermissions(long perms)
{
return updatable.getPermissionField().setValue(perms).update();
}
/**
* Sets the {@link net.dv8tion.jda.core.Permission Permissions} of the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link net.dv8tion.jda.core.managers.fields.PermissionField#setPermissions(Permission...) RoleManagerUpdatable#getPermissionField().setPermissions(Permission...)}
*
* <p>Permissions may only include already present Permissions for the currently logged in account.
* <br>You are unable to give permissions you don't have!
*
* @param permissions
* The new permission for the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* <br>or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
* <br>or does not have permission to apply one of the specified permissions
* @throws java.lang.IllegalArgumentException
* If any of the provided values is {@code null}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getPermissionField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
* @see #setPermissions(Collection)
* @see #setPermissions(long)
*/
public AuditableRestAction<Void> setPermissions(Permission... permissions)
{
return setPermissions(Arrays.asList(permissions));
}
/**
* Sets the {@link net.dv8tion.jda.core.Permission Permissions} of the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link net.dv8tion.jda.core.managers.fields.PermissionField#setPermissions(Collection) RoleManagerUpdatable#getPermissionField().setPermissions(Collection)}
*
* <p>Permissions may only include already present Permissions for the currently logged in account.
* <br>You are unable to give permissions you don't have!
*
* @param permissions
* The new permission for the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* <br>or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
* <br>or does not have permission to apply one of the specified permissions
* @throws java.lang.IllegalArgumentException
* If any of the provided values is {@code null}
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getPermissionField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
* @see #setPermissions(Permission...)
* @see #setPermissions(long)
*/
public AuditableRestAction<Void> setPermissions(Collection<Permission> permissions)
{
return updatable.getPermissionField().setPermissions(permissions).update();
}
/**
* Sets the {@link java.awt.Color Color} of the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link RoleManagerUpdatable#getColorField()}
*
* @param color
* The new color for the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getColorField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
*/
public AuditableRestAction<Void> setColor(Color color)
{
return updatable.getColorField().setValue(color).update();
}
/**
* Sets the <b><u>hoist state</u></b> of the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link RoleManagerUpdatable#getHoistedField()}
*
* @param hoisted
* Whether the selected {@link net.dv8tion.jda.core.entities.Role Role} should be hoisted
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getHoistedField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
*/
public AuditableRestAction<Void> setHoisted(boolean hoisted)
{
return updatable.getHoistedField().setValue(hoisted).update();
}
/**
* Sets the <b><u>mentionable state</u></b> of the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link RoleManagerUpdatable#getMentionableField()}
*
* @param mentionable
* Whether the selected {@link net.dv8tion.jda.core.entities.Role Role} should be mentionable
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getMentionableField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
*/
public AuditableRestAction<Void> setMentionable(boolean mentionable)
{
return updatable.getMentionableField().setValue(mentionable).update();
}
/**
* Adds the specified {@link net.dv8tion.jda.core.Permission Permissions} to the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link net.dv8tion.jda.core.managers.fields.PermissionField#givePermissions(Permission...) RoleManagerUpdatable#getPermissionField().givePermissions(Permission...)}
*
* <p>Permissions may only include already present Permissions for the currently logged in account.
* <br>You are unable to give permissions you don't have!
*
* @param perms
* The permission to give to the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* <br>or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
* <br>or does not have permission to apply one of the specified permissions
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getPermissionField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
* @see #setPermissions(Collection)
* @see #setPermissions(Permission...)
*/
public AuditableRestAction<Void> givePermissions(Permission... perms)
{
return givePermissions(Arrays.asList(perms));
}
/**
* Adds the specified {@link net.dv8tion.jda.core.Permission Permissions} to the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link net.dv8tion.jda.core.managers.fields.PermissionField#givePermissions(Collection) RoleManagerUpdatable#getPermissionField().givePermissions(Collection)}
*
* <p>Permissions may only include already present Permissions for the currently logged in account.
* <br>You are unable to give permissions you don't have!
*
* @param perms
* The permission to give to the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* <br>or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
* <br>or does not have permission to apply one of the specified permissions
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getPermissionField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
* @see #setPermissions(Collection)
* @see #setPermissions(Permission...)
*/
public AuditableRestAction<Void> givePermissions(Collection<Permission> perms)
{
return updatable.getPermissionField().givePermissions(perms).update();
}
/**
* Revokes the specified {@link net.dv8tion.jda.core.Permission Permissions} from the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link net.dv8tion.jda.core.managers.fields.PermissionField#revokePermissions(Permission...) RoleManagerUpdatable#getPermissionField().revokePermissions(Permission...)}
*
* <p>Permissions may only include already present Permissions for the currently logged in account.
* <br>You are unable to revoke permissions you don't have!
*
* @param perms
* The permission to give to the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* <br>or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
* <br>or does not have permission to revoke one of the specified permissions
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getPermissionField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
* @see #setPermissions(Collection)
* @see #setPermissions(Permission...)
*/
public AuditableRestAction<Void> revokePermissions(Permission... perms)
{
return revokePermissions(Arrays.asList(perms));
}
/**
* Revokes the specified {@link net.dv8tion.jda.core.Permission Permissions} from the selected {@link net.dv8tion.jda.core.entities.Role Role}.
* <br>Wraps {@link net.dv8tion.jda.core.managers.fields.PermissionField#revokePermissions(Collection) RoleManagerUpdatable#getPermissionField().revokePermissions(Collection)}
*
* <p>Permissions may only include already present Permissions for the currently logged in account.
* <br>You are unable to revoke permissions you don't have!
*
* @param perms
* The permission to give to the selected {@link net.dv8tion.jda.core.entities.Role Role}
*
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_ROLES MANAGE_ROLES}
* <br>or does not meet the required hierarchy position to {@link Role#canInteract(net.dv8tion.jda.core.entities.Role) interact} with this Role
* <br>or does not have permission to revoke one of the specified permissions
*
* @return {@link net.dv8tion.jda.core.requests.restaction.AuditableRestAction AuditableRestAction}
* <br>Update RestAction from {@link RoleManagerUpdatable#update() #update()}
*
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#getPermissionField()
* @see net.dv8tion.jda.core.managers.RoleManagerUpdatable#update()
* @see #setPermissions(Collection)
* @see #setPermissions(Permission...)
*/
public AuditableRestAction<Void> revokePermissions(Collection<Permission> perms)
{
return updatable.getPermissionField().revokePermissions(perms).update();
}
}