/*
 * Aeronica's mxTune MOD
 * Copyright 2019, Paul Boese a.k.a. Aeronica
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package net.aeronica.mods.mxtune.managers;

import net.aeronica.mods.mxtune.Reference;
import net.aeronica.mods.mxtune.util.ModLogger;

import java.util.UUID;

public class ClientFileManager
{
    private static UUID cachedServerID;

    // TODO: Client side server cache folders must be per server and player (integrated AND dedicated)
    // This must be done to avoid potential naming conflicts.
    private ClientFileManager() { /* NOP*/ }

    public static void setCachedServerID(long msb, long lsb)
    {
        cachedServerID = new UUID(msb, lsb);
        ModLogger.debug("Cached Server ID received: %s", cachedServerID.toString());
    }

    private static UUID getCachedServerID()
    {
        return cachedServerID;
    }

    // Uses Playlist for now. Area will be used comes once I get all the basic mechanics working
    // This is called every tick so after at least one to two ticks a song should be available
    // If no local cache files exist then the area/playlist will get DL and cached. On subsequent ticks
    // the song itself will be chosen and made available
    static boolean songAvailable(UUID uuidPlayList)
    {
        // META: What to do?

        // Check local cache for area/playlist
        // if area/playlist not exists
        //     DL area/playlist and cache to collection and disk (async threaded flush)
        // else
        //     choose song based on <Area> settings and <playlist>
        //     if song not cached
        //         DL and cache
        //     else
        //         get song from cache
        // queue song for next play and set songAvailable to true.
        return !Reference.EMPTY_UUID.equals(uuidPlayList);
    }
}

@@ -770,617 +770,2201 @@
 une.
-util.ModLogger;%0A%0Aimport java.util.UUID;%0A%0Apublic class ClientFileManager%0A%7B%0A    private static UUID cachedServerID;%0A%0A    // TODO: Client side server cache folders must be per server and player (integrated AND dedicated)%0A    // This must be done to avoid potential naming conflicts.%0A    private ClientFileManager() %7B /* NOP*/ %7D%0A%0A    public static void setCachedServerID(long msb, long lsb)%0A    %7B%0A        cachedServerID = new UUID(msb, lsb);%0A        ModLogger.debug(%22Cached Server ID received: %25s%22, cachedServerID.toString());%0A    %7D%0A%0A    private static UUID getCachedServerID()%0A    %7B%0A        return cachedServerID
+caches.FileHelper;%0Aimport net.aeronica.mods.mxtune.util.MXTuneRuntimeException;%0Aimport net.aeronica.mods.mxtune.util.ModLogger;%0Aimport net.minecraft.client.Minecraft;%0Aimport net.minecraftforge.fml.relauncher.Side;%0A%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport java.util.UUID;%0A%0Apublic class ClientFileManager%0A%7B%0A    private static UUID cachedServerID = Reference.EMPTY_UUID;%0A    private static Minecraft mc = Minecraft.getMinecraft();%0A    private static UUID playerUniqueID;%0A    private static Path clientSideCacheDirectory;%0A%0A    // TODO: Client side server cache folders must be per server and player (integrated AND dedicated)%0A    // This must be done to avoid potential naming conflicts.%0A    private ClientFileManager() %7B /* NOP*/ %7D%0A%0A    /**%0A     * Sets the cached server ID for the server the client logged onto. This is an mxTune feature for internal use.%0A     * Called when the client logs on to the server as part of the ClientStateData query.%0A     * @param msb UUID MSB%0A     * @param lsb UUID LSB%0A     */%0A    public static void setCachedServerID(long msb, long lsb)%0A    %7B%0A        cachedServerID = new UUID(msb, lsb);%0A        ModLogger.debug(%22Cached Server ID received: %25s%22, cachedServerID.toString());%0A        createClientSideCacheDirectory();%0A    %7D%0A%0A    /**%0A     * %3Cp%3EBuild a unique client side server data cache directory by player and server.%3C/p%3E%0A     * e.g. &lt;game folder&gt;/mxtune/server_cache/&lt;player UUID&gt/&lt;server UUID&gt;%0A     */%0A    private static void createClientSideCacheDirectory()%0A    %7B%0A        playerUniqueID = mc.player.getUniqueID();%0A        Path clientSidePlayerServerCachePath = Paths.get(FileHelper.CLIENT_SERVER_CACHE_FOLDER, playerUniqueID.toString(), getCachedServerID().toString());%0A        clientSideCacheDirectory = FileHelper.getDirectory(clientSidePlayerServerCachePath.toString(), Side.CLIENT);%0A    %7D%0A%0A    static UUID getCachedServerID()%0A    %7B%0A        if (Reference.EMPTY_UUID.equals(cachedServerID))%0A            throw new MXTuneRuntimeException(%22EMPTY_UUID detected! Something is seriously wrong.%22);%0A        return cachedServerID;%0A    %7D%0A%0A    static Path getClientSideCacheDirectory()%0A    %7B%0A        return clientSideCacheDirectory
 ;%0A  

Build a unique client side server data cache by player and server. e.g. <game folder>/mxtune/server_cache/<player UUID>/<server UUID>