diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java index d360e230f..fa83371ac 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java @@ -76,6 +76,7 @@ public enum StorageKey { SETTINGS_HYDRATE_REGIONS_ON_BOOT(false, "options.hydrate-regions-on-boot", StorageLocation.CONFIG_FILE), SETTINGS_VOICE_FILTERS_GAMEMODE(false, "vc-filter.require-same-gamemode", StorageLocation.CONFIG_FILE), + SETTINGS_VOICE_FILTERS_TEAM(false, "vc-filter.require-common-team", StorageLocation.CONFIG_FILE), SETTINGS_BEDROCK_PREFIX(false, "options.bedrock-name-prefix", StorageLocation.CONFIG_FILE), SETTINGS_TOKEN_AUTO_LOGIN(false, "options.token-auto-login", StorageLocation.CONFIG_FILE), diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java index 2370afc4e..7c30939e1 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java @@ -21,6 +21,7 @@ import com.craftmend.openaudiomc.spigot.modules.voicechat.filters.FilterService; import com.craftmend.openaudiomc.spigot.modules.voicechat.filters.PeerFilter; import com.craftmend.openaudiomc.spigot.modules.voicechat.filters.impl.GamemodeFilter; +import com.craftmend.openaudiomc.spigot.modules.voicechat.filters.impl.TeamFilter; import com.craftmend.openaudiomc.spigot.modules.voicechat.tasks.PlayerProximityTicker; import com.craftmend.openaudiomc.spigot.modules.voicechat.tasks.PlayerVicinityMessageTask; import com.craftmend.openaudiomc.spigot.modules.voicechat.tasks.TickVoicePacketQueue; @@ -189,6 +190,11 @@ public void onEnable() { OpenAudioLogger.toConsole("Enabling voicechat gamemode filter"); getService(FilterService.class).addFilterFunction(new GamemodeFilter()); } + + if (StorageKey.SETTINGS_VOICE_FILTERS_TEAM.getBoolean()) { + OpenAudioLogger.toConsole("Enabling voicechat team filter"); + getService(FilterService.class).addFilterFunction(new TeamFilter()); + } } private void sendMessage(User player, String message) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/filters/impl/TeamFilter.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/filters/impl/TeamFilter.java new file mode 100644 index 000000000..980aed155 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/filters/impl/TeamFilter.java @@ -0,0 +1,33 @@ +package com.craftmend.openaudiomc.spigot.modules.voicechat.filters.impl; + +import com.craftmend.openaudiomc.spigot.modules.voicechat.filters.CustomFilterFunction; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Team; + +public class TeamFilter implements CustomFilterFunction { + + @Override + public boolean isPlayerValidListener(Player listener, Player possibleSpeaker) { + // is there a scoreboard present? + if (Bukkit.getScoreboardManager() == null) return true; + + boolean assignmentMatch = true; + for (Team team : Bukkit.getScoreboardManager().getMainScoreboard().getTeams()) { + boolean foundPlayerA = team.hasEntry(listener.getName()); + boolean foundPlayerB = team.hasEntry(possibleSpeaker.getName()); + + if (foundPlayerA && foundPlayerB) { + return true; + } + + // is only one of the players in the team? + if (foundPlayerA || foundPlayerB) { + assignmentMatch = false; + } + } + + return assignmentMatch; + } + +} diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index e75719b20..4066fe8e3 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -213,6 +213,10 @@ vc-filter: # When enabled, players will only be able to hear eachother if they both share the same gamemode (survival, creative, adventure, spectator) require-same-gamemode: false + # When enabled, players will only be able to hear eachother if they both share the same team. Edge cases: + # - Players without a team can only hear other players without a team + require-common-team: false + # PlaceholderAPI papi: # Value to display when player is connected to the web client