Search in sources :

Example 1 with LanternAssetManager

use of org.lanternpowered.server.asset.LanternAssetManager in project LanternServer by LanternPowered.

the class LanternModule method provideAssetManager.

@Exposed
@Provides
@Singleton
private LanternAssetManager provideAssetManager(@Option({ "asset-repository-config", "asset-repo-config" }) @Nullable Path repoConfig, LanternPluginManager pluginManager) {
    final Gson gson = new GsonBuilder().registerTypeAdapter(AssetRepository.class, new AssetRepositoryJsonDeserializer(pluginManager)).create();
    try {
        URL url;
        if (repoConfig != null) {
            url = PathUtils.toURL(repoConfig);
        } else {
            url = getClass().getClassLoader().getResource("assets_repo.json");
            checkNotNull(url);
        }
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
            return new LanternAssetManager(gson.fromJson(reader, AssetRepository.class));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : LanternAssetManager(org.lanternpowered.server.asset.LanternAssetManager) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) AssetRepository(org.lanternpowered.server.asset.AssetRepository) IOException(java.io.IOException) AssetRepositoryJsonDeserializer(org.lanternpowered.server.asset.json.AssetRepositoryJsonDeserializer) URL(java.net.URL) Exposed(com.google.inject.Exposed) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Exposed (com.google.inject.Exposed)1 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 AssetRepository (org.lanternpowered.server.asset.AssetRepository)1 LanternAssetManager (org.lanternpowered.server.asset.LanternAssetManager)1 AssetRepositoryJsonDeserializer (org.lanternpowered.server.asset.json.AssetRepositoryJsonDeserializer)1