1
1
package com .craftmend .openaudiomc .spigot .modules .voicechat ;
2
2
3
3
import com .craftmend .openaudiomc .api .EventApi ;
4
+ import com .craftmend .openaudiomc .api .channels .ChannelJoinResponse ;
4
5
import com .craftmend .openaudiomc .api .channels .VoiceChannel ;
5
6
import com .craftmend .openaudiomc .api .channels .events .ChannelCreatedEvent ;
6
7
import com .craftmend .openaudiomc .api .channels .events .ChannelDeletedEvent ;
22
23
import com .craftmend .openaudiomc .generic .storage .enums .StorageKey ;
23
24
import com .craftmend .openaudiomc .generic .user .User ;
24
25
import com .craftmend .openaudiomc .spigot .modules .voicechat .channels .Channel ;
26
+ import com .craftmend .openaudiomc .spigot .modules .voicechat .channels .ChannelEnterResponse ;
25
27
import com .craftmend .openaudiomc .spigot .modules .voicechat .commands .*;
26
28
import org .bukkit .Bukkit ;
27
29
import org .bukkit .event .Listener ;
28
30
import org .bukkit .permissions .Permission ;
29
31
32
+ import java .util .ArrayList ;
30
33
import java .util .Collection ;
31
34
import java .util .Collections ;
32
35
import java .util .Map ;
@@ -108,6 +111,12 @@ public VoiceChannelService(
108
111
requirePermission ? permission : null ,
109
112
this
110
113
);
114
+
115
+ Object permissionViabilityBoolean = obj .get ("requirePermissionToSee" );
116
+ if (permissionViabilityBoolean != null && permissionViabilityBoolean instanceof Boolean ) {
117
+ staticChannel .setRequiresPermissionToSee ((boolean ) permissionViabilityBoolean );
118
+ }
119
+
111
120
channelMap .put (staticChannel .getName (), staticChannel );
112
121
OpenAudioLogger .info ("Created static channel: " + staticChannel .getName ());
113
122
@@ -189,8 +198,11 @@ public void onClientConnect(VoicechatReadyEvent event) {
189
198
return ;
190
199
}
191
200
User <?> user = (User <?>) event .getClient ().getActor ();
192
- PacketClientChannelsDisplayPacket packet = new PacketClientChannelsDisplayPacket ( new ClientChannelsDisplayPayload ( channelMap .values (), user , ClientChannelsDisplayPayload . ClientChannelOperation . ALL ));
201
+ Collection < Channel > visibleChannels = new ArrayList <>( channelMap .values ());
193
202
203
+ // filter out channels that require permission to see, and we don't have the permission
204
+ visibleChannels .removeIf (channel -> channel .isRequiresPermissionToSee () && channel .attemptEnter (user ) != ChannelEnterResponse .OK );
205
+ PacketClientChannelsDisplayPacket packet = new PacketClientChannelsDisplayPacket (new ClientChannelsDisplayPayload (visibleChannels , user , ClientChannelsDisplayPayload .ClientChannelOperation .ALL ));
194
206
ClientConnection client = (ClientConnection ) event .getClient ();
195
207
client .sendPacket (packet );
196
208
}
@@ -204,6 +216,11 @@ public void onMembersUpdate(ChannelMembersUpdatedEvent event) {
204
216
for (ClientConnection client : getService (NetworkingService .class ).getClients ()) {
205
217
// are they connected and are they in voice chat?
206
218
if (client .getRtcSessionManager ().isReady ()) {
219
+ // is this channel visible to the client?
220
+ if (event .getChannel ().requiresPermissionToSee () && event .getChannel ().joinPreconditionCheck (client ) != ChannelJoinResponse .NO_PERMISSION ) {
221
+ continue ;
222
+ }
223
+
207
224
PacketClientChannelsDisplayPacket packet = new PacketClientChannelsDisplayPacket (new ClientChannelsDisplayPayload (
208
225
Collections .singleton ((Channel ) event .getChannel ()),
209
226
client .getUser (),
@@ -223,6 +240,10 @@ public void onChannelCreate(ChannelCreatedEvent event) {
223
240
for (ClientConnection client : getService (NetworkingService .class ).getClients ()) {
224
241
// are they connected and are they in voice chat?
225
242
if (client .getRtcSessionManager ().isReady ()) {
243
+ if (event .getChannel ().requiresPermissionToSee () && event .getChannel ().joinPreconditionCheck (client ) != ChannelJoinResponse .NO_PERMISSION ) {
244
+ continue ;
245
+ }
246
+
226
247
PacketClientChannelsDisplayPacket packet = new PacketClientChannelsDisplayPacket (new ClientChannelsDisplayPayload (
227
248
Collections .singleton ((Channel ) event .getChannel ()),
228
249
client .getUser (),
@@ -242,6 +263,10 @@ public void onChannelDelete(ChannelDeletedEvent event) {
242
263
for (ClientConnection client : getService (NetworkingService .class ).getClients ()) {
243
264
// are they connected and are they in voice chat?
244
265
if (client .getRtcSessionManager ().isReady ()) {
266
+ if (event .getChannel ().requiresPermissionToSee () && event .getChannel ().joinPreconditionCheck (client ) != ChannelJoinResponse .NO_PERMISSION ) {
267
+ continue ;
268
+ }
269
+
245
270
PacketClientChannelsDisplayPacket packet = new PacketClientChannelsDisplayPacket (new ClientChannelsDisplayPayload (
246
271
Collections .singleton ((Channel ) event .getChannel ()),
247
272
client .getUser (),
0 commit comments