package dev.loki.chest; import dev.loki.config.LocationsConfig; import org.bukkit.Location; import org.bukkit.plugin.java.JavaPlugin; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; public class ChestManager { private final JavaPlugin plugin; private final Map chests; private final LocationsConfig locationsConfig; public ChestManager(JavaPlugin plugin, LocationsConfig locationsConfig) { this.plugin = plugin; this.chests = new HashMap<>(); this.locationsConfig = locationsConfig; loadChests(); } private void loadChests() { List locations = locationsConfig.getChestLocations(); for (Location loc : locations) { Chest chest = new Chest(loc); chests.put(chest.getId(), chest); } plugin.getLogger().info("Loaded " + chests.size() + " chests"); } public Chest getChest(UUID id) { return chests.get(id); } public List getAllChests() { return new ArrayList<>(chests.values()); } public Chest getNearestChest(Location location, double maxRange) { Chest nearest = null; double minDistance = maxRange; for (Chest chest : chests.values()) { double distance = chest.getDistance(location); if (distance < minDistance) { minDistance = distance; nearest = chest; } } return nearest; } public List getAvailableChests() { List available = new ArrayList<>(); for (Chest chest : chests.values()) { if (chest.isAvailable()) { available.add(chest); } } return available; } public void resetAllChests() { for (Chest chest : chests.values()) { chest.setOpened(false); chest.setEmpty(false); } plugin.getLogger().info("Reset all chests"); } public void clearChests() { chests.clear(); } public void addChest(Location location) { Chest chest = new Chest(location); chests.put(chest.getId(), chest); locationsConfig.addChestLocation(location); } public int getTotalChests() { return chests.size(); } public int getRemainingChests() { return (int) chests.values().stream().filter(Chest::isAvailable).count(); } }