Skip to content

Commit

Permalink
Add a filter based on common teams
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Jan 18, 2024
1 parent 0268eff commit 825d939
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
4 changes: 4 additions & 0 deletions plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 825d939

Please sign in to comment.