Package de.marcely.bedwars.tools
Class VarSound
java.lang.Object
de.marcely.bedwars.tools.VarSound
- All Implemented Interfaces:
Cloneable
Easy solution for playing vanilla and custom sounds while retaining async support.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
static VarSound
Creates a VarSound from a vanilla sound.static VarSound
fromCustom
(String name) Creates a VarSound from a custom sound.abstract Sound
Returns the bukkit enum of the sound.abstract String
getName()
Returns the name of the sound.float
getPitch()
Returns the pitch of the sound.float
Returns the volume of the sound.boolean
isActive()
Returns whether this sound is active.abstract boolean
Returns whether this sound is a vanilla sound or whether it's a custom sound that requires a resource pack.static VarSound
parse
(ConfigurationSection config) Parses a sound from aConfigurationSection
.void
Plays the sound to the player at the location of the player.void
Plays the sound to the player at the given location.abstract void
Plays the sound to the player at the given location.void
Plays the sound at the given location.abstract void
Plays the sound at the given location.Serializes this sound into aConfigurationSection
.setActive
(boolean active) Sets whether this sound is active.setPitch
(float pitch) Sets the pitch of the sound.setVolume
(float volume) Sets the volume of the sound.
-
Constructor Details
-
VarSound
public VarSound()
-
-
Method Details
-
isVanilla
public abstract boolean isVanilla()Returns whether this sound is a vanilla sound or whether it's a custom sound that requires a resource pack.- Returns:
true
if it's a vanilla sound,false
otherwise
-
getName
Returns the name of the sound.If it's a vanilla sound, it returns
Enum.name()
.- Returns:
- The name of the sound
-
getBukkitEnum
Returns the bukkit enum of the sound.- Returns:
- The bukkit enum of the sound. May be
null
if it's not present
-
getVolume
public float getVolume()Returns the volume of the sound.Default is
1
.- Returns:
- The volume of the sound
-
setVolume
Sets the volume of the sound.- Parameters:
volume
- The volume of the sound- Returns:
- Returns this exact instance
-
getPitch
public float getPitch()Returns the pitch of the sound.Default is
1
.- Returns:
- The pitch of the sound
-
setPitch
Sets the pitch of the sound.- Parameters:
pitch
- The pitch of the sound- Returns:
- Returns this exact instance
-
isActive
public boolean isActive()Returns whether this sound is active.If it's not active, it won't play.
- Returns:
true
if it's active,false
otherwise
-
setActive
Sets whether this sound is active.If it's not active, it won't play.
- Parameters:
active
-true
if it's active,false
otherwis- Returns:
- Returns this exact instancee
-
play
public abstract void play(Player player, Location loc, @Nullable @Nullable Float overrideVolume, @Nullable @Nullable Float overridePitch) Plays the sound to the player at the given location.- Parameters:
player
- The player to play the sound toloc
- The location to play the sound atoverrideVolume
- The volume to play the sound at. Ifnull
, it usesgetVolume()
overridePitch
- The pitch to play the sound at. Ifnull
, it usesgetPitch()
-
play
public abstract void play(Location loc, @Nullable @Nullable Float overrideVolume, @Nullable @Nullable Float overridePitch) Plays the sound at the given location.- Parameters:
loc
- The location to play the sound atoverrideVolume
- The volume to play the sound at. Ifnull
, it usesgetVolume()
overridePitch
- The pitch to play the sound at. Ifnull
, it usesgetPitch()
-
play
Plays the sound to the player at the given location.- Parameters:
player
- The player to play the sound toloc
- The location to play the sound at
-
play
Plays the sound to the player at the location of the player.- Parameters:
player
- The player to play the sound to
-
play
Plays the sound at the given location.- Parameters:
loc
- The location to play the sound at
-
clone
-
serializeAsConfig
Serializes this sound into aConfigurationSection
. It includes the following keys:- name: The name of the sound (required)
- is-active: Whether the sound is active (default: true)
- is-custom-resourcepack: Whether the sound is a custom sound that requires a resource pack (default: false)
- volume: The volume of the sound (default: 1.0)
- pitch: The pitch of the sound (default: 1.0)
- Returns:
- The serialized sound
-
parse
Parses a sound from aConfigurationSection
. It includes the following keys:- name: The name of the sound (required)
- is-active: Whether the sound is active (default: true)
- is-custom-resourcepack: Whether the sound is a custom sound that requires a resource pack (default: false)
- volume: The volume of the sound (default: 1.0)
- pitch: The pitch of the sound (default: 1.0)
- Parameters:
config
- The config to parse- Returns:
- The parsed sound
- Throws:
IllegalArgumentException
- If the config is invalid
-
from
Creates a VarSound from a vanilla sound.- Parameters:
sound
- The sound- Returns:
- The created wrapper
-
fromCustom
Creates a VarSound from a custom sound.- Parameters:
name
- The name of the sound- Returns:
- The created wrapper
-