Skip to content

Commit 07075c4

Browse files
committed
Add docs for RecipientsResolver
1 parent 8a02c74 commit 07075c4

File tree

1 file changed

+79
-2
lines changed

1 file changed

+79
-2
lines changed

api/src/main/java/net/draycia/carbon/api/channels/RecipientsResolver.java

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,36 @@
2828
import net.kyori.adventure.key.Key;
2929
import org.checkerframework.common.returnsreceiver.qual.This;
3030

31+
/**
32+
* Resolves the recipients for a message from a given sender.
33+
*
34+
* @see ChatChannel#recipientsResolver()
35+
* @see #builder(CarbonServer)
36+
* @since 3.0.0
37+
*/
3138
@FunctionalInterface
3239
public interface RecipientsResolver {
40+
41+
/**
42+
* Resolves the recipients for a message from a given sender.
43+
*
44+
* @param sender the sender to resolve recipients for
45+
* @return resolved recipients
46+
* @since 3.0.0
47+
*/
3348
List<Audience> recipients(CarbonPlayer sender);
3449

50+
/**
51+
* Creates a new combined {@link RecipientsResolver} from this resolver and {@code resolver}.
52+
*
53+
* <p>
54+
* Note that this method does not filter duplicate audiences.
55+
* </p>
56+
*
57+
* @param resolver second resolver
58+
* @return new combined resolver
59+
* @since 3.0.0
60+
*/
3561
default RecipientsResolver and(final RecipientsResolver resolver) {
3662
return sender -> {
3763
final List<Audience> recipients = new ArrayList<>(this.recipients(sender));
@@ -40,10 +66,25 @@ default RecipientsResolver and(final RecipientsResolver resolver) {
4066
};
4167
}
4268

69+
/**
70+
* Creates a new {@link Builder}.
71+
*
72+
* @param server server instance
73+
* @return new {@link Builder}
74+
* @since 3.0.0
75+
*/
4376
static Builder builder(final CarbonServer server) {
4477
return new Builder(server);
4578
}
4679

80+
/**
81+
* Mutable builder for {@link RecipientsResolver}.
82+
* <p>
83+
* Custom implementations are supported, however the builder simplifies most use cases.
84+
* </p>
85+
*
86+
* @since 3.0.0
87+
*/
4788
final class Builder {
4889
private final CarbonServer server;
4990
private final List<Predicate<CarbonPlayer>> playerFilters = new ArrayList<>();
@@ -53,26 +94,62 @@ private Builder(final CarbonServer server) {
5394
this.server = server;
5495
}
5596

97+
/**
98+
* Includes online players with permission to hear the channel that have not left the channel,
99+
* using {@link #players(Predicate)}.
100+
*
101+
* @param channel channel
102+
* @return this builder
103+
* @since 3.0.0
104+
*/
56105
public @This Builder permittedPlayersInChannel(final ChatChannel channel) {
57106
return this.permittedPlayersInChannel(channel.permissions(), channel.key());
58107
}
59108

109+
/**
110+
* Includes online players with permission to hear the channel that have not left the channel,
111+
* using {@link #players(Predicate)}.
112+
*
113+
* @param permissions permissions
114+
* @param channelKey channel
115+
* @return this builder
116+
* @since 3.0.0
117+
*/
60118
public @This Builder permittedPlayersInChannel(final ChannelPermissions permissions, final Key channelKey) {
61-
this.playerFilters.add(player -> permissions.hearingPermitted(player).permitted()
119+
return this.players(player -> permissions.hearingPermitted(player).permitted()
62120
&& !player.leftChannels().contains(channelKey));
63-
return this;
64121
}
65122

123+
/**
124+
* Includes online players matching the predicate in the resolved recipients. Adding multiple predicates
125+
* will include players matching any one of the predicate.
126+
*
127+
* @param filter player filter
128+
* @return this builder
129+
* @since 3.0.0
130+
*/
66131
public @This Builder players(final Predicate<CarbonPlayer> filter) {
67132
this.playerFilters.add(filter);
68133
return this;
69134
}
70135

136+
/**
137+
* Unconditionally includes the console in the resolved recipients.
138+
*
139+
* @return this builder
140+
* @since 3.0.0
141+
*/
71142
public @This Builder console() {
72143
this.includeConsole = true;
73144
return this;
74145
}
75146

147+
/**
148+
* Builds a new {@link RecipientsResolver} from the current state of this builder.
149+
*
150+
* @return new {@link RecipientsResolver} instance
151+
* @since 3.0.0
152+
*/
76153
public RecipientsResolver build() {
77154
final boolean includeConsole = this.includeConsole;
78155
final List<Predicate<CarbonPlayer>> playerFilters = List.copyOf(this.playerFilters);

0 commit comments

Comments
 (0)