Class XSound.SoundPlayer

java.lang.Object
com.cryptomorin.xseries.XSound.SoundPlayer
Enclosing class:
XSound

public static class XSound.SoundPlayer extends Object
  • Field Details

  • Constructor Details

  • Method Details

    • withRecord

      public XSound.SoundPlayer withRecord(XSound.Record record)
    • forPlayers

      public XSound.SoundPlayer forPlayers(@Nullable org.bukkit.entity.Player... players)
      Plays the sound only for a single player and no one else can hear it.
    • atLocation

      public XSound.SoundPlayer atLocation(@Nullable org.bukkit.Location location)
      Plays the sound to all the nearby players (based on the specified volume)
    • forPlayers

      public XSound.SoundPlayer forPlayers(@Nullable Collection<org.bukkit.entity.Player> players)
      Play the sound for the given players.
    • getHearingPlayers

      public Collection<org.bukkit.entity.Player> getHearingPlayers()
      Gets a list of players who can hear this sound.
    • getHearingPlayers

      public static Collection<org.bukkit.entity.Player> getHearingPlayers(org.bukkit.Location location, double volume)
      Gets a list of players that can hear this sound at the given location and volume. This method pretty much uses the default algorithm used by Bukkit.
      Parameters:
      location - The location which the sound is going to be played.
      volume - The volume of the sound being played. Also see XSound.Record.volume
      Returns:
    • play

      public void play()
      Plays the sound with the given options and updating the player's location.
      Since:
      3.0.0
    • play

      public void play(@Nonnull org.bukkit.Location updatedLocation)
      Plays the sound with the updated location. Uses PacketPlayOutNamedSoundEffect.
      Parameters:
      updatedLocation - the updated location.
      Since:
      3.0.0
    • play

      public void play(Collection<org.bukkit.entity.Player> players, @Nonnull org.bukkit.Location updatedLocation)
    • stopSound

      public void stopSound()
      Stops the sound playing to the players that this sound was played to. Note this works fine if the sound was played to one specific player, but for location-based sounds this only works if the players were within the same range as the original volume level.

      If this is a critical issue you can extend this class and add a cache for all the players that heard the sound.

      Since:
      7.0.2