Skip to content

Commit

Permalink
Rename and restructure of code
Browse files Browse the repository at this point in the history
  • Loading branch information
tekgator committed May 31, 2023
1 parent 165e97d commit 1a10c5f
Show file tree
Hide file tree
Showing 54 changed files with 277 additions and 288 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
## [Unreleased]


## [1.3.0] - 2023-06-01
### Added
- Paper plugin flag pre and snapshot builds as IsSnapshot
- Pocketmine flag alpha builds as IsSnapshot
- Spigot plugin flag pre and snapshot builds as IsSnapshot

### Changed
- Renamed IProvider to IMinecraftProvider
- Renamed IProject to IMinecraftProject
- Renamed IVersion to IMinecraftVersion
- Renamed IDownload to IMinecraftDownload
- Rename ProviderManager to MinecraftProviderManager
- Change LINQ method calls to query format


## [1.2.3] - 2023-05-31
### Changed
- GetVersion on IProvider now returns all versions for all projects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace MinecraftJars.Core.Downloads;

public interface IDownload
public interface IMinecraftDownload
{
/// <summary>
/// Filename of the download e.g. server-version.jar. Name could be used for the downloaded file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MinecraftJars.Core.Projects;

public interface IProject
public interface IMinecraftProject
{
/// <summary>
/// Group of the project e.g. Server, Bedrock or Proxy
Expand Down Expand Up @@ -32,7 +32,7 @@ public interface IProject
/// <summary>
/// Get available versions for the project from the provider
/// </summary>
public Task<IEnumerable<IVersion>> GetVersions(
Task<IEnumerable<IMinecraftVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace MinecraftJars.Core.Providers;

public interface IProvider
public interface IMinecraftProvider
{
/// <summary>
/// The options the provider manager has been provided with
Expand All @@ -23,12 +23,12 @@ public interface IProvider
/// <summary>
/// Available projects of the provider
/// </summary>
IEnumerable<IProject> Projects { get; }
IEnumerable<IMinecraftProject> Projects { get; }

/// <summary>
/// Get available versions for all projects from the provider
/// </summary>
public Task<IEnumerable<IVersion>> GetVersions(
Task<IEnumerable<IMinecraftVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace MinecraftJars.Core.Versions;

public interface IVersion
public interface IMinecraftVersion
{
/// <summary>
/// Project information about the version
/// </summary>
IProject Project { get; }
IMinecraftProject Project { get; }

/// <summary>
/// Version name e.g. 1.19.4
Expand All @@ -30,5 +30,5 @@ public interface IVersion
/// Note: In case this method is building the actual JAR the user is responsible to move/delete the temp.
/// directory including the built JAR file
/// </summary>
Task<IDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!);
Task<IMinecraftDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!);
}
2 changes: 1 addition & 1 deletion MinecraftJars.Demo/MinecraftJars.Demo.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MinecraftJars;
using MinecraftJars.Core.Versions;

var providerManager = new ProviderManager();
var providerManager = new MinecraftJarManager();

foreach (var provider in providerManager.GetProviders())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace MinecraftJars.Plugin.Fabric;

[Export(typeof(IProvider))]
public class FabricProvider : IProvider
[Export(typeof(IMinecraftProvider))]
public class FabricProvider : IMinecraftProvider
{
[ImportingConstructor]
public FabricProvider(ProviderOptions? options)
Expand All @@ -18,14 +18,14 @@ public FabricProvider(ProviderOptions? options)
public ProviderOptions ProviderOptions { get; }
public string Name => "Fabric";
public byte[] Logo => Properties.Resources.Fabric;
public IEnumerable<IProject> Projects => FabricProjectFactory.Projects;
public IEnumerable<IMinecraftProject> Projects => FabricProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
public async Task<IEnumerable<IMinecraftVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();
var versions = new List<IMinecraftVersion>();

foreach (var project in Projects)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,27 @@ internal static class FabricVersionFactory
{
var project = FabricProjectFactory.Projects.Single(p => p.Name.Equals(projectName));

var versionsApi = await HttpClient.GetFromJsonAsync<Versions>(FabricVersionsRequestUri, cancellationToken);

if (versionsApi == null)
var versionsApi = await HttpClient.GetFromJsonAsync<Versions>(FabricVersionsRequestUri, cancellationToken) ??
throw new InvalidOperationException("Could not acquire game type details.");

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

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

var versions = versionsApi.Games
.Select(game => new FabricVersion(
Project: project,

var versions = (from game in versionsApi.Games
where string.IsNullOrWhiteSpace(options.Version) || game.Version.Equals(options.Version)
where options.IncludeSnapshotBuilds || !game.Stable
let installer = versionsApi.Installers.First().Version
select new FabricVersion(
Project: project,
Version: game.Version,
IsSnapShot: !game.Stable)
{
InstallerVersion = versionsApi.Installers.First().Version
}).ToList();

{
InstallerVersion = versionsApi.Installers.First().Version
}).ToList();
return options.MaxRecords.HasValue
? versions.Take(options.MaxRecords.Value).ToList()
: versions;
}

public static async Task<IDownload> GetDownload(
public static async Task<IMinecraftDownload> GetDownload(
DownloadOptions options,
FabricVersion version,
CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public record FabricDownload(
string Url,
DateTime? ReleaseTime = null,
HashType HashType = HashType.None,
string? Hash = null) : IDownload;
string? Hash = null) : IMinecraftDownload;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public record FabricProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject
byte[] Logo) : IMinecraftProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
public async Task<IEnumerable<IMinecraftVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace MinecraftJars.Plugin.Fabric.Model;

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

public Task<IDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!) =>
public Task<IMinecraftDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!) =>
FabricVersionFactory.GetDownload(options ?? new DownloadOptions(), this, cancellationToken);
}
8 changes: 4 additions & 4 deletions MinecraftJars.Plugin/MinecraftJars.Plugin.Fabric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,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 [FabricProvider](FabricProvider.cs)
- `IProject` to [FabricProject](Model/FabricProject.cs)
- `IVersion` to [FabricVersion](Model/FabricVersion.cs)
- `IDownload` to [FabricDownload](Model/FabricDownload.cs)
- `IMinecraftProvider` to [FabricProvider](FabricProvider.cs)
- `IMinecraftProject` to [FabricProject](Model/FabricProject.cs)
- `IMinecraftVersion` to [FabricVersion](Model/FabricVersion.cs)
- `IMinecraftDownload` to [FabricDownload](Model/FabricDownload.cs)
- No `Hash`, `ReleaseTime` or `Size` is provided
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public record MohistDownload(
string Url,
DateTime? ReleaseTime,
HashType HashType,
string? Hash) : IDownload;
string? Hash) : IMinecraftDownload;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public record MohistProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject
byte[] Logo) : IMinecraftProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
public async Task<IEnumerable<IMinecraftVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace MinecraftJars.Plugin.Mohist.Model;

public record MohistVersion(
IProject Project,
IMinecraftProject Project,
string Version,
bool IsSnapShot = false) : IVersion
bool IsSnapShot = false) : IMinecraftVersion
{
public Task<IDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!) =>
public Task<IMinecraftDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!) =>
MohistVersionFactory.GetDownload(options ?? new DownloadOptions(), this, cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace MinecraftJars.Plugin.Mohist;

[Export(typeof(IProvider))]
public class MohistProvider : IProvider
[Export(typeof(IMinecraftProvider))]
public class MohistProvider : IMinecraftProvider
{
[ImportingConstructor]
public MohistProvider(ProviderOptions? options)
Expand All @@ -18,14 +18,14 @@ public MohistProvider(ProviderOptions? options)
public ProviderOptions ProviderOptions { get; }
public string Name => "Mohist";
public byte[] Logo => Properties.Resources.Mohist;
public IEnumerable<IProject> Projects => MohistProjectFactory.Projects;
public IEnumerable<IMinecraftProject> Projects => MohistProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
public async Task<IEnumerable<IMinecraftVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();
var versions = new List<IMinecraftVersion>();

foreach (var project in Projects)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,24 @@ internal static class MohistVersionFactory
{
var project = MohistProjectFactory.Projects.Single(p => p.Name.Equals(projectName));

var availVersions = await HttpClient.GetFromJsonAsync<List<string>>(MohistVersionRequestUri, cancellationToken);
var versionApi = await HttpClient.GetFromJsonAsync<List<string>>(MohistVersionRequestUri, cancellationToken) ??
throw new InvalidOperationException("Could not acquire version details.");

if (availVersions == null)
throw new InvalidOperationException("Could not acquire game type details.");

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

availVersions.Reverse();
versionApi.Reverse();

var versions = availVersions
.Select(availVersion => new MohistVersion(
Project: project,
Version: availVersion)
var versions = (from version in versionApi
where string.IsNullOrWhiteSpace(options.Version) || version.Equals(options.Version)
select new MohistVersion(
Project: project,
Version: version)
).ToList();

return options.MaxRecords.HasValue
? versions.Take(options.MaxRecords.Value).ToList()
: versions;
}

public static async Task<IDownload> GetDownload(
public static async Task<IMinecraftDownload> GetDownload(
DownloadOptions options,
MohistVersion version,
CancellationToken cancellationToken)
Expand Down
8 changes: 4 additions & 4 deletions MinecraftJars.Plugin/MinecraftJars.Plugin.Mohist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The plugin is already bundled with the core library [MinecraftJar.NET](../../REA
The plugin has no 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)
- `IMinecraftProvider` to [MohistProvider](MohistProvider.cs)
- `IMinecraftProject` to [MohistProject](Model/MohistProject.cs)
- `IMinecraftVersion` to [MohistVersion](Model/MohistVersion.cs)
- `IMinecraftDownload` to [MohistDownload](Model/MohistDownload.cs)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public record MojangDownload(
string Url,
HashType HashType = HashType.None,
string? Hash = null,
DateTime? ReleaseTime = null) : IDownload;
DateTime? ReleaseTime = null) : IMinecraftDownload;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public record MojangProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject
byte[] Logo) : IMinecraftProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
public async Task<IEnumerable<IMinecraftVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace MinecraftJars.Plugin.Mojang.Models;

public record MojangVersion(
IProject Project,
IMinecraftProject Project,
string Version,
bool IsSnapShot,
Os? Os = null) : IVersion
Os? Os = null) : IMinecraftVersion
{
internal DateTime? ReleaseTime { get; init; }
internal string DetailUrl { get; init; } = string.Empty;

public Task<IDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!) =>
public Task<IMinecraftDownload> GetDownload(DownloadOptions? options = null, CancellationToken cancellationToken = default!) =>
MojangVersionFactory.GetDownload(options ?? new DownloadOptions(), this, cancellationToken);
}
Loading

0 comments on commit 1a10c5f

Please sign in to comment.