Core/src/main/java/eu/univento/core/api/map/MapDownloader.java

54 lines
1.4 KiB
Java

/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.core.api.map;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
/**
* @author joethei
* @version 0.1
*/
public class MapDownloader {
private static void download(URL file, File dest) {
try {
FileUtils.copyURLToFile(file, dest);
} catch (IOException e) {
e.printStackTrace();
}
}
/*
public static World loadMap(String name) {
Map map = MapDatabase.getMap(name);
try {
download(new URL(map.getDownload()), new File("worlds/" + name));
return Bukkit.createWorld(new WorldCreator(name));
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
*/
public static World loadMap(Map map) {
try {
download(new URL(map.getDownload()), new File("worlds/" + map.getName()));
return Bukkit.createWorld(new WorldCreator(map.getName()));
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
}