Interface VoicechatServerApi

All Superinterfaces:
VoicechatApi

public interface VoicechatServerApi extends VoicechatApi
  • Method Details

    • sendEntitySoundPacketTo

      void sendEntitySoundPacketTo(VoicechatConnection connection, EntitySoundPacket packet)
      Sends the sound packet to the provided connection.
      Parameters:
      connection - the connection to send the packet to
      packet - the packet to send
    • sendLocationalSoundPacketTo

      void sendLocationalSoundPacketTo(VoicechatConnection connection, LocationalSoundPacket packet)
      Sends the sound packet to the provided connection.
      Parameters:
      connection - the connection to send the packet to
      packet - the packet to send
    • sendStaticSoundPacketTo

      void sendStaticSoundPacketTo(VoicechatConnection connection, StaticSoundPacket packet)
      Sends the sound packet to the provided connection.
      Parameters:
      connection - the connection to send the packet to
      packet - the packet to send
    • createEntityAudioChannel

      @Nullable EntityAudioChannel createEntityAudioChannel(UUID channelId, Entity entity)
      Creates a sound channel for the specified entity.
      Parameters:
      channelId - the ID of the channel - Has to be unique
      entity - the entity to attach the channel to
      Returns:
      the channel
    • createLocationalAudioChannel

      @Nullable LocationalAudioChannel createLocationalAudioChannel(UUID channelId, ServerLevel level, Position initialPosition)
      Creates a sound channel at the provided location.
      Parameters:
      channelId - the ID of the channel - Has to be unique
      level - the world
      initialPosition - the position where the sound should be played
      Returns:
      the channel
    • createStaticAudioChannel

      @Nullable StaticAudioChannel createStaticAudioChannel(UUID channelId, ServerLevel level, VoicechatConnection connection)
      Creates a static audio channel.
      Parameters:
      channelId - the ID of the channel - Has to be unique
      level - the level
      connection - the connection that should hear the audio
      Returns:
      the channel
    • createAudioPlayer

      AudioPlayer createAudioPlayer(AudioChannel audioChannel, OpusEncoder encoder, Supplier<short[]> audioSupplier)
      Creates a new audio player.

      NOTE: Never use more than one audio player for every audio channel.
      Parameters:
      audioChannel - the channel where the audio player should send the audio to
      encoder - the opus encoder used to encode the audio data
      audioSupplier - this gets called whenever a new audio frame needs to be sent. The size of the array always needs to be 960. To end the playback, return null
      Returns:
      the audio player
    • createAudioPlayer

      AudioPlayer createAudioPlayer(AudioChannel audioChannel, OpusEncoder encoder, short[] audio)
      Creates a new audio player.

      NOTE: Never use more than one audio player for every audio channel.
      Parameters:
      audioChannel - the channel where the audio player should send the audio to
      encoder - the opus encoder used to encode the audio data
      audio - the audio data
      Returns:
      the audio player
    • createAudioSender

      AudioSender createAudioSender(VoicechatConnection connection)
      Creates a new audio sender.
      This can be used to simulate a player sending microphone packets. This needs to be registered using registerAudioSender(AudioSender) and unregistered using unregisterAudioSender(AudioSender).
      Parameters:
      connection - the connection of the player
      Returns:
      the audio sender
    • registerAudioSender

      boolean registerAudioSender(AudioSender sender)
      NOTE: Only one instance of this can exist per player. This will return false if an audio sender for this player already exists.
      NOTE: The audio sender will only work for players that are connected to the server and don't have the mod installed. Otherwise, it will return false.
      Parameters:
      sender - the sender to register
      Returns:
      if the sender was registered
    • unregisterAudioSender

      boolean unregisterAudioSender(AudioSender sender)
      Unregisters an audio sender.
      Parameters:
      sender - the sender to unregister
      Returns:
      false if the audio sender was not registered.
    • playerAudioListenerBuilder

      PlayerAudioListener.Builder playerAudioListenerBuilder()
      Returns:
      a PlayerAudioListener builder
    • registerAudioListener

      boolean registerAudioListener(AudioListener listener)
      Registers a new AudioListener.
      Returns false if the listener is already registered.
      Parameters:
      listener - the listener to register
      Returns:
      if the listener was registered
    • unregisterAudioListener

      boolean unregisterAudioListener(AudioListener listener)
      Unregisters an AudioListener.
      Returns false if the listener is already unregistered.
      Parameters:
      listener - the listener to unregister
      Returns:
      if the listener was unregistered
    • unregisterAudioListener

      boolean unregisterAudioListener(UUID listenerId)
      Unregisters an AudioListener.
      Returns false if the listener is already unregistered.
      Parameters:
      listenerId - the AudioListener.getListenerId() of the listener to unregister
      Returns:
      if the listener was unregistered
    • getConnectionOf

      @Nullable VoicechatConnection getConnectionOf(UUID playerUuid)
      Gets the connection of the player with this UUID.
      Parameters:
      playerUuid - the players UUID
      Returns:
      the connection or null if the player is not connected
    • getConnectionOf

      @Nullable default VoicechatConnection getConnectionOf(ServerPlayer player)
      Gets the connection of the player.
      Parameters:
      player - the player
      Returns:
      the connection or null if the player is not connected
    • createGroup

      @Deprecated Group createGroup(String name, @Nullable String password)
      Deprecated.
      use groupBuilder() instead
      Creates a new group.
      Parameters:
      name - the name of the group
      password - the password of the group - null for no password
      Returns:
      the group
    • createGroup

      @Deprecated Group createGroup(String name, @Nullable String password, boolean persistent)
      Deprecated.
      use groupBuilder() instead
      Creates a new group.
      Parameters:
      name - the name of the group
      password - the password of the group - null for no password
      persistent - if the group should be persistent
      Returns:
      the group
    • groupBuilder

      Group.Builder groupBuilder()
      Returns:
      a new group builder
    • removeGroup

      boolean removeGroup(UUID groupId)
      Removes a persistent group. NOTE: You can't remove a group that is not persistent or has players in it.
      Parameters:
      groupId - the ID of the group
      Returns:
      if the group was removed
    • getGroup

      @Nullable Group getGroup(UUID groupId)
      Gets a group by its ID.
      Parameters:
      groupId - the ID of the group
      Returns:
      the group or null if the group doesn't exist
    • getGroups

      Collection<Group> getGroups()
      Returns:
      all groups
    • getSecret

      @Nullable @Deprecated UUID getSecret(UUID userId)
      Deprecated.
      Gets the secret for the user with this userId. Calling this function with a players UUID, that is already connected, this will return the secret of that player. Calling it with a new random UUID this will return a new secret. Use this with caution - Keep this secret confidential, as this allows connecting to the voice chat as this person. Note that if this userId is a players UUID and this player disconnects, the secret will get removed and thus is no longer valid to connect with.
      Parameters:
      userId - the user ID
      Returns:
      the secret or null if no server is running
    • getPlayersInRange

      Collection<ServerPlayer> getPlayersInRange(ServerLevel level, Position pos, double range, Predicate<ServerPlayer> filter)
      A convenience method to get all players in the range of a specific location.
      Parameters:
      level - the world
      pos - the location
      range - the range
      filter - the filter to exclude specific players
      Returns:
      all players in the provided location
    • getBroadcastRange

      double getBroadcastRange()
      The distance at which audio packets are broadcast. NOTE: This is not the distance it can be heard.
      Returns:
      the maximum distance, voice chat audio packets can be received
    • getPlayersInRange

      default Collection<ServerPlayer> getPlayersInRange(ServerLevel level, Position pos, double range)
      A convenience method to get all players in the range of a specific location.
      Parameters:
      level - the world
      pos - the location
      range - the range
      Returns:
      all players in the provided location
    • registerVolumeCategory

      void registerVolumeCategory(VolumeCategory category)
      Registers a volume category. This will get synchronized to all connected clients and all future clients that will connect. A category can be created with VoicechatApi.volumeCategoryBuilder(). The category can be unregistered with unregisterVolumeCategory(de.maxhenkel.voicechat.api.VolumeCategory).
      Parameters:
      category - the category to register
    • unregisterVolumeCategory

      default void unregisterVolumeCategory(VolumeCategory category)
      Unregisters a category for all connected players. This will release the texture ID for the icon if one exists on all clients.
      Parameters:
      category - the category to remove
    • unregisterVolumeCategory

      void unregisterVolumeCategory(String categoryId)
      Unregisters a category for all connected players. This will release the texture ID for the icon if one exists on all clients.
      Parameters:
      categoryId - the category ID to remove
    • getVolumeCategories

      Collection<VolumeCategory> getVolumeCategories()
      Returns:
      all registered volume categories
    • getServerConfig

      ConfigAccessor getServerConfig()
      Returns:
      a read-only config accessor for the mods server config