Skip to content

Commit

Permalink
Merge pull request #6 from tekgator/dev
Browse files Browse the repository at this point in the history
Separation of Snapshot and Standard versions for Mojang, Fabric and Pocketmine plugin, this is handled now via the IsSnapshot indicator on IVersion
  • Loading branch information
tekgator committed May 30, 2023
2 parents 8bcd4e7 + 9372a09 commit 016dba3
Show file tree
Hide file tree
Showing 48 changed files with 178 additions and 187 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [1.2.2] - 2023-05-30
### Added
- Add version option to include snapshots during load, by default this is false
- Add indicator to show that the current version is a snapshot / preview / experimental / beta / alpha build
- Add IsSnapshot test cases

### Changed
- Restructure and simplify API directories

### Removed
- Separation of Snapshot ans Standard versions for Mojang, Fabric and Pocketmine plugin, this is handled now via the IsSnapshot indicator on IVersion


## [1.2.1] - 2023-05-29
### Fixed
Expand Down
5 changes: 5 additions & 0 deletions MinecraftJars.Core/Versions/IVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public interface IVersion
/// </summary>
string Version { get; }

/// <summary>
/// Indicates whether this version experimental
/// </summary>
bool IsSnapShot { get; }

/// <summary>
/// Indicates TRUE in case the plugin needs to build the JAR file instead of providing download information
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions MinecraftJars.Core/Versions/VersionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class VersionOptions
/// </summary>
public string? Version { get; set; }

/// <summary>
/// Indicates to return snapshot / experimental / preview / beta / alpha builds as well
/// </summary>
public bool IncludeSnapshotBuilds { get; set; }

/// <summary>
/// Limit the amount of records returned by the plugin API. Useful if only
/// e.g. the last x Versions are required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ namespace MinecraftJars.Plugin.Fabric;
internal static class FabricProjectFactory
{
public const string Fabric = "Fabric";
public const string FabricSnapshot = "Fabric Snapshot";

public static readonly IEnumerable<FabricProject> Projects = new List<FabricProject>
{
new(Group: Group.Server,
Name: Fabric,
Description: "Fabric is a lightweight, experimental modding toolchain for Minecraft.",
Url: "https://fabricmc.net",
Logo: Properties.Resources.Fabric),
new(Group: Group.Server,
Name: FabricSnapshot,
Description: "Fabric is a lightweight, experimental modding toolchain for Minecraft. Based on Minecraft snapshot versions",
Url: "https://fabricmc.net",
Logo: Properties.Resources.Fabric),
Logo: Properties.Resources.Fabric)
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ internal static class FabricVersionFactory

if (!string.IsNullOrWhiteSpace(options.Version))
versionsApi.Games.RemoveAll(v => !v.Version.Equals(options.Version));

switch (project.Name)
{
case FabricProjectFactory.Fabric:
versionsApi.Games.RemoveAll(v => !v.Stable);
break;
case FabricProjectFactory.FabricSnapshot:
versionsApi.Games.RemoveAll(v => v.Stable);
break;
}

if (!options.IncludeSnapshotBuilds)
versionsApi.Games.RemoveAll(v => !v.Stable);

var versions = versionsApi.Games
.Select(game => new FabricVersion(
Project: project,
Version: game.Version)
Version: game.Version,
IsSnapShot: !game.Stable)
{
InstallerVersion = versionsApi.Installers.First().Version
}).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace MinecraftJars.Plugin.Fabric.Model;

public record FabricVersion(
IProject Project,
string Version) : IVersion
string Version,
bool IsSnapShot) : IVersion
{
internal string InstallerVersion { get; init; } = string.Empty;

Expand Down
9 changes: 4 additions & 5 deletions MinecraftJars.Plugin/MinecraftJars.Plugin.Fabric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

Provider for:
- Fabric
- Fabric Snapshot

## Installing

Expand All @@ -16,8 +15,8 @@ The plugin is already bundled with the core library [MinecraftJar.NET](../../REA
The plugin has a few minor specialities compared to the core interfaces.
If required the interface can be casted to it's instantiated classes.

- `IProvider` to [MohistProvider](MohistProvider.cs)
- `IProject` to [MohistProject](Model/MohistProject.cs)
- `IVersion` to [MohistVersion](Model/MohistVersion.cs)
- `IDownload` to [MohistDownload](Model/MohistDownload.cs)
- `IProvider` to [FabricProvider](FabricProvider.cs)
- `IProject` to [FabricProject](Model/FabricProject.cs)
- `IVersion` to [FabricVersion](Model/FabricVersion.cs)
- `IDownload` to [FabricDownload](Model/FabricDownload.cs)
- No `Hash`, `ReleaseTime` or `Size` is provided
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MinecraftJars.Plugin.Mohist.Model.BuildApi;
namespace MinecraftJars.Plugin.Mohist.Model.MohistApi;

internal class Build
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace MinecraftJars.Plugin.Mohist.Model;

public record MohistVersion(
IProject Project,
string Version) : IVersion
string Version,
bool IsSnapShot = false) : IVersion
{
public Task<IDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!) =>
MohistVersionFactory.GetDownload(options ?? new DownloadOptions(), this, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MinecraftJars.Core.Downloads;
using MinecraftJars.Core.Versions;
using MinecraftJars.Plugin.Mohist.Model;
using MinecraftJars.Plugin.Mohist.Model.BuildApi;
using MinecraftJars.Plugin.Mohist.Model.MohistApi;

namespace MinecraftJars.Plugin.Mohist;

Expand All @@ -18,7 +18,6 @@ internal static class MohistVersionFactory
VersionOptions options,
CancellationToken cancellationToken)
{
var versions = new List<MohistVersion>();
var project = MohistProjectFactory.Projects.Single(p => p.Name.Equals(projectName));

var availVersions = await HttpClient.GetFromJsonAsync<List<string>>(MohistVersionRequestUri, cancellationToken);
Expand All @@ -31,12 +30,12 @@ internal static class MohistVersionFactory

availVersions.Reverse();

versions.AddRange(availVersions
.Select(version => new MohistVersion(
Project: project,
Version: version
)));
var versions = availVersions
.Select(availVersion => new MohistVersion(
Project: project,
Version: availVersion)
).ToList();

return options.MaxRecords.HasValue
? versions.Take(options.MaxRecords.Value).ToList()
: versions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MinecraftJars.Plugin.Mojang.Models.DetailApi;
namespace MinecraftJars.Plugin.Mojang.Models.MojangApi;

internal class Detail
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MinecraftJars.Plugin.Mojang.Models.DetailApi;
namespace MinecraftJars.Plugin.Mojang.Models.MojangApi;

internal class Downloads
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MinecraftJars.Plugin.Mojang.Models.DetailApi;
namespace MinecraftJars.Plugin.Mojang.Models.MojangApi;

internal class JavaVersion
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MinecraftJars.Plugin.Mojang.Models.ManifestApi;
namespace MinecraftJars.Plugin.Mojang.Models.MojangApi;

internal class Latest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MinecraftJars.Plugin.Mojang.Models.ManifestApi;
namespace MinecraftJars.Plugin.Mojang.Models.MojangApi;

internal class Manifest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MinecraftJars.Plugin.Mojang.Models.DetailApi;
namespace MinecraftJars.Plugin.Mojang.Models.MojangApi;

internal class Server
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MinecraftJars.Plugin.Mojang.Models.ManifestApi;
namespace MinecraftJars.Plugin.Mojang.Models.MojangApi;

internal class Version
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace MinecraftJars.Plugin.Mojang.Models;
public record MojangVersion(
IProject Project,
string Version,
bool IsSnapShot,
Os? Os = null) : IVersion
{
internal DateTime? ReleaseTime { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ namespace MinecraftJars.Plugin.Mojang;
internal class MojangProjectFactory
{
public const string Vanilla = "Vanilla";
public const string VanillaSnapshot = "Vanilla Snapshot";
public const string Bedrock = "Bedrock";
public const string BedrockPreview = "Bedrock Preview";

public static readonly IEnumerable<MojangProject> Projects = new List<MojangProject>
{
Expand All @@ -17,20 +15,10 @@ internal class MojangProjectFactory
Description: "The Mojang vanilla Minecraft experience without mod support.",
Url: "https://www.minecraft.net/download/server",
Logo: Properties.Resources.Vanilla),
new(Group: Group.Server,
Name: VanillaSnapshot,
Description: "A Snapshot is a testing version of Minecraft, periodically released by Mojang Studios.",
Url: "https://feedback.minecraft.net/hc/en-us/sections/360002267532-Snapshot-Information-and-Changelogs",
Logo: Properties.Resources.VanillaSnapshot),
new(Group: Group.Bedrock,
Name: Bedrock,
Description: "Minecraft: Bedrock Edition refers to the multi-platform versions of Minecraft based on the Bedrock codebase.",
Url: "https://www.minecraft.net/download/server/bedrock",
Logo: Properties.Resources.Bedrock),
new(Group: Group.Bedrock,
Name: BedrockPreview,
Description: "Minecraft Preview is an app players can use to test out beta features from Bedrock Edition. It works as a separate app, rather than the previous system of opt in beta content inside of the Bedrock Edition game itself.",
Url: "https://www.minecraft.net/download/server/bedrock",
Logo: Properties.Resources.BedrockPreview)
Logo: Properties.Resources.Bedrock)
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
using MinecraftJars.Core.Downloads;
using MinecraftJars.Core.Versions;
using MinecraftJars.Plugin.Mojang.Models;
using MinecraftJars.Plugin.Mojang.Models.DetailApi;
using MinecraftJars.Plugin.Mojang.Models.ManifestApi;
using MinecraftJars.Plugin.Mojang.Models.MojangApi;
using Group = MinecraftJars.Core.Projects.Group;

namespace MinecraftJars.Plugin.Mojang;
Expand Down Expand Up @@ -39,7 +38,7 @@ internal static partial class MojangVersionFactory
VersionOptions options,
CancellationToken cancellationToken)
{
var versions = new List<MojangVersion>();

var project = MojangProjectFactory.Projects.Single(p => p.Name.Equals(projectName));

var manifest = await HttpClient.GetFromJsonAsync<Manifest>(MojangVanillaRequestUri, cancellationToken);
Expand All @@ -50,16 +49,18 @@ internal static partial class MojangVersionFactory
if (!string.IsNullOrWhiteSpace(options.Version))
manifest.Versions.RemoveAll(v => !v.Id.Equals(options.Version));

versions.AddRange(manifest.Versions
.Where(v => project.Name == MojangProjectFactory.Vanilla ?
v.Type.Equals("release", StringComparison.OrdinalIgnoreCase) :
!v.Type.Equals("release", StringComparison.OrdinalIgnoreCase))
.Select(version => new MojangVersion(
if (!options.IncludeSnapshotBuilds)
manifest.Versions
.RemoveAll(v => !v.Type.Equals("release", StringComparison.OrdinalIgnoreCase));

var versions = manifest.Versions
.Select(v => new MojangVersion(
Project: project,
Version: version.Id) {
ReleaseTime = version.ReleaseTime,
DetailUrl = version.Url
}));
Version: v.Id,
IsSnapShot: !v.Type.Equals("release", StringComparison.OrdinalIgnoreCase)) {
ReleaseTime = v.ReleaseTime,
DetailUrl = v.Url
}).ToList();

return options.MaxRecords.HasValue
? versions.Take(options.MaxRecords.Value).ToList()
Expand All @@ -71,7 +72,6 @@ internal static partial class MojangVersionFactory
VersionOptions options,
CancellationToken cancellationToken)
{
var versions = new List<MojangVersion>();
var project = MojangProjectFactory.Projects.Single(p => p.Name.Equals(projectName));

var request = new HttpRequestMessage(HttpMethod.Get, MojangBedrockRequestUri);
Expand All @@ -86,44 +86,22 @@ internal static partial class MojangVersionFactory
throw new InvalidOperationException("Could not acquire version details.");

var html = await response.Content.ReadAsStringAsync(cancellationToken);

foreach (var match in MojangBedrockDownloadLink().Matches(html).Cast<Match>())
{
var url = match.Value;

var version = match.Groups.Values
.Where(p => p.Name == "version")
.Select(p => p.Value)
.FirstOrDefault();

if (version == null)
continue;

if (!string.IsNullOrWhiteSpace(options.Version) && !options.Version.Equals(version))
continue;

var isPreview = match.Groups["preview"].Value.Length > 0;

if ((project.Name == MojangProjectFactory.Bedrock && isPreview) ||
(project.Name == MojangProjectFactory.BedrockPreview && !isPreview))
continue;

var platform = match.Groups.Values
.Where(p => p.Name == "platform")
.Select(p => p.Value)
.FirstOrDefault() switch
{
"linux" => Os.Linux,
_ => Os.Windows
};

versions.Add(new MojangVersion(
Project: project,
Version: version,
Os: platform) {

var versions = (from match in MojangBedrockDownloadLink().Matches(html)
let url = match.Value
let version = match.Groups["version"].Value
let isPreview = !string.IsNullOrWhiteSpace(match.Groups["preview"].Value)
let platform = match.Groups["platform"].Value.Equals("linux", StringComparison.OrdinalIgnoreCase) ? Os.Linux : Os.Windows
where !string.IsNullOrWhiteSpace(version) && (string.IsNullOrWhiteSpace(options.Version) || options.Version.Equals(version))
where options.IncludeSnapshotBuilds || !isPreview
select new MojangVersion(
Project: project,
Version: version,
IsSnapShot: isPreview,
Os: platform)
{
DetailUrl = url
});
}
}).ToList();

return options.MaxRecords.HasValue
? versions.Take(options.MaxRecords.Value).ToList()
Expand Down

0 comments on commit 016dba3

Please sign in to comment.