feat: add configurable ambient audio zones
Build / maven (push) Failing after 6s

This commit is contained in:
root
2026-08-04 05:08:16 +02:00
parent a877b29748
commit 2e2a59b90a
15 changed files with 476 additions and 1 deletions
@@ -0,0 +1,22 @@
package com.lexian.ambientaudio.service;
import com.lexian.ambientaudio.config.ZoneStore;
import com.lexian.ambientaudio.model.AudioZone;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.util.*;
/** Owns in-memory zone definitions and atomically refreshes the playback index after changes. */
public final class ZoneService {
private final JavaPlugin plugin; private final ZoneStore store; private final PlaybackService playback;
private final Map<String, AudioZone> zones = new HashMap<>();
public ZoneService(JavaPlugin plugin, PlaybackService playback) { this.plugin = plugin; this.store = new ZoneStore(plugin); this.playback = playback; }
public void reload() { plugin.reloadConfig(); zones.clear(); zones.putAll(store.load()); refreshPlayback(); }
public Collection<AudioZone> all() { return List.copyOf(zones.values()); }
public AudioZone get(String name) { return zones.get(name.toLowerCase(Locale.ROOT)); }
public void put(AudioZone zone) throws IOException { zones.put(zone.normalizedName(), zone); store.save(zones.values()); refreshPlayback(); }
public AudioZone remove(String name) throws IOException { AudioZone removed = zones.remove(name.toLowerCase(Locale.ROOT)); if (removed != null) { store.save(zones.values()); refreshPlayback(); } return removed; }
private void refreshPlayback() { FileConfiguration c = plugin.getConfig(); playback.configure(zones.values(), Math.max(1, c.getInt("playback.check-interval-ticks", 10)), Math.max(0, c.getLong("playback.leave-grace-ticks", 100)), c.getBoolean("playback.blend-overlapping-zones", false)); }
}