This commit is contained in:
parent
c3c2b47b67
commit
4f6bc2c108
@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
**1.1.5**
|
||||
* Add JSON Strategy
|
||||
|
||||
**1.1.4**
|
||||
* Add Refresh Button To GUI
|
||||
* Add ``/modupdater`` Command
|
||||
|
110
MOD_DEVELOPERS.md
Normal file
110
MOD_DEVELOPERS.md
Normal file
@ -0,0 +1,110 @@
|
||||
# Mod Developers
|
||||
To opt-in a mod for ModUpdater, you must select an update strategy in ```fabric.mod.json```.
|
||||
|
||||
## CurseForge
|
||||
This update strategy uses the CurseForge API to check for updates.
|
||||
|
||||
### ```fabric.mod.json```
|
||||
```json
|
||||
{
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "curseforge",
|
||||
"projectID": 306612
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Requires Semantic Versioning
|
||||
- [Requires ```build.gradle``` modification](#buildgradle-modification)
|
||||
|
||||
## GitHub Releases
|
||||
This update strategy uses the GitHub Releases API to check for updates.
|
||||
|
||||
### ```fabric.mod.json```
|
||||
```json
|
||||
{
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "github",
|
||||
"owner": "Repository Owner",
|
||||
"repository": "Repository Name"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Requires Semantic Versioning
|
||||
- [Requires ```build.gradle``` Modification](#buildgradle-modification)
|
||||
|
||||
## Maven
|
||||
This update strategy uses the specified Maven repository to check for updates.
|
||||
|
||||
### ```fabric.mod.json```
|
||||
```json
|
||||
{
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "maven",
|
||||
"repository": "https://maven.fabricmc.net",
|
||||
"group": "net.fabricmc.fabric-api",
|
||||
"artifact": "fabric-api"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Requires Semantic Versioning
|
||||
- [Requires ```build.gradle``` Modification](#buildgradle-modification)
|
||||
|
||||
## JSON
|
||||
This update strategy uses the specified JSON file to check for updates.
|
||||
|
||||
### ```fabric.mod.json```
|
||||
```json
|
||||
{
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "json",
|
||||
"url": "https://example.com/thing.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### JSON Format
|
||||
```json
|
||||
{
|
||||
"1.16.1": {
|
||||
"version": "1.0.1",
|
||||
"downloadUrl": "https://example.com/thing2.jar"
|
||||
},
|
||||
"20w20a": {
|
||||
"version": "1.0.0",
|
||||
"downloadUrl": "https://example.com/thing.jar"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Does Not Require Semantic Versioning
|
||||
- ```build.gradle``` Modification Is Not Required
|
||||
|
||||
## ```build.gradle``` Modification
|
||||
Multiple update strategies require the Minecraft version to be appended to the end of the JAR version to detect what Minecraft version a JAR supports.
|
||||
|
||||
Replace:
|
||||
```gradle
|
||||
version = project.mod_version
|
||||
```
|
||||
with:
|
||||
```gradle
|
||||
version = "${project.mod_version}+${project.minecraft_version}"
|
||||
```
|
||||
|
||||
If you prefer hyphens you can also use:
|
||||
```gradle
|
||||
version = "${project.mod_version}-${project.minecraft_version}"
|
||||
```
|
||||
|
||||
You can also just use the major version of Minecraft instead of the full version (like ```1.16``` instead of ```1.16.1``` or ```20w20a```).
|
63
README.md
63
README.md
@ -6,69 +6,10 @@ Created For [ModFest 1.16](https://modfest.net/1.16)
|
||||
**NOTE:** This is only able to scan mods that have opted-in!
|
||||
|
||||
## Mod Users
|
||||
Go to the Mod Menu and click the configure icon for ModUpdater to view available updates.
|
||||
Go to the Mod Menu and click the configure icon to show the ModUpdater GUI or use the ```/modupdater``` command.
|
||||
|
||||
## Mod Developers
|
||||
Both ```fabric.mod.json``` and ```build.gradle``` must be modified to opt-in to ModUpdater.
|
||||
|
||||
### ```fabric.mod.json```
|
||||
**Maven**
|
||||
```json
|
||||
{
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "maven",
|
||||
"repository": "https://maven.fabricmc.net",
|
||||
"group": "net.fabricmc.fabric-api",
|
||||
"artifact": "fabric-api"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**CurseForge**
|
||||
```json
|
||||
{
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "curseforge",
|
||||
"projectID": 306612
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**GitHub Releases**
|
||||
```json
|
||||
{
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "github",
|
||||
"owner": "Repository Owner",
|
||||
"repository": "Repository Name"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ```build.gradle```
|
||||
To properly detect the version of a file, the Minecraft version must be appended to the file name.
|
||||
|
||||
Replace:
|
||||
```gradle
|
||||
version = project.mod_version
|
||||
```
|
||||
with:
|
||||
```gradle
|
||||
version = "${project.mod_version}+${project.minecraft_version}"
|
||||
```
|
||||
|
||||
If you prefer hyphens you can also use:
|
||||
```gradle
|
||||
version = "${project.mod_version}-${project.minecraft_version}"
|
||||
```
|
||||
|
||||
You can also just use the major version of Minecraft instead of the full version (like ```1.16``` instead of ```1.16.1``` or ```20w20a```).
|
||||
[View Mod Developers](MOD_DEVELOPERS.md)
|
||||
|
||||
## Changelog
|
||||
[View Changelog](CHANGELOG.md)
|
||||
|
@ -9,7 +9,7 @@ org.gradle.jvmargs = -Xmx1G
|
||||
fabric_loader_version = 0.8.8+build.202
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.1.4
|
||||
mod_version = 1.1.5
|
||||
maven_group = com.thebrokenrail
|
||||
|
||||
# Dependencies
|
||||
|
@ -0,0 +1,87 @@
|
||||
package com.thebrokenrail.modupdater.strategy;
|
||||
|
||||
import com.squareup.moshi.JsonAdapter;
|
||||
import com.squareup.moshi.JsonDataException;
|
||||
import com.squareup.moshi.Moshi;
|
||||
import com.squareup.moshi.Types;
|
||||
import com.thebrokenrail.modupdater.ModUpdater;
|
||||
import com.thebrokenrail.modupdater.api.ConfigObject;
|
||||
import com.thebrokenrail.modupdater.api.UpdateStrategy;
|
||||
import com.thebrokenrail.modupdater.data.ModUpdate;
|
||||
import com.thebrokenrail.modupdater.util.Util;
|
||||
import net.fabricmc.loader.api.SemanticVersion;
|
||||
import net.fabricmc.loader.util.version.VersionParsingException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
public class JSONStrategy implements UpdateStrategy {
|
||||
@SuppressWarnings("unused")
|
||||
private static class LatestVersionEntry {
|
||||
private String version;
|
||||
private String downloadUrl;
|
||||
}
|
||||
|
||||
private final JsonAdapter<Map<String, LatestVersionEntry>> jsonAdapter;
|
||||
|
||||
public JSONStrategy() {
|
||||
Moshi moshi = new Moshi.Builder().build();
|
||||
Type map = Types.newParameterizedType(Map.class, String.class, LatestVersionEntry.class);
|
||||
jsonAdapter = moshi.adapter(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ModUpdate run(ConfigObject obj, String oldVersion, String name) {
|
||||
String url;
|
||||
try {
|
||||
url = obj.getString("url");
|
||||
} catch (ConfigObject.MissingValueException e) {
|
||||
ModUpdater.logWarn(name, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
String data;
|
||||
try {
|
||||
data = Util.urlToString(url);
|
||||
} catch (IOException e) {
|
||||
ModUpdater.logWarn(name, e.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, LatestVersionEntry> map;
|
||||
try {
|
||||
map = jsonAdapter.fromJson(data);
|
||||
} catch (JsonDataException | IOException e) {
|
||||
ModUpdater.logWarn(name, e.toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String version = Util.getMinecraftVersion().getName();
|
||||
if (map.containsKey(version)) {
|
||||
LatestVersionEntry entry = map.get(version);
|
||||
ModUpdate update = new ModUpdate(oldVersion, entry.version, entry.downloadUrl, name);
|
||||
try {
|
||||
if (SemanticVersion.parse(entry.version).compareTo(SemanticVersion.parse(oldVersion)) > 0) {
|
||||
return update;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (VersionParsingException e) {
|
||||
if (!oldVersion.equals(entry.version)) {
|
||||
return update;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.thebrokenrail.modupdater.strategy.util;
|
||||
import com.thebrokenrail.modupdater.api.UpdateStrategy;
|
||||
import com.thebrokenrail.modupdater.strategy.CurseForgeStrategy;
|
||||
import com.thebrokenrail.modupdater.strategy.GitHubReleasesStrategy;
|
||||
import com.thebrokenrail.modupdater.strategy.JSONStrategy;
|
||||
import com.thebrokenrail.modupdater.strategy.MavenStrategy;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -21,5 +22,6 @@ public class UpdateStrategyRegistry {
|
||||
data.put("curseforge", new CurseForgeStrategy());
|
||||
data.put("maven", new MavenStrategy());
|
||||
data.put("github", new GitHubReleasesStrategy());
|
||||
data.put("json", new JSONStrategy());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user