Skip to content

Commit 6974c44

Browse files
committed
add option to hide channels that you cannot join
1 parent 66ec90f commit 6974c44

File tree

9 files changed

+59
-5
lines changed

9 files changed

+59
-5
lines changed

.tool-versions

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
java openjdk-21
1+
java openjdk-18.0.2.1

api/dependency-reduced-pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595
</dependency>
9696
</dependencies>
9797
<properties>
98-
<java.version>1.8</java.version>
9998
<delombok.output>${project.build.directory}/delombok</delombok.output>
99+
<java.version>1.8</java.version>
100100
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
101101
<sourcepath>src/main/java</sourcepath>
102102
</properties>

api/src/main/java/com/craftmend/openaudiomc/api/channels/VoiceChannel.java

+6
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ public interface VoiceChannel {
7373
* @param client the client to remove
7474
*/
7575
void removeMember(Client client);
76+
77+
/**
78+
* Check if the channel requires permission to see
79+
* @return true if the channel requires permission to see
80+
*/
81+
boolean requiresPermissionToSee();
7682
}

modules/jutils/dependency-reduced-pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
</plugins>
8585
</build>
8686
<properties>
87-
<maven.compiler.source>8</maven.compiler.source>
8887
<maven.compiler.target>8</maven.compiler.target>
88+
<maven.compiler.source>8</maven.compiler.source>
8989
</properties>
9090
</project>

plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.craftmend.openaudiomc.spigot.modules.voicechat;
22

33
import com.craftmend.openaudiomc.api.EventApi;
4+
import com.craftmend.openaudiomc.api.channels.ChannelJoinResponse;
45
import com.craftmend.openaudiomc.api.channels.VoiceChannel;
56
import com.craftmend.openaudiomc.api.channels.events.ChannelCreatedEvent;
67
import com.craftmend.openaudiomc.api.channels.events.ChannelDeletedEvent;
@@ -22,11 +23,13 @@
2223
import com.craftmend.openaudiomc.generic.storage.enums.StorageKey;
2324
import com.craftmend.openaudiomc.generic.user.User;
2425
import com.craftmend.openaudiomc.spigot.modules.voicechat.channels.Channel;
26+
import com.craftmend.openaudiomc.spigot.modules.voicechat.channels.ChannelEnterResponse;
2527
import com.craftmend.openaudiomc.spigot.modules.voicechat.commands.*;
2628
import org.bukkit.Bukkit;
2729
import org.bukkit.event.Listener;
2830
import org.bukkit.permissions.Permission;
2931

32+
import java.util.ArrayList;
3033
import java.util.Collection;
3134
import java.util.Collections;
3235
import java.util.Map;
@@ -108,6 +111,12 @@ public VoiceChannelService(
108111
requirePermission ? permission : null,
109112
this
110113
);
114+
115+
Object permissionViabilityBoolean = obj.get("requirePermissionToSee");
116+
if (permissionViabilityBoolean != null && permissionViabilityBoolean instanceof Boolean) {
117+
staticChannel.setRequiresPermissionToSee((boolean) permissionViabilityBoolean);
118+
}
119+
111120
channelMap.put(staticChannel.getName(), staticChannel);
112121
OpenAudioLogger.info("Created static channel: " + staticChannel.getName());
113122

@@ -189,8 +198,11 @@ public void onClientConnect(VoicechatReadyEvent event) {
189198
return;
190199
}
191200
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());
193202

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));
194206
ClientConnection client = (ClientConnection) event.getClient();
195207
client.sendPacket(packet);
196208
}
@@ -204,6 +216,11 @@ public void onMembersUpdate(ChannelMembersUpdatedEvent event) {
204216
for (ClientConnection client : getService(NetworkingService.class).getClients()) {
205217
// are they connected and are they in voice chat?
206218
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+
207224
PacketClientChannelsDisplayPacket packet = new PacketClientChannelsDisplayPacket(new ClientChannelsDisplayPayload(
208225
Collections.singleton((Channel) event.getChannel()),
209226
client.getUser(),
@@ -223,6 +240,10 @@ public void onChannelCreate(ChannelCreatedEvent event) {
223240
for (ClientConnection client : getService(NetworkingService.class).getClients()) {
224241
// are they connected and are they in voice chat?
225242
if (client.getRtcSessionManager().isReady()) {
243+
if (event.getChannel().requiresPermissionToSee() && event.getChannel().joinPreconditionCheck(client) != ChannelJoinResponse.NO_PERMISSION) {
244+
continue;
245+
}
246+
226247
PacketClientChannelsDisplayPacket packet = new PacketClientChannelsDisplayPacket(new ClientChannelsDisplayPayload(
227248
Collections.singleton((Channel) event.getChannel()),
228249
client.getUser(),
@@ -242,6 +263,10 @@ public void onChannelDelete(ChannelDeletedEvent event) {
242263
for (ClientConnection client : getService(NetworkingService.class).getClients()) {
243264
// are they connected and are they in voice chat?
244265
if (client.getRtcSessionManager().isReady()) {
266+
if (event.getChannel().requiresPermissionToSee() && event.getChannel().joinPreconditionCheck(client) != ChannelJoinResponse.NO_PERMISSION) {
267+
continue;
268+
}
269+
245270
PacketClientChannelsDisplayPacket packet = new PacketClientChannelsDisplayPacket(new ClientChannelsDisplayPayload(
246271
Collections.singleton((Channel) event.getChannel()),
247272
client.getUser(),

plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/channels/Channel.java

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.craftmend.openaudiomc.generic.user.User;
1515
import com.craftmend.openaudiomc.spigot.modules.voicechat.VoiceChannelService;
1616
import lombok.Getter;
17+
import lombok.Setter;
1718
import org.jetbrains.annotations.Nullable;
1819

1920
import java.util.*;
@@ -26,6 +27,8 @@ public class Channel implements VoiceChannel {
2627
private final Map<UUID, ClientConnection> members = new HashMap<>();
2728
private final VoiceChannelService voiceChannelService;
2829
private final String requiredPermission;
30+
@Setter
31+
@Getter private boolean requiresPermissionToSee = false;
2932
@Getter private final ChannelType type;
3033

3134
public Channel(@Nullable User creator, String name, VoiceChannelService voiceChannelService) {
@@ -175,4 +178,9 @@ public void addMember(Client client) {
175178
public void removeMember(Client client) {
176179
removeMember(((ClientConnection) client).getUser());
177180
}
181+
182+
@Override
183+
public boolean requiresPermissionToSee() {
184+
return this.requiresPermissionToSee;
185+
}
178186
}

plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/commands/ChannelListCommand.java

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.craftmend.openaudiomc.generic.user.User;
1212
import com.craftmend.openaudiomc.spigot.modules.voicechat.VoiceChannelService;
1313
import com.craftmend.openaudiomc.spigot.modules.voicechat.channels.Channel;
14+
import com.craftmend.openaudiomc.spigot.modules.voicechat.channels.ChannelEnterResponse;
1415
import lombok.SneakyThrows;
1516

1617
import java.util.Collection;
@@ -39,6 +40,11 @@ public void onExecute(User sender, String[] args) {
3940
sender.sendMessage(Platform.translateColors(StorageKey.MESSAGE_VOICE_CHANNEL_LIST_HEADER.getString()));
4041

4142
for (Channel channel : channels) {
43+
// is this player able to see this channel? if not, then continue
44+
if (channel.isRequiresPermissionToSee() && channel.attemptEnter(sender) != ChannelEnterResponse.OK) {
45+
continue;
46+
}
47+
4248
StringBuilder readableOccupants;
4349
Collection<Client> occupants = channel.getMembers();
4450
if (occupants.isEmpty()) {

plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/tabcomplete/VoiceChannelTabCompleteProvider.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
import com.craftmend.openaudiomc.generic.user.User;
66
import com.craftmend.openaudiomc.spigot.modules.voicechat.VoiceChannelService;
77
import com.craftmend.openaudiomc.spigot.modules.voicechat.channels.Channel;
8+
import com.craftmend.openaudiomc.spigot.modules.voicechat.channels.ChannelEnterResponse;
89

10+
import java.util.ArrayList;
911
import java.util.Collection;
1012

1113
public class VoiceChannelTabCompleteProvider implements TabCompleteProvider {
1214

1315
@Override
1416
public String[] getOptions(User sender) {
15-
Collection<Channel> channels = OpenAudioMc.getService(VoiceChannelService.class).getChannels();
17+
Collection<Channel> channels = new ArrayList<>(OpenAudioMc.getService(VoiceChannelService.class).getChannels());
18+
channels.removeIf(channel -> channel.isRequiresPermissionToSee() && channel.attemptEnter(sender) != ChannelEnterResponse.OK);
1619
String[] options = new String[channels.size()];
1720
int i = 0;
1821
for (Channel channel : channels) {

plugin/src/main/resources/config.yml

+6
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ static-channels:
335335
permission: channels.staffchat
336336
requirePermission: true
337337

338+
339+
- name: admin-chat
340+
permission: channels.adminchat
341+
requirePermission: true
342+
requirePermissionToSee: true # hide this channel for players who don't have the permission
343+
338344
# PlaceholderAPI
339345
papi:
340346
# Value to display when player is connected to the web client

0 commit comments

Comments
 (0)