-
Notifications
You must be signed in to change notification settings - Fork 42
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
Showing
5 changed files
with
110 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Obsidian.Plugins; | ||
using Obsidian.Utilities.Interfaces; | ||
using System.Reflection; | ||
|
||
namespace Obsidian.Events; | ||
internal readonly struct MinecraftEventDelegateExecutor : IEventExecutor | ||
{ | ||
public required Type EventType { get; init; } | ||
|
||
public required Priority Priority { get; init; } | ||
|
||
public required ILogger? Logger { get; init; } | ||
|
||
public PluginContainer? PluginContainer { get; init; } | ||
|
||
public required Delegate MethodDelegate { get; init; } | ||
|
||
public ParameterInfo[] GetParameters() => this.MethodDelegate.Method.GetParameters(); | ||
|
||
public IEnumerable<TAttribute> GetCustomAttributes<TAttribute>() where TAttribute : Attribute => | ||
this.MethodDelegate.Method.GetCustomAttributes<TAttribute>(); | ||
|
||
//TODO PARAM INJECTIONS | ||
public async ValueTask Execute(IServiceProvider serviceProvider, params object[]? methodParams) | ||
{ | ||
if (this.MethodDelegate.Method.ReturnType == typeof(ValueTask)) | ||
{ | ||
await (ValueTask)this.MethodDelegate.DynamicInvoke(methodParams)!; | ||
return; | ||
} | ||
else if (this.MethodDelegate.Method.ReturnType == typeof(Task)) | ||
{ | ||
await ((Task)this.MethodDelegate.DynamicInvoke(methodParams)!).ConfigureAwait(false); | ||
return; | ||
} | ||
|
||
this.MethodDelegate.DynamicInvoke(methodParams); | ||
} | ||
|
||
public bool MatchParams(object[] args) => throw new NotImplementedException(); | ||
} |
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,54 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Internal; | ||
using Microsoft.Extensions.Logging; | ||
using Obsidian.Plugins; | ||
using Obsidian.Utilities.Interfaces; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
|
||
namespace Obsidian.Events; | ||
internal readonly struct MinecraftEventExecutor : IEventExecutor | ||
{ | ||
public required Type EventType { get; init; } | ||
|
||
public required ILogger Logger { get; init; } | ||
|
||
public required Type ModuleType { get; init; } | ||
|
||
public required PluginContainer? PluginContainer { get; init; } | ||
|
||
public required Priority Priority { get; init; } | ||
|
||
public required ObjectFactory ModuleFactory { get; init; } | ||
|
||
public required ObjectMethodExecutor MethodExecutor { get; init; } | ||
|
||
//TODO PARAM INJECTION | ||
public async ValueTask Execute(IServiceProvider serviceProvider, params object[]? methodParams) | ||
{ | ||
var module = this.ModuleFactory!.Invoke(this.PluginContainer?.ServiceScope.ServiceProvider | ||
?? serviceProvider, null);//Will inject services through constructor | ||
|
||
this.PluginContainer?.InjectServices(this.Logger, module); //inject through attribute | ||
|
||
if (this.MethodExecutor.MethodReturnType == typeof(ValueTask)) | ||
{ | ||
await (ValueTask)this.MethodExecutor.Execute(module, methodParams)!; | ||
return; | ||
} | ||
else if (this.MethodExecutor.MethodReturnType == typeof(Task)) | ||
{ | ||
await ((Task)this.MethodExecutor.Execute(module, methodParams)!).ConfigureAwait(false); | ||
return; | ||
} | ||
|
||
this.MethodExecutor.Execute(module, methodParams); | ||
} | ||
|
||
public ParameterInfo[] GetParameters() => this.MethodExecutor.MethodParameters; | ||
|
||
public IEnumerable<TAttribute> GetCustomAttributes<TAttribute>() where TAttribute : Attribute => | ||
this.MethodExecutor.MethodInfo.GetCustomAttributes<TAttribute>(); | ||
|
||
public bool MatchParams(object[] args) => this.GetParameters().Length - 1 == args.Length; | ||
} |
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