Class SoundFile

java.lang.Object
de.mrjulsen.dragnsounds.core.filesystem.SoundFile

public class SoundFile extends Object
This object contains information about one specific sound file on the server. While most of the values are read-only, addons can use the metadata to store additional information (such as visibility to other players, etc.)
  • Field Details

    • META_DISPLAY_NAME

      public static final String META_DISPLAY_NAME
      Default metadata key to get the display name of the file which is stored in the metadata. (because it is not read-only)
      See Also:
    • META_DEFAULT_KEYS

      public static final String[] META_DEFAULT_KEYS
    • CURRENT_VERSION

      protected static final int CURRENT_VERSION
      See Also:
    • DEFAULT_AUDIO_FILE_EXTENSION

      public static final String DEFAULT_AUDIO_FILE_EXTENSION
      See Also:
    • metadata

      protected Map<String,String> metadata
  • Method Details

    • currentVersion

      public int currentVersion()
    • getMetadata

      public Map<String,String> getMetadata()
      Additional data about this file. Addons can use this to store their own info about sound files.
      Returns:
      A copy of the metadata of this file. (Not the actual object to prevent changes)
      Related:
      updateMetadata(...) - Add or replace metadata entries., removeMetadata(...) - Remove metadata entries.
    • updateMetadata

      public void updateMetadata(Map<String,String> meta)
      Update the metadata of this file. The data will be send to the server and applied there.
      Parameters:
      meta - The collection of the new keys and values. This is NOT the complete Map containing ALL metadata entries, but only a collection of the changes. New keys will be added and existing ones will be replaced.
      Related:
      removeMetadata(...) - Remove metadata entries.
    • removeMetadata

      public void removeMetadata(Set<String> keys)
      Update the metadata of this file. The data will be send to the server and applied there.
      Parameters:
      keys - A collection of metadata keys that should be removed from the list.
      API Note:
      You CANNOT remove any of the built-in metadata entries, such as META_DISPLAY_NAME, as they are changeable, but not optional. You can add these keys to the Set, but they get removed while processing.
      Related:
      updateMetadata(...) - Add or replace metadata entries., META_DEFAULT_KEYS - Contains all built-in metadata keys.
    • getMetadataSafe

      public String getMetadataSafe(String key)
      A safe method to get the metadata of the sound file.
      Parameters:
      key - The key name of the metadata entry.
      Returns:
      The metadata string value or an empty string if the metadata entry does not exist.
    • getLocation

      public SoundLocation getLocation()
      Returns:
      The location where the sound file is saved.
    • getId

      public String getId()
      Returns:
      The id of the sound and the name of the sound file on disk.
    • hash

      public String hash()
      Returns:
      The file hash value.
    • getInfo

      public SoundFileInfo getInfo()
      Returns:
      Some additional read-only information about the file itself, such as the owner or the upload timestamp. It also contains shortcuts to important information for better performance. These values are changed automatically when the file hash changes.
    • getPath

      public Optional<Path> getPath()
      Returns:
      An Optional containing the path to the sound file or an empty Optional if the path is invalid or there is an error while generating the path.
    • getPath

      protected static Optional<Path> getPath(SoundLocation location, String soundFileId)
    • getAsFile

      public Optional<File> getAsFile()
      Returns the file object of this sound.
      Returns:
      The file, if available.
      Valid on side:
      Server
    • getDisplayName

      public String getDisplayName()
      A shortcut to a default metadata value.
      Returns:
      The display name of the file.
      API Note:
      Metadata key: META_DISPLAY_NAME
    • getAudioChannels

      public EChannels getAudioChannels()
      A shortcut to get the audio channels.
      Returns:
      Audio channels enum value.
    • serializeNbt

      public net.minecraft.nbt.CompoundTag serializeNbt()
    • deserializeNbt

      public void deserializeNbt(net.minecraft.nbt.CompoundTag nbt, net.minecraft.world.level.Level level)
    • fromNbt

      public static SoundFile fromNbt(net.minecraft.nbt.CompoundTag nbt, net.minecraft.world.level.Level level)
    • validateHash

      public void validateHash()
      Called on the server-side after loading the file. Do not call this by yourself!
    • of

      public static Optional<SoundFile> of(SoundLocation location, String id)
      Get a SoundFile object by location and filename (Id).
      Parameters:
      location - The location where the sound is saved at.
      id - The if of the sound file (filename on disk without extension)
      Returns:
      The SoundFile, if available.
      Valid on side:
      Server
    • client

      public static SoundFile client(SoundLocation location, String id)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • updateMetadataInternal

      public static void updateMetadataInternal(SoundLocation location, String id, Map<String,String> meta) throws IOException
      Throws:
      IOException
    • removeMetadataInternal

      public static void removeMetadataInternal(SoundLocation location, String id, Set<String> keys) throws IOException
      Throws:
      IOException