Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b445fb
commit 683f9ba
Showing
9 changed files
with
92 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
paper/src/main/java/com/badbones69/crazycrates/tasks/crates/effects/SoundEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.badbones69.crazycrates.tasks.crates.effects; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.Sound; | ||
import org.bukkit.SoundCategory; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
|
||
public class SoundEffect { | ||
|
||
private final SoundCategory category; | ||
private final boolean isEnabled; | ||
private final Sound sound; | ||
private final float volume; | ||
private final float pitch; | ||
|
||
/** | ||
* Builds a sound to play. | ||
* | ||
* @param section in the crate config. | ||
* @param type of sound i.e. cycle-sound or click-sound. | ||
* @param fallback the fallback sound if no sound is found. | ||
* @param category of sound as to respect the client side sound settings. | ||
*/ | ||
public SoundEffect(ConfigurationSection section, String type, String fallback, SoundCategory category) { | ||
this.isEnabled = section.getBoolean(type + ".toggle", false); | ||
|
||
this.sound = Sound.valueOf(section.getString(type + ".value", fallback)); | ||
this.volume = (float) section.getDouble(type + ".volume", 1.0); | ||
this.pitch = (float) section.getDouble(type + ".pitch", 1.0); | ||
|
||
this.category = category; | ||
} | ||
|
||
public void play(Location location) { | ||
if (!this.isEnabled) return; | ||
|
||
location.getWorld().playSound(location, this.sound, this.category, this.volume, this.pitch); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters