Skip to content

Instantly share code, notes, and snippets.

@NeusFear
Created April 30, 2024 00:26
Show Gist options
  • Save NeusFear/4f5159ee7ce9beaa4911a2e1ac551c4a to your computer and use it in GitHub Desktop.
Save NeusFear/4f5159ee7ce9beaa4911a2e1ac551c4a to your computer and use it in GitHub Desktop.
package com.terminalvelocitycabbage.engine.mod;
import com.electronwill.nightconfig.core.conversion.Conversion;
import com.electronwill.nightconfig.core.conversion.Converter;
import com.github.zafarkhaja.semver.Version;
import java.util.ArrayList;
import java.util.List;
public class ModInfo {
private ModIdentity identity;
private ModAuthors authors;
private ModDependencies dependencies;
public static class ModIdentity {
String namespace;
String name;
String description;
String version; //TODO add @SpecValidator here to confirm in semver format
}
public static class ModAuthors {
List<String> creators;
List<String> contributors;
}
//This is a temporary workaround for a night-config feature. When not requiring a class to parse to replace this
public static class VersionPair {
//A Pair defined as <Namespace, Version>
@Conversion(VersionToStringConverter.class)
String namespace;
Version version;
public VersionPair(String namespace, Version version) {
this.namespace = namespace;
this.version = version;
}
public String getNamespace() {
return namespace;
}
public Version getVersion() {
return version;
}
}
public static class ModDependencies {
List<VersionPair> required;
List<VersionPair> optional;
}
static class VersionToStringConverter implements Converter<String, VersionPair> {
@Override
public String convertToField(VersionPair stringVersionPair) {
return stringVersionPair.getNamespace() + ":" + stringVersionPair.getVersion();
}
@Override
public VersionPair convertFromField(String s) {
String[] split = s.split(":");
return new VersionPair(split[0], Version.parse(split[1]));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment