Java源码示例:org.spongepowered.api.asset.Asset

示例1
public ProtectionConfigImpl(final Configuration configuration)
{
	this.configuration = configuration;

	try
	{
		Optional<Asset> worldsFile = Sponge.getAssetManager().getAsset(EagleFactionsPlugin.getPlugin(), "Worlds.conf");
		if (worldsFile.isPresent())
		{
			worldsFile.get().copyToDirectory(configuration.getConfigDirectoryPath(), false, true);
		}
	}
	catch (final IOException e)
	{
		e.printStackTrace();
	}

	this.configurationLoader = HoconConfigurationLoader.builder().setPath(configuration.getConfigDirectoryPath().resolve("Worlds.conf")).build();
	loadWorldsFile();
	saveWorldsFile();
}
 
示例2
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);
}
 
示例3
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);
    }
}
 
示例4
/**
     * 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;
        }
    }
 
示例5
public ConfigurationImpl(final Path configDir, final Asset configAsset)
{
    this.configDirectoryPath = configDir;
    if (!Files.exists(this.configDirectoryPath))
    {
        try
        {
            Files.createDirectory(this.configDirectoryPath);
        }
        catch (IOException exception)
        {
            exception.printStackTrace();
        }
    }

    this.configPath = this.configDirectoryPath.resolve("Settings.conf");

    try
    {
        configAsset.copyToFile(this.configPath, false, true);
    }
    catch (final IOException e)
    {
        e.printStackTrace();
    }

    this.configLoader = HoconConfigurationLoader.builder().setPath(this.configPath).build();
    loadConfiguration();

    this.storageConfig = new StorageConfigImpl(this);
    this.chatConfig = new ChatConfigImpl(this);
    this.dynmapConfig = new DynmapConfigImpl(this);
    this.powerConfig = new PowerConfigImpl(this);
    this.protectionConfig = new ProtectionConfigImpl(this);
    this.pvpLoggerConfig = new PVPLoggerConfigImpl(this);
    this.factionsConfig = new FactionsConfigImpl(this);
    reloadConfiguration();
}
 
示例6
@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();
}
 
示例7
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();
            WebAPI.sentryCapture(e);
        }
    } else {
        this.folderPath = folderPath;
    }
}
 
示例8
public RPSchematics() {

        File file = new File(RedProtect.get().configDir, "schematics");
        if (!file.exists()) {
            file.mkdir();
            try {
                Asset schemAsset = RedProtect.get().container.getAsset("schematics/house1.schem").get();
                schemAsset.copyToDirectory(new File(RedProtect.get().configDir, "schematics").toPath());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
示例9
public SpongeAssetResource(String resourceName, Asset asset) {
    this.resourceName = resourceName;
    this.asset = asset;
}
 
示例10
public RawFileConfig(File file, @Nullable Asset asset) {
    this.file = file;
    this.asset = asset;
    reload();
}