当前位置: 首页>>代码示例>>Java>>正文


Java Asset类代码示例

本文整理汇总了Java中org.spongepowered.api.asset.Asset的典型用法代码示例。如果您正苦于以下问题:Java Asset类的具体用法?Java Asset怎么用?Java Asset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Asset类属于org.spongepowered.api.asset包,在下文中一共展示了Asset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: releaseExample

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
public List<String> releaseExample()
{
    String defaultMenuDir = "menu/";
    File menuDir = this.plugin.getConfigDir().resolve(defaultMenuDir).toFile();
    if (menuDir.isDirectory() || menuDir.mkdirs())
    {
        try
        {
            AssetManager assetManager = Sponge.getAssetManager();
            Optional<Asset> example = assetManager.getAsset(this.plugin, "examples/example.conf");
            Optional<Asset> example2 = assetManager.getAsset(this.plugin, "examples/example2.conf");
            example.orElseThrow(IOException::new).copyToDirectory(menuDir.toPath());
            example2.orElseThrow(IOException::new).copyToDirectory(menuDir.toPath());
        }
        catch (IOException e)
        {
            this.logger.warn("Cannot extract default chest GUI configurations", e);
        }
    }
    return Collections.singletonList(defaultMenuDir);
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:22,代码来源:VirtualChestInventoryDispatcher.java

示例2: VirtualChestTranslation

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
public VirtualChestTranslation(VirtualChestPlugin plugin)
{
    Locale locale = Locale.getDefault();
    AssetManager assets = Sponge.getAssetManager();
    logger = plugin.getLogger();
    try
    {
        Asset asset = assets.getAsset(plugin, "i18n/" + locale.toString() + ".properties").orElse(assets.
                getAsset(plugin, "i18n/en_US.properties").orElseThrow(() -> new IOException(I18N_ERROR)));
        resourceBundle = new PropertyResourceBundle(new InputStreamReader(asset.getUrl().openStream(), Charsets.UTF_8));
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:17,代码来源:VirtualChestTranslation.java

示例3: loadDefault

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
@Override
protected void loadDefault() {
	if (!this.isNewDirs()) return;
	
	String collection = this.name.split("/")[0];
	Optional<Asset> asset = this.plugin.getPluginContainer().getAsset("collections/" + collection + ".conf");
	if (!asset.isPresent()) {
		this.plugin.getELogger().debug("Asset 'collections/" + collection + ".conf' not found");
		return;
	}
	
	URL jarConfigFile = asset.get().getUrl();
	ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setURL(jarConfigFile).build();
	try {
		this.getNode().setValue(loader.load());
		this.save(true);
	} catch (IOException e) {}
}
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:19,代码来源:EConfigSubjectStorage.java

示例4: construct

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
public <T extends CatalogType> T construct(Asset asset, String id, Class<T> objectType) {
    checkNotNull(asset, "asset");
    checkNotNull(objectType, "objectType");
    checkArgument(this.constructorClasses.containsKey(objectType),
            "The object type %s isn't supported!", objectType.getName());
    final Class<?> constructorClass = this.constructorClasses.get(objectType);
    final CatalogTypeConstructor<T> constructor;
    try (final InputStream is = asset.getUrl().openStream()) {
        final InputStreamReader reader = new InputStreamReader(is);
        constructor = (CatalogTypeConstructor<T>) this.gson.fromJson(reader, constructorClass);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    final String pluginId = asset.getOwner().getId();
    return constructor.create(pluginId, id);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:17,代码来源:LanternScriptGameRegistry.java

示例5: get

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
@Override
public Asset get() {
    final AssetId assetId = this.point.getAnnotation(AssetId.class);
    String name;
    if (assetId != null) {
        name = assetId.value();
    } else {
        name = provideName(this.point).orElseThrow(
                () -> new IllegalStateException("Missing @AssetId or @Named annotation."));
    }
    if (name.indexOf(':') == -1) {
        name = this.container.getId() + ':' + name;
    }
    final String name1 = name;
    return this.assetManager.getAsset(name)
            .orElseThrow(() -> new NoSuchElementException("Cannot find asset " + name1));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:PluginAssetProvider.java

示例6: discoverCatalogFile

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
private boolean discoverCatalogFile() throws IOException {
    Optional<Asset> assetOptional = Sponge.getAssetManager().getAsset(plugin, "mcap/catalog.json.gz");

    if (!assetOptional.isPresent()) {
        assetOptional = Sponge.getAssetManager().getAsset(plugin, "mcap/catalog.json");

        if (!assetOptional.isPresent()) {
            logger.warn("No catalog mappings file found. This will be a problem");
            return false;
        }

        node = GsonConfigurationLoader.builder().setURL(assetOptional.get().getUrl()).build().load();
        return true;
    }

    Optional<Asset> finalAssetOptional = assetOptional;
    //noinspection OptionalGetWithoutIsPresent
    node = GsonConfigurationLoader.builder().setSource(() -> new BufferedReader(new InputStreamReader(new GZIPInputStream(finalAssetOptional.get()
            .getUrl().openStream())))).build().load();
    return true;
}
 
开发者ID:MinigameCore,项目名称:MinigameCore,代码行数:22,代码来源:CatalogTypeApplier.java

示例7: complete

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
/**
     * This method completes a datafile.
     * Any fields that are in the asset provided but not in the datafile will be set in the datafile.
     *
     * @param file  The file to complete
     * @param asset The asset with the default values
     * @return Whether anything was added to the file
     */
    public static boolean complete(RawConfig file, Asset asset) {
        try {
            ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setURL(asset.getUrl()).build();
            CommentedConfigurationNode assetnode = loader.load();
            CommentedConfigurationNode sourcenode = file.get();

//            if (complete(assetnode, sourcenode)) {
//                file.save(assetnode);
//                return true;
//            }
            return false;
        } catch (Exception ex) {
            ErrorLogger.log(ex, "Config completion failed for " + file + " / " + asset);
            return false;
        }
    }
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:25,代码来源:ConfigCompleter.java

示例8: getDefaultConfigURL

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
@Override
public URL getDefaultConfigURL() {
    Optional<Asset> config = pluginContainer.getAsset("config.yml");
    if (!config.isPresent()) {
        throw new IllegalArgumentException("Default config is missing from jar");
    }
    return config.get().getUrl();
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:9,代码来源:SpongeConfigAPI.java

示例9: AssetHandler

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
public AssetHandler(String folderPath) {
    Optional<Asset> asset = Sponge.getAssetManager().getAsset(WebAPI.getInstance(), folderPath);
    if (folderPath.contains(".") && asset.isPresent()) {
        try {
            this.assetString = asset.get().readString();
            this.contentType = guessContentType(folderPath);
        } catch (IOException e) {
            e.printStackTrace();
            if (WebAPI.reportErrors()) WebAPI.sentryCapture(e);
        }
    } else {
        this.folderPath = folderPath;
    }
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:15,代码来源:AssetHandler.java

示例10: register

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
@Override
public void register(CustomMaterialDefinition definition) {
    PluginContainer pluginContainer = definition.getPluginContainer();
    Map<String, CompletableFuture<SkinRecord>> texturesToSkins = getTexturesToSkins(pluginContainer);

    definition.getModels().stream()
            .filter(texture -> !texturesToSkins.containsKey(texture))
            .forEach(texture -> {
                MineskinService mineskinService = getMineskinService();
                Asset asset = getAsset(pluginContainer, texture);
                CompletableFuture<SkinRecord> future = mineskinService.getSkinAsync(asset);
                texturesToSkins.put(texture, future);
            });
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:15,代码来源:CustomMaterialRegistry.java

示例11: getAsset

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
private Asset getAsset(PluginContainer pluginContainer, String texture) {
    Object plugin = pluginContainer.getInstance()
            .orElseThrow(() -> new IllegalStateException("Could not access the plugin instance of plugin: " + pluginContainer.getId()));
    AssetManager assetManager = Sponge.getAssetManager();
    String assetPath = CustomMaterialDefinition.getTextureAsset(texture);

    return assetManager.getAsset(plugin, assetPath)
            .orElseThrow(() -> new IllegalArgumentException("Could not locate asset '" + assetPath + "' of plugin '" + pluginContainer.getId() + "'."));
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:10,代码来源:CustomMaterialRegistry.java

示例12: generateResourcePack

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
public Path generateResourcePack() {
    Path directory = getDirectoryResourcePack();

    // Copy over the pack.mcmeta file
    Path packFile = directory.resolve(FILE_NAME_PACK);

    try {
        Files.createDirectories(directory);

        if (Files.exists(packFile))
            Files.delete(packFile);

        Asset pack = Sponge.getAssetManager().getAsset(CustomItemLibrary.getInstance(), FILE_NAME_PACK)
                .orElseThrow(() -> new IllegalStateException("Could not access the 'pack.mcmeta' asset."));
        pack.copyToFile(packFile);
    } catch(IOException e) {
        CustomItemLibrary.getInstance().getLogger()
                .warn("Could not create the 'pack.mcmeta' file.");
        e.printStackTrace();
    }

    getDefinitions().forEach(customFeatureDefinition ->
            customFeatureDefinition.generateResourcePackFiles(directory));

    registryMap.values().forEach(registry ->
            registry.generateResourcePackFiles(directory));

    DurabilityRegistry.getInstance().generateResourcePack(directory);

    return directory;
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:32,代码来源:CustomItemServiceImpl.java

示例13: compile

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> Script<T> compile(Asset asset, Class<T> function) {
    final String id = ((org.lanternpowered.api.asset.Asset) asset).getId();
    return (Script<T>) this.functionAssetScripts.computeIfAbsent(id, id0 -> {
        try {
            return this.compileScript(Joiner.on('\n').join(asset.readLines()),
                    (ScriptFunctionMethod) ScriptFunctionMethod.of(function), asset, null);
        } catch (IOException e) {
            throw new IllegalArgumentException("Failed to read the asset data: " + id0);
        }
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:14,代码来源:LanternScriptGameRegistry.java

示例14: copyAsset

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
static void copyAsset(CustomFeatureDefinition definition, AssetId assetId, Path resourcePackDirectory) {
    PluginContainer plugin = assetId.getPluginContainer();
    String filePath = getFilePath(plugin, assetId.getValue());
    Optional<Asset> optionalAsset = assetId.getAsset();

    if (!optionalAsset.isPresent()) {
        CustomItemLibrary.getInstance().getLogger()
                .warn("Could not locate an asset for plugin '"
                        + plugin.getName() + "' with path '" + filePath + "'.");
        return;
    }

    Asset asset = optionalAsset.get();
    Path outputFile = resourcePackDirectory.resolve(Paths.get(filePath));

    try {
        Files.createDirectories(outputFile.getParent());

        if (Files.exists(outputFile))
            Files.delete(outputFile);

        Files.createFile(outputFile);

        //noinspection unchecked
        CustomFeatureRegistry registry = (CustomFeatureRegistry) CustomItemLibrary.getInstance()
                .getService().getRegistry(definition).get();

        try (
                ReadableByteChannel input = Channels
                        .newChannel(asset.getUrl().openStream());
                SeekableByteChannel output = Files.newByteChannel
                        (outputFile, StandardOpenOption.WRITE)
        ) {
            //noinspection unchecked
            registry.writeAsset(definition, assetId, input, output, outputFile);
        }
    } catch (IOException e) {
        e.printStackTrace();
        CustomItemLibrary.getInstance().getLogger()
                .warn("Could not copy a file from assets (" + filePath + "): " + e.getLocalizedMessage());
    }
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:43,代码来源:CustomFeatureRegistry.java

示例15: getAsset

import org.spongepowered.api.asset.Asset; //导入依赖的package包/类
public Optional<Asset> getAsset() {
    return pluginContainer.getAsset(getValue());
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:4,代码来源:AssetId.java


注:本文中的org.spongepowered.api.asset.Asset类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。