94 lines
3 KiB
Java
94 lines
3 KiB
Java
package dev.loki.sound;
|
|
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.World;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
public class GeneratorSound extends BukkitRunnable {
|
|
|
|
private static final long AMBIENT_INTERVAL = 100L;
|
|
private static final float AMBIENT_VOLUME = 0.4f;
|
|
private static final float AMBIENT_PITCH = 0.8f;
|
|
|
|
private final JavaPlugin plugin;
|
|
private final SoundManager soundManager;
|
|
private final Map<UUID, Location> activeGenerators;
|
|
|
|
public GeneratorSound(JavaPlugin plugin, SoundManager soundManager) {
|
|
this.plugin = plugin;
|
|
this.soundManager = soundManager;
|
|
this.activeGenerators = new HashMap<>();
|
|
}
|
|
|
|
public void addGenerator(UUID id, Location location) {
|
|
activeGenerators.put(id, location);
|
|
}
|
|
|
|
public void removeGenerator(UUID id) {
|
|
activeGenerators.remove(id);
|
|
}
|
|
|
|
public void start() {
|
|
runTaskTimer(plugin, 0L, AMBIENT_INTERVAL);
|
|
}
|
|
|
|
public void stop() {
|
|
cancel();
|
|
activeGenerators.clear();
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
for (Location location : activeGenerators.values()) {
|
|
playAmbientGeneratorSound(location);
|
|
}
|
|
}
|
|
|
|
private void playAmbientGeneratorSound(Location location) {
|
|
World world = location.getWorld();
|
|
if (world == null) return;
|
|
|
|
world.playSound(location, Sound.BLOCK_REDSTONE_TORCH_BURNOUT, AMBIENT_VOLUME, AMBIENT_PITCH);
|
|
}
|
|
|
|
public void playGeneratorProgress(Location location, double progressPercent) {
|
|
float pitch = 0.8f + (float) (progressPercent / 100.0f * 0.4f);
|
|
soundManager.playWithVolumeAt(location, Sound.BLOCK_NOTE_BLOCK_PLING, 0.5f, pitch);
|
|
}
|
|
|
|
public void playGeneratorComplete(Location location) {
|
|
soundManager.playWithVolumeAt(location, Sound.BLOCK_BEACON_POWER_SELECT, 1.0f, 1.0f);
|
|
playGeneratorStartSound(location);
|
|
}
|
|
|
|
public void playGeneratorStartSound(Location location) {
|
|
soundManager.playWithVolumeAt(location, Sound.BLOCK_PISTON_EXTEND, 0.8f, 0.5f);
|
|
}
|
|
|
|
public void playGeneratorStopSound(Location location) {
|
|
soundManager.playWithVolumeAt(location, Sound.BLOCK_PISTON_CONTRACT, 0.6f, 0.5f);
|
|
}
|
|
|
|
public void playGeneratorExplosion(Location location) {
|
|
World world = location.getWorld();
|
|
if (world == null) return;
|
|
|
|
world.playSound(location, Sound.ENTITY_GENERIC_EXPLODE, 1.0f, 0.8f);
|
|
world.playSound(location, Sound.ENTITY_TNT_PRIMED, 0.8f, 0.6f);
|
|
}
|
|
|
|
public void playSkillCheckSuccess(Location location) {
|
|
soundManager.playWithVolumeAt(location, Sound.BLOCK_NOTE_BLOCK_CHIME, 0.6f, 1.5f);
|
|
}
|
|
|
|
public void playSkillCheckFail(Location location) {
|
|
soundManager.playWithVolumeAt(location, Sound.BLOCK_NOTE_BLOCK_BASS, 0.8f, 0.5f);
|
|
soundManager.playWithVolumeAt(location, Sound.ENTITY_ITEM_BREAK, 0.4f, 0.8f);
|
|
}
|
|
}
|