You've already forked AstralRinth
forked from didirus/AstralRinth
Add even more validators (#385)
* Add even more validators I was gonna add shaderpacks too, but those have no standard metadata file at all. * Make it compile * Fix logic * Update validators * fix mistake Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
@@ -4,9 +4,9 @@ use crate::validate::{
|
||||
use std::io::Cursor;
|
||||
use zip::ZipArchive;
|
||||
|
||||
pub struct PluginValidator;
|
||||
pub struct BukkitValidator;
|
||||
|
||||
impl super::Validator for PluginValidator {
|
||||
impl super::Validator for BukkitValidator {
|
||||
fn get_file_extensions(&self) -> &[&str] {
|
||||
&["zip", "jar"]
|
||||
}
|
||||
@@ -36,3 +36,105 @@ impl super::Validator for PluginValidator {
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BungeeCordValidator;
|
||||
|
||||
impl super::Validator for BungeeCordValidator {
|
||||
fn get_file_extensions(&self) -> &[&str] {
|
||||
&["zip", "jar"]
|
||||
}
|
||||
|
||||
fn get_project_types(&self) -> &[&str] {
|
||||
&["mod"]
|
||||
}
|
||||
|
||||
fn get_supported_loaders(&self) -> &[&str] {
|
||||
&["bungeecord", "waterfall"]
|
||||
}
|
||||
|
||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||
SupportedGameVersions::All
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("bungee.yml").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"No bungee.yml present for plugin file.".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VelocityValidator;
|
||||
|
||||
impl super::Validator for VelocityValidator {
|
||||
fn get_file_extensions(&self) -> &[&str] {
|
||||
&["zip", "jar"]
|
||||
}
|
||||
|
||||
fn get_project_types(&self) -> &[&str] {
|
||||
&["mod"]
|
||||
}
|
||||
|
||||
fn get_supported_loaders(&self) -> &[&str] {
|
||||
&["velocity"]
|
||||
}
|
||||
|
||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||
SupportedGameVersions::All
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("velocity-plugin.json").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"No velocity-plugin.json present for plugin file.".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SpongeValidator;
|
||||
|
||||
impl super::Validator for SpongeValidator {
|
||||
fn get_file_extensions(&self) -> &[&str] {
|
||||
&["zip", "jar"]
|
||||
}
|
||||
|
||||
fn get_project_types(&self) -> &[&str] {
|
||||
&["mod"]
|
||||
}
|
||||
|
||||
fn get_supported_loaders(&self) -> &[&str] {
|
||||
&["sponge"]
|
||||
}
|
||||
|
||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||
SupportedGameVersions::All
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
if !archive
|
||||
.file_names()
|
||||
.any(|name| name == "sponge_plugins.json" || name == "mcmod.info")
|
||||
{
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No sponge_plugins.json or mcmod.info present for Sponge plugin.",
|
||||
));
|
||||
};
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user