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 optus 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 optus encoder used to encode the audio data
      audio - the audio data
      Returns:
      the audio player
    • 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

      Group createGroup(String name, @Nullable String password)
      Creates a new group.
      Parameters:
      name - the name of the group
      password - the password of the group - null for no password
      Returns:
      the group
    • 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()
      Returns:
      the maximum distance, voice chat audio can be heard
    • 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