Stage 12: Data storage system

This commit is contained in:
loki5512344 2026-05-31 20:47:02 +02:00
parent 82ed455cd2
commit 4fd7955d56
62 changed files with 5613 additions and 0 deletions

View file

@ -0,0 +1,94 @@
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);
}
}

View file

@ -0,0 +1,34 @@
package dev.loki.sound;
public enum SoundLevels {
LOW(0.3f, 0.8f),
MEDIUM(0.6f, 1.0f),
HIGH(1.0f, 1.2f);
private final float volume;
private final float pitch;
SoundLevels(float volume, float pitch) {
this.volume = volume;
this.pitch = pitch;
}
public float getVolume() {
return volume;
}
public float getPitch() {
return pitch;
}
public static SoundLevels fromDistance(double distance, double maxRange) {
double ratio = distance / maxRange;
if (ratio < 0.33) {
return HIGH;
} else if (ratio < 0.66) {
return MEDIUM;
} else {
return LOW;
}
}
}

View file

@ -0,0 +1,75 @@
package dev.loki.sound;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Collection;
public class SoundManager {
private final JavaPlugin plugin;
public SoundManager(JavaPlugin plugin) {
this.plugin = plugin;
}
public void playSound(Player player, Location location, Sound sound, SoundLevels level) {
player.playSound(location, sound, level.getVolume(), level.getPitch());
}
public void playSound(Player player, Sound sound, SoundLevels level) {
player.playSound(player.getLocation(), sound, level.getVolume(), level.getPitch());
}
public void playSoundAt(Location location, Sound sound, SoundLevels level) {
World world = location.getWorld();
if (world == null) return;
world.playSound(location, sound, level.getVolume(), level.getPitch());
}
public void playSoundToAll(Collection<Player> players, Sound sound, SoundLevels level) {
for (Player player : players) {
if (player.isOnline()) {
playSound(player, sound, level);
}
}
}
public void playWithVolume(Player player, Sound sound, float volume, float pitch) {
player.playSound(player.getLocation(), sound, volume, pitch);
}
public void playWithVolumeAt(Location location, Sound sound, float volume, float pitch) {
World world = location.getWorld();
if (world == null) return;
world.playSound(location, sound, volume, pitch);
}
public void playAmbientSound(Location location, Sound sound, float volume, float pitch, int intervalTicks) {
}
public void stopSound(Player player, Sound sound) {
player.stopSound(sound);
}
public void playHeartbeat(Player player, SoundLevels level) {
playSound(player, Sound.ENTITY_WARDEN_HEARTBEAT, level);
}
public void playGeneratorStart(Location location) {
playWithVolumeAt(location, Sound.BLOCK_PISTON_EXTEND, 0.8f, 0.5f);
}
public void playGeneratorStop(Location location) {
playWithVolumeAt(location, Sound.BLOCK_PISTON_CONTRACT, 0.6f, 0.5f);
}
public void playGeneratorExplosion(Location location) {
playWithVolumeAt(location, Sound.ENTITY_GENERIC_EXPLODE, 1.0f, 0.8f);
}
}

View file

@ -0,0 +1,92 @@
package dev.loki.sound;
import dev.loki.player.Killer;
import dev.loki.player.Survivor;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Collection;
public class TerrorRadiusSound extends BukkitRunnable {
private static final double TERROR_RADIUS = 32.0;
private static final long TICK_INTERVAL = 20L;
private final JavaPlugin plugin;
private final SoundManager soundManager;
private Killer killer;
private Collection<Survivor> survivors;
public TerrorRadiusSound(JavaPlugin plugin, SoundManager soundManager) {
this.plugin = plugin;
this.soundManager = soundManager;
}
public void setTargets(Killer killer, Collection<Survivor> survivors) {
this.killer = killer;
this.survivors = survivors;
}
public void start() {
runTaskTimer(plugin, 0L, TICK_INTERVAL);
}
public void stop() {
cancel();
}
@Override
public void run() {
if (killer == null || !killer.isOnline()) {
return;
}
Player killerPlayer = killer.getPlayer();
if (killerPlayer == null) return;
Location killerLoc = killerPlayer.getLocation();
for (Survivor survivor : survivors) {
if (!survivor.isOnline()) continue;
if (survivor.getState().isDeadOrEscaped()) continue;
Player survPlayer = survivor.getPlayer();
if (survPlayer == null) continue;
Location survLoc = survPlayer.getLocation();
double distance = killerLoc.distance(survLoc);
if (distance <= TERROR_RADIUS) {
SoundLevels level = SoundLevels.fromDistance(distance, TERROR_RADIUS);
playTerrorSound(survPlayer, level);
}
}
}
private void playTerrorSound(Player player, SoundLevels level) {
soundManager.playHeartbeat(player, level);
}
public double getTerrorRadius() {
return TERROR_RADIUS;
}
public SoundLevels getTerrorLevel(double distance) {
if (distance > TERROR_RADIUS) {
return null;
}
return SoundLevels.fromDistance(distance, TERROR_RADIUS);
}
public void playImmediateTerror(Survivor survivor, SoundLevels level) {
if (!survivor.isOnline()) return;
Player player = survivor.getPlayer();
if (player == null) return;
playTerrorSound(player, level);
}
}