Skip to content

Commit f0c0284

Browse files
authored
Merge pull request #1 from HawkDiscord/feature/docs
Add docs where missing
2 parents d806adb + 7bc0827 commit f0c0284

6 files changed

Lines changed: 72 additions & 16 deletions

File tree

common/src/main/java/me/schlaubi/regnumutils/common/Misc.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,25 @@
1919

2020
package me.schlaubi.regnumutils.common;
2121

22+
import org.jetbrains.annotations.NotNull;
2223
import org.jetbrains.annotations.Nullable;
2324

2425
import java.util.Collection;
2526
import java.util.List;
2627

28+
/**
29+
* Some tools.
30+
*/
2731
public class Misc {
2832

33+
/**
34+
* Returns the first element of a {@link Collection}.
35+
* @param collection the collection
36+
* @param <T> the type of the elements
37+
* @return the element or {@code null} if the collection is empty
38+
*/
2939
@Nullable
30-
public static <T> T first(Collection<T> collection) {
40+
public static <T> T first(@NotNull Collection<T> collection) {
3141
if (collection.isEmpty()) {
3242
return null;
3343
}
@@ -38,7 +48,12 @@ public static <T> T first(Collection<T> collection) {
3848
}
3949
}
4050

41-
public static boolean isNumeric(String input) {
51+
/**
52+
* Checks whether a String is numeric or not.
53+
* @param input the string to check
54+
* @return whether a String is numeric or not
55+
*/
56+
public static boolean isNumeric(@NotNull String input) {
4257
return input
4358
.chars()
4459
.mapToObj(it -> (char) it)

common/src/main/java/me/schlaubi/regnumutils/common/builder/GameAnimatorBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ public TimeUnit getTimeUnit() {
241241
* @see GameAnimatorBuilder#setInterval(long)
242242
* @see GameAnimatorBuilder#setInitialDelay(long)
243243
*/
244+
@SuppressWarnings("UnusedReturnValue")
244245
@NotNull
245246
public GameAnimatorBuilder setTimeUnit(@NotNull TimeUnit unit) {
246247
this.unit = unit;
@@ -266,7 +267,6 @@ public GameAnimatorBuilder setJDA(JDA jda) {
266267
* @return the {@link GameAnimatorBuilder}
267268
* @see GameAnimatorBuilder#setApplier(Consumer)
268269
*/
269-
270270
@NotNull
271271
public GameAnimatorBuilder setShardManager(ShardManager shardManager) {
272272
return setApplier((game) -> JDAExtensions.applyGame(shardManager, game));

common/src/main/java/me/schlaubi/regnumutils/common/formatting/FormatUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import net.dv8tion.jda.api.entities.MessageEmbed;
2323
import org.jetbrains.annotations.NotNull;
2424

25+
/**
26+
* Some useful formatting helpers.
27+
*/
2528
public class FormatUtil {
2629

2730
/**

common/src/main/java/me/schlaubi/regnumutils/common/messaging/SafeMessage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
import java.util.function.Consumer;
4343
import java.util.function.Supplier;
4444

45+
/**
46+
* Util to send messages safely without risking {@link InsufficientPermissionException}s
47+
*/
4548
@SuppressWarnings({"unused", "WeakerAccess"})
4649
public class SafeMessage {
4750

common/src/main/java/me/schlaubi/regnumutils/common/parsing/EntityResolver.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import java.util.function.Function;
3131

3232
/**
33-
* Useful tool to parse a text-message for EntityResolvable
33+
* Useful tool to parse a text-message for EntityResolvable.
3434
*/
3535
@SuppressWarnings({"unused", "WeakerAccess"})
3636
public class EntityResolver {
3737

3838
/**
39-
* Resolves an {@link User} entity by a mention, it's id or it's name (case-sensitive)
39+
* Resolves an {@link User} entity by a mention, it's id or it's name (case-sensitive).
4040
*
4141
* @param input e.g an user input that should get parsed for mentions
4242
* @param jda the {@link JDA} instance of you bot
@@ -51,7 +51,7 @@ public static User resolveUser(
5151
}
5252

5353
/**
54-
* Resolves an {@link TextChannel} entity by a mention, it's id or it's name
54+
* Resolves an {@link TextChannel} entity by a mention, it's id or it's name.
5555
*
5656
* @param input e.g an user input that should get parsed for mentions
5757
* @param jda the {@link JDA} instance of you bot
@@ -69,7 +69,7 @@ public static User resolveUser(
6969

7070

7171
/**
72-
* Resolves an {@link Role} entity by a mention, it's id or it's name (case-sensitive)
72+
* Resolves an {@link Role} entity by a mention, it's id or it's name (case-sensitive).
7373
*
7474
* @param input e.g an user input that should get parsed for mentions
7575
* @param guild the {@link Guild} the member is on
@@ -84,7 +84,7 @@ public static Member resolveMember(
8484
}
8585

8686
/**
87-
* Resolves an {@link TextChannel} entity by a mention, it's id or it's name
87+
* Resolves an {@link TextChannel} entity by a mention, it's id or it's name.
8888
*
8989
* @param input e.g an user input that should get parsed for mentions
9090
* @param guild the {@link Guild} the member is on
@@ -101,7 +101,7 @@ public static Member resolveMember(
101101
}
102102

103103
/**
104-
* Resolves an {@link TextChannel} entity by a mention, it's id or it's name (case-sensitive)
104+
* Resolves an {@link TextChannel} entity by a mention, it's id or it's name (case-sensitive).
105105
*
106106
* @param input e.g an user input that should get parsed for mentions
107107
* @param guild the {@link Guild} the channel is on
@@ -116,7 +116,7 @@ public static TextChannel resolveTextChannel(
116116
}
117117

118118
/**
119-
* Resolves an {@link TextChannel} entity by a mention, it's id or it's name
119+
* Resolves an {@link TextChannel} entity by a mention, it's id or it's name.
120120
*
121121
* @param input e.g an user input that should get parsed for mentions
122122
* @param guild the {@link Guild} the channel is on
@@ -133,7 +133,7 @@ public static TextChannel resolveTextChannel(
133133
}
134134

135135
/**
136-
* Resolves an {@link Role} entity by a mention, it's id or it's name (case-sensitive)
136+
* Resolves an {@link Role} entity by a mention, it's id or it's name (case-sensitive).
137137
*
138138
* @param input e.g an user input that should get parsed for mentions
139139
* @param guild the {@link Guild} the role is on
@@ -148,7 +148,7 @@ public static Role resolveRole(
148148
}
149149

150150
/**
151-
* Resolves an {@link Role} entity by a mention, it's id or it's name
151+
* Resolves an {@link Role} entity by a mention, it's id or it's name.
152152
*
153153
* @param input e.g an user input that should get parsed for mentions
154154
* @param guild the {@link Guild} the role is on
@@ -165,7 +165,7 @@ public static Role resolveRole(
165165
}
166166

167167
/**
168-
* Resolves an {@link IMentionable mentionable} entity by a mention, it's id or it's name (case-sensitive)
168+
* Resolves an {@link IMentionable mentionable} entity by a mention, it's id or it's name (case-sensitive).
169169
*
170170
* @param input e.g an user input that should get parsed for mentions
171171
* @param type the {@link net.dv8tion.jda.api.entities.Message.MentionType} of the expected entity
@@ -179,13 +179,13 @@ public static <T extends IMentionable> T resolveEntity(
179179
@NotNull String input,
180180
@NotNull Message.MentionType type,
181181
@NotNull Function<@NotNull String, @Nullable T> idResolver,
182-
@NotNull BiFunction<@NotNull String, Boolean, @Nullable Collection<T>> nameResolver
182+
@NotNull BiFunction<@NotNull String, Boolean, @NotNull Collection<T>> nameResolver
183183
) {
184184
return resolveEntity(input, type, idResolver, nameResolver, false);
185185
}
186186

187187
/**
188-
* Resolves an {@link IMentionable mentionable} entity by a mention, it's id or it's name
188+
* Resolves an {@link IMentionable mentionable} entity by a mention, it's id or it's name.
189189
*
190190
* @param input e.g an user input that should get parsed for mentions
191191
* @param type the {@link net.dv8tion.jda.api.entities.Message.MentionType} of the expected entity
@@ -200,7 +200,7 @@ public static <T extends IMentionable> T resolveEntity(
200200
@NotNull String input,
201201
@NotNull Message.MentionType type,
202202
@NotNull Function<@NotNull String, @Nullable T> idResolver,
203-
@NotNull BiFunction<@NotNull String, Boolean, @Nullable Collection<T>> nameResolver,
203+
@NotNull BiFunction<@NotNull String, Boolean, @NotNull Collection<T>> nameResolver,
204204
boolean ignoreCase
205205
) {
206206
if (input.isBlank() || input.isEmpty()) {

common/src/main/kotlin/me/schlaubi/regnumutils/common/jda/_JDAExtensions.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,67 @@ import net.dv8tion.jda.api.OnlineStatus
2828
import net.dv8tion.jda.api.entities.Activity
2929
import net.dv8tion.jda.api.sharding.ShardManager
3030

31+
/**
32+
* The [JDA] instance used by the [cc.hawkbot.regnum.client.core.discord.ShardManager].
33+
* @see JDAShardManager
34+
*/
3135
val cc.hawkbot.regnum.client.core.discord.ShardManager.jda: ShardManager
3236
get() = (this as JDAShardManager).jda
3337

38+
/**
39+
* Converts a [GameAnimator.Game] to an [Activity] object which can be used for changing a [jda presence][net.dv8tion.jda.api.managers.Presence]
40+
* @see Activity
41+
*/
3442
fun GameAnimator.Game.toActivity() = Activity.of(Activity.ActivityType.fromKey(type), content)
3543

44+
/**
45+
* Converts a [GameAnimator.Game] to an [OnlineStatus] object which can be used for changing a [jda presence][net.dv8tion.jda.api.managers.Presence]
46+
* @see OnlineStatus
47+
*/
3648
val GameAnimator.Game.onlineStatus: OnlineStatus
3749
get() = OnlineStatus.fromKey(status)
3850

51+
/**
52+
* Applies a [GameAnimator.Game] to a a [jda presence][net.dv8tion.jda.api.managers.Presence]
53+
* @see net.dv8tion.jda.api.managers.Presence
54+
*/
3955
fun JDA.applyGame(game: GameAnimator.Game) = presence.setPresence(game.onlineStatus, game.toActivity())
4056

57+
/**
58+
* Applies a [GameAnimator.Game] to a a [jda presence][net.dv8tion.jda.api.managers.Presence]
59+
* @see net.dv8tion.jda.api.managers.Presence
60+
*/
4161
fun ShardManager.applyGame(game: GameAnimator.Game) = setPresence(game.onlineStatus, game.toActivity())
4262

4363
object JDAExtensions {
4464

65+
/**
66+
* @see cc.hawkbot.regnum.client.core.discord.ShardManager.jda
67+
*/
4568
@JvmStatic
4669
fun jda(shardManager: cc.hawkbot.regnum.client.core.discord.ShardManager) = shardManager.jda
4770

71+
/**
72+
* @see GameAnimator.Game.toActivity
73+
*/
4874
@JvmStatic
4975
fun gameToActivity(game: GameAnimator.Game) = game.toActivity()
5076

77+
/**
78+
* @see GameAnimator.Game.onlineStatus
79+
*/
5180
@JvmStatic
5281
fun gameToOnlineStatus(game: GameAnimator.Game) = game.onlineStatus
5382

83+
/**
84+
* @see JDA.applyGame
85+
*/
5486
@JvmStatic
5587
fun applyGame(jda: JDA, game: GameAnimator.Game) = jda.applyGame(game)
5688

89+
/**
90+
* @see ShardManager.applyGame
91+
*/
5792
@JvmStatic
5893
fun applyGame(jda: ShardManager, game: GameAnimator.Game) = jda.applyGame(game)
5994
}

0 commit comments

Comments
 (0)