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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()static VarSoundCreates a VarSound from a vanilla sound.static VarSoundfromCustom(String name) Creates a VarSound from a custom sound.abstract SoundReturns the bukkit enum of the sound.abstract StringgetName()Returns the name of the sound.floatgetPitch()Returns the pitch of the sound.floatReturns the volume of the sound.booleanisActive()Returns whether this sound is active.abstract booleanReturns whether this sound is a vanilla sound or whether it's a custom sound that requires a resource pack.static VarSoundparse(ConfigurationSection config) Parses a sound from aConfigurationSection.voidPlays the sound to the player at the location of the player.voidPlays the sound to the player at the given location.abstract voidPlays the sound to the player at the given location.voidPlays the sound at the given location.abstract voidPlays 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:
trueif it's a vanilla sound,falseotherwise
-
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
nullif 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:
trueif it's active,falseotherwise
-
setActive
Sets whether this sound is active.If it's not active, it won't play.
- Parameters:
active-trueif it's active,falseotherwis- 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
-