All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.k3nder.core.AssetsUtils Maven / Gradle / Ivy

package net.k3nder.core;
import java.lang.*;
import java.net.URI;
import java.net.URISyntaxException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;

import com.fasterxml.jackson.databind.ObjectMapper;
import net.k3nder.core.json.assets.object.Object;
import net.k3nder.core.json.assets.object.Objects;
import org.apache.commons.io.FileUtils;


public class AssetsUtils {

    public static String URL_ = "https://resources.download.minecraft.net/";
    public static void AssetsDownload(String pathJson, String PathDest, String PathObjects) throws IOException, URISyntaxException {
        File json = new File(pathJson);
        ObjectMapper objectMapper = new ObjectMapper();
        Objects objects = objectMapper.readValue(json, net.k3nder.core.json.assets.object.Objects.class);
        for(Map.Entry entry : objects.objects.entrySet()){
            String hash = entry.getValue().hash;
            String block = hash.substring(0,2);
            String url = URL_ + block + "/" + hash;
            String path = entry.getKey();
            String Path = PathDest + path;
            String name = getPath(path);
            int indexExtend = name.lastIndexOf(".");
            if (!(indexExtend == -1)){
                String PathO = PathObjects + "/" + block + "/" + hash;
                System.out.println(Path);
                Path pats = java.nio.file.Paths.get(Path);
                Path pats0 = java.nio.file.Paths.get(PathO);
                if(!Files.exists(pats)){
                    System.out.println(pats);
                    FileUtils.copyURLToFile(new URI(url).toURL(), pats.toFile());
                }
                if(!Files.exists(pats0)){
                    System.out.println(pats0);
                    FileUtils.copyURLToFile(new URI(url).toURL(), pats0.toFile());
                }

            }
        }
    }
    public static String getPath(String ruta) {
        if (ruta == null) return null;
        int ultimaBarra = ruta.lastIndexOf("/");
        if (ultimaBarra != -1) {
            return ruta.substring(ultimaBarra + 1);
        } else {
            return ruta;
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy