Skip to content

Commit 9f92cb7

Browse files
committed
Add more javadocs
1 parent e540f28 commit 9f92cb7

4 files changed

Lines changed: 38 additions & 14 deletions

File tree

core/src/main/java/org/mythicprojects/yetanothermessageslibrary/message/MessageDispatcher.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@
1616
import org.mythicprojects.yetanothermessageslibrary.replace.replacement.Replacement;
1717
import org.mythicprojects.yetanothermessageslibrary.util.TriFunction;
1818

19+
/**
20+
* MessageDispatcher is a class that allows you to send messages to receivers with placeholders and actions.
21+
* It highly simplifies the process of sending messages to multiple receivers in multiple languages etc.
22+
*
23+
* @param <RECEIVER> the type of the receiver
24+
* @param <DISPATCHER> the type of the dispatcher itself
25+
*/
1926
@SuppressWarnings("unchecked")
2027
public interface MessageDispatcher<RECEIVER, DISPATCHER extends MessageDispatcher<RECEIVER, ? extends DISPATCHER>> {
2128

2229
/**
2330
* Add a receiver to the dispatcher
31+
*
2432
* @param receiver the receiver
2533
* @return this dispatcher
2634
*/
@@ -29,6 +37,7 @@ public interface MessageDispatcher<RECEIVER, DISPATCHER extends MessageDispatche
2937

3038
/**
3139
* Add multiple receivers to the dispatcher
40+
*
3241
* @param receivers the receivers
3342
* @return this dispatcher
3443
*/
@@ -40,6 +49,7 @@ default DISPATCHER receivers(@NotNull Collection<? extends @Nullable RECEIVER> r
4049

4150
/**
4251
* Add multiple receivers to the dispatcher
52+
*
4353
* @param receivers the receivers
4454
* @return this dispatcher
4555
*/
@@ -53,6 +63,7 @@ default DISPATCHER receivers(@NotNull RECEIVER... receivers) {
5363

5464
/**
5565
* Add all players to the dispatcher
66+
*
5667
* @return this dispatcher
5768
* @throws UnsupportedOperationException if the operation is not implemented in the current MessageDispatcher
5869
*/
@@ -65,6 +76,7 @@ default DISPATCHER all() throws UnsupportedOperationException {
6576

6677
/**
6778
* Add all players to the dispatcher
79+
*
6880
* @return this dispatcher
6981
* @throws UnsupportedOperationException if the operation is not implemented in the current MessageDispatcher
7082
*/
@@ -75,6 +87,7 @@ default DISPATCHER allPlayers() throws UnsupportedOperationException {
7587

7688
/**
7789
* Add all viewers to the dispatcher
90+
*
7891
* @return this dispatcher
7992
* @throws UnsupportedOperationException if the operation is not implemented in the current MessageDispatcher
8093
*/
@@ -85,6 +98,7 @@ default DISPATCHER console() throws UnsupportedOperationException {
8598

8699
/**
87100
* Add a predicate to the dispatcher
101+
*
88102
* @param predicate the predicate
89103
* @return this dispatcher
90104
*/
@@ -93,9 +107,10 @@ default DISPATCHER console() throws UnsupportedOperationException {
93107

94108
/**
95109
* Add a predicate to the dispatcher for a specific receiver class
110+
*
96111
* @param receiverClass the class of the receiver
97-
* @param predicate the predicate
98-
* @param <T> the type of the receiver
112+
* @param predicate the predicate
113+
* @param <T> the type of the receiver
99114
* @return this dispatcher
100115
*/
101116
@Contract("_, _ -> this")
@@ -110,7 +125,8 @@ default <T extends RECEIVER> DISPATCHER predicate(@NotNull Class<T> receiverClas
110125

111126
/**
112127
* Add a field to the dispatcher to use by the replacements
113-
* @param key the key of the field
128+
*
129+
* @param key the key of the field
114130
* @param value the value of the field
115131
* @return this dispatcher
116132
*/
@@ -119,6 +135,7 @@ default <T extends RECEIVER> DISPATCHER predicate(@NotNull Class<T> receiverClas
119135

120136
/**
121137
* Add multiple fields to the dispatcher to use by the replacements
138+
*
122139
* @param fields the fields
123140
* @return this dispatcher
124141
*/
@@ -237,6 +254,7 @@ default <T extends RECEIVER> DISPATCHER with(
237254

238255
/**
239256
* Add an action to the dispatcher that will be executed after the message is sent
257+
*
240258
* @param action the action
241259
* @return this dispatcher
242260
*/
@@ -245,6 +263,7 @@ default <T extends RECEIVER> DISPATCHER with(
245263

246264
/**
247265
* Send the message to all receivers
266+
*
248267
* @return this dispatcher
249268
*/
250269
@Contract(" -> this")

tools/src/main/java/org/mythicprojects/yetanothermessageslibrary/replace/Replaceable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
public interface Replaceable {
99

10+
/**
11+
* @return whether this replaceable supports string replacement
12+
*/
1013
default boolean supportsStringReplacement() {
1114
return false;
1215
}

tools/src/main/java/org/mythicprojects/yetanothermessageslibrary/replace/StringReplacer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public static String replace(@Nullable Locale locale, @Nullable String text, @No
2222
for (Replaceable replacement : replacements) {
2323
text = replacement.replace(locale, text);
2424
}
25-
2625
return text;
2726
}
2827

tools/src/main/java/org/mythicprojects/yetanothermessageslibrary/replace/replacement/Replacement.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.regex.Pattern;
1111
import net.kyori.adventure.text.ComponentLike;
1212
import net.kyori.adventure.text.TextReplacementConfig;
13-
import org.jetbrains.annotations.ApiStatus;
1413
import org.jetbrains.annotations.NotNull;
1514
import org.jetbrains.annotations.Nullable;
1615
import org.mythicprojects.yetanothermessageslibrary.replace.Replaceable;
@@ -23,22 +22,30 @@ public abstract class Replacement implements Replaceable {
2322
private final Object placeholder;
2423

2524
protected Replacement(@NotNull Object placeholder) {
26-
PlaceholderType placeholderType = PlaceholderType.match(placeholder.getClass());
25+
PlaceholderType placeholderType = PlaceholderType.findType(placeholder.getClass());
2726
Validate.isTrue(placeholderType != null, "placeholder must be a String or Pattern");
2827
this.placeholderType = placeholderType;
2928
this.placeholder = placeholder;
3029
}
3130

31+
/**
32+
* @return the type of placeholder (String or Pattern)
33+
*/
3234
protected final @NotNull Replacement.PlaceholderType getPlaceholderType() {
3335
return this.placeholderType;
3436
}
3537

38+
/**
39+
* @return a new TextReplacementConfig.Builder that matches the placeholder
40+
*/
3641
protected final @NotNull TextReplacementConfig.Builder newReplacementBuilder() {
3742
return this.placeholderType.newReplacementBuilder(this.placeholder);
3843
}
3944

40-
@ApiStatus.Internal
41-
public final @NotNull Object getPlaceholder() {
45+
/**
46+
* @return the placeholder object to match (String or Pattern)
47+
*/
48+
protected final @NotNull Object getPlaceholder() {
4249
return this.placeholder;
4350
}
4451

@@ -79,14 +86,10 @@ protected enum PlaceholderType {
7986
this.replacementBuilderFactory = replacementBuilderFactory;
8087
}
8188

82-
public Class<?> getClazz() {
89+
private @NotNull Class<?> getClazz() {
8390
return this.clazz;
8491
}
8592

86-
public boolean isInstance(Object obj) {
87-
return this.clazz.isInstance(obj);
88-
}
89-
9093
public @NotNull String replace(@NotNull String text, @NotNull Object placeholder, @NotNull String replacement) {
9194
return this.replacer.apply(text, placeholder, replacement);
9295
}
@@ -95,7 +98,7 @@ public boolean isInstance(Object obj) {
9598
return this.replacementBuilderFactory.apply(placeholder);
9699
}
97100

98-
public static @Nullable Replacement.PlaceholderType match(@NotNull Class<?> clazz) {
101+
public static @Nullable Replacement.PlaceholderType findType(@NotNull Class<?> clazz) {
99102
return PLACEHOLDERS_MAP.get(clazz);
100103
}
101104

0 commit comments

Comments
 (0)