-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a98ace
commit cf016a3
Showing
5 changed files
with
151 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package xiamomc.morph.updates; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum Platforms | ||
{ | ||
SPIGOT("Spigot"), | ||
PAPER("Paper"), | ||
PURPUR("Purpur"), | ||
FOLIA("Folia"); | ||
|
||
private final String implName; | ||
|
||
public String getImplName() | ||
{ | ||
return implName; | ||
} | ||
|
||
Platforms(String implName) | ||
{ | ||
this.implName = implName; | ||
} | ||
|
||
public static Platforms fromName(String name) | ||
{ | ||
return Arrays.stream(Platforms.values()) | ||
.filter(v -> v.implName.equalsIgnoreCase(name)) | ||
.findFirst().orElse(PAPER); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/xiamomc/morph/updates/SingleUpdateInfoMeta.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package xiamomc.morph.updates; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import org.slf4j.ILoggerFactory; | ||
import xiamomc.morph.MorphPlugin; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class SingleUpdateInfoMeta | ||
{ | ||
@SerializedName("id") | ||
public String id; | ||
|
||
@SerializedName("project_id") | ||
public String projectId; | ||
|
||
@SerializedName("author_id") | ||
public String authorId; | ||
|
||
@SerializedName("featured") | ||
public boolean featured; | ||
|
||
@SerializedName("name") | ||
public String displayName; | ||
|
||
@SerializedName("version_number") | ||
public String versionNumber; | ||
|
||
@SerializedName("changelog") | ||
public String changelog; | ||
|
||
@SerializedName("changelog_url") | ||
public String changelogUrl; | ||
|
||
@SerializedName("date_published") | ||
public String datePublished; | ||
|
||
@SerializedName("downloads") | ||
public double downloads; | ||
|
||
@SerializedName("version_type") | ||
public String versionType; | ||
|
||
@SerializedName("status") | ||
public String status; | ||
|
||
@SerializedName("requested_status") | ||
public String requestedStatus; | ||
|
||
@SerializedName("files") | ||
public List<Object> files; | ||
|
||
@SerializedName("dependencies") | ||
public List<Object> dependencies; | ||
|
||
@SerializedName("game_versions") | ||
public List<String> supportedVersions; | ||
|
||
@SerializedName("loaders") | ||
public List<String> supportedLoaders; | ||
|
||
public static SingleUpdateInfoMeta fromMap(Map<?, ?> map) | ||
{ | ||
var instance = new SingleUpdateInfoMeta(); | ||
var fields = instance.getClass().getDeclaredFields(); | ||
|
||
for (Field field : fields) | ||
{ | ||
var serializedName = field.isAnnotationPresent(SerializedName.class) | ||
? field.getAnnotation(SerializedName.class).value() | ||
: field.getName(); | ||
|
||
var mapValue = map.getOrDefault(serializedName, null); | ||
|
||
//MorphPlugin.getInstance().getSLF4JLogger() | ||
// .info("Name: '%s', ST: '%s', VT: '%s'" | ||
// .formatted(field.getName(), field.getType(), (mapValue == null ? "nil" : mapValue.getClass()))); | ||
|
||
try | ||
{ | ||
field.set(instance, mapValue); | ||
} | ||
catch (Throwable t) | ||
{ | ||
MorphPlugin.getInstance().getSLF4JLogger().warn("Unable to set '%s' to '%s': %s".formatted(field.getName(), mapValue, t.getMessage())); | ||
//t.printStackTrace(); | ||
} | ||
} | ||
|
||
return instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters